-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Tom Haddon <[email protected]>
- Loading branch information
1 parent
20acfa2
commit 1f7ad84
Showing
3 changed files
with
88 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Backup and restore Jenkins | ||
A backup is a snapshot of the Jenkins data (jobs, configurations, secrets, plugins, etc.) at a given point in time. This backup can be used to: | ||
* Restore Jenkins to a previous stable state (during disaster recovery). | ||
* Migrate data to a new Jenkins charm instance. | ||
|
||
## Create a backup | ||
1. Create the backup script | ||
From [Backing-up/Restoring Jenkins](https://www.jenkins.io/doc/book/system-administration/backing-up/), This script backs up the most essential files as mentioned in the article: | ||
* The `master.key` file. | ||
* Job-related files in the `./jobs`, `./builds` and `./workspace` folders. | ||
* Plugins (`.hpi` and `.jpi` files) in the `./plugins` folder | ||
|
||
```bash | ||
cat <<EOF > backup.sh | ||
#!/bin/bash | ||
export JENKINS_HOME=/var/lib/jenkins | ||
export JENKINS_BACKUP=/mnt/backup | ||
echo "running backup as \$(whoami) in \$(pwd)" | ||
mkdir -p \$JENKINS_BACKUP | ||
cp \$JENKINS_HOME/secrets/master.key \$JENKINS_BACKUP | ||
cp -r \$JENKINS_HOME/jobs \$JENKINS_BACKUP | ||
cp -r \$JENKINS_HOME/builds \$JENKINS_BACKUP | ||
cp -r \$JENKINS_HOME/workspace \$JENKINS_BACKUP | ||
mkdir -p \$JENKINS_BACKUP/plugins | ||
cp -r \$JENKINS_HOME/plugins/*.hpi \$JENKINS_BACKUP/plugins | ||
cp -r \$JENKINS_HOME/plugins/*.jpi \$JENKINS_BACKUP/plugins | ||
chown -R 2000:2000 \$JENKINS_BACKUP | ||
tar zcvf jenkins_backup.tar.gz --directory=/mnt backup | ||
EOF | ||
|
||
chmod +x backup.sh | ||
``` | ||
2. Transfer the backup script above to the running unit of the Jenkins-k8s charm and run it | ||
```bash | ||
JENKINS_UNIT=jenkins-k8s/0 | ||
juju scp --container jenkins ./backup.sh $JENKINS_UNIT:/backup.sh | ||
juju ssh --container jenkins $JENKINS_UNIT /backup.sh | ||
``` | ||
3. Retrieve the compressed backup file | ||
```bash | ||
JENKINS_UNIT=jenkins-k8s/0 | ||
juju scp --container jenkins $JENKINS_UNIT:/jenkins_backup.tar.gz jenkins_backup.tar.gz | ||
``` | ||
You now have the compressed Jenkins data on your host system. | ||
|
||
## Restore the backup on a new (or existing) charm instance | ||
1. Restore the backup on the Jenkins charm unit. | ||
```bash | ||
JENKINS_UNIT=jenkins-k8s/0 | ||
juju scp --container jenkins ./jenkins_backup.tar.gz $JENKINS_UNIT:/jenkins_backup.tar.gz | ||
juju ssh --container jenkins $JENKINS_UNIT tar zxvf jenkins_backup.tar.gz | ||
juju ssh --container jenkins $JENKINS_UNIT chown -R 2000:2000 /backup | ||
juju ssh --container jenkins $JENKINS_UNIT cp -aR /backup/* /var/lib/jenkins | ||
juju ssh --container jenkins $JENKINS_UNIT rm -rf /backup /jenkins_backup.tar.gz | ||
``` | ||
2. Restart pebble for the changes to take effect | ||
```bash | ||
juju ssh --container jenkins $JENKINS_UNIT pebble restart jenkins | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# How to redeploy Jenkins | ||
|
||
Redeployment is a process where the old charm instance is removed and data is migrated to a new charm instance. Redeploying the Jenkins charm consists of 3 steps: | ||
|
||
1. Create the new Jenkins charm instance | ||
```bash | ||
juju deploy jenkins-k8s jenkins-k8s-new | ||
``` | ||
2. Migrate Jenkins data | ||
See the `Migrate Jenkins data` section below. | ||
3. Remove the old Jenkins charm instance | ||
```bash | ||
juju remove-application jenkins-k8s | ||
``` | ||
|
||
### Migrate Jenkins data | ||
Follow the instructions in [the charm's documentation for backup and restore](https://charmhub.io/jenkins-k8s/docs/backup-and-restore-jenkins) to migrate the data to the new Jenkins charm instance. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,17 @@ | ||
# How to resize the jenkins-home storage volume | ||
The default size of the jenkins-home storage volume for a fresh installation is 1GB. While this works for most scenarios, operators might need to have more storage for installing plugins, storing artifacts, and runninng builds/checking out SCMs on the built-in node. | ||
The default size of the jenkins-home storage volume for a fresh installation is 1GB. While this works for most scenarios, operators might need to have more storage for installing plugins, storing artifacts, and running builds/checking out SCMs on the built-in node. | ||
|
||
A low disk-space on the built-in node will cause the node to go offline, blocking jenkins from running jobs. | ||
A low disk-space on the built-in node will cause the node to go offline, blocking Jenkins from running jobs. | ||
|
||
## Create a backup | ||
From [Backing-up/Restoring Jenkins](https://www.jenkins.io/doc/book/system-administration/backing-up/), This script backs up the most essential files as mentioned in the article: | ||
* The `master.key` file. | ||
* Job-related files in the `./jobs`, `./builds` and `./workspace` folders. | ||
* Plugins (`.hpi` and `.jpi` files) in the `./plugins` folder | ||
### Create a backup of the current Jenkins charm instance | ||
Follow the `Create a backup` section of [the charm's backup and restore documentation](https://charmhub.io/jenkins-k8s/docs/backup-and-restore-jenkins) to create an archive of the Jenkins data on your host system | ||
|
||
### Deploy the new Jenkins charm instance, specifying the size of the storage volume | ||
Create a new application with the `--storage` flag. In this example we'll deploy the charm with a storage of 10GB | ||
```bash | ||
echo cat <<EOF > backup.sh | ||
#!/bin/bash | ||
export JENKINS_HOME=/var/lib/jenkins | ||
export JENKINS_BACKUP=/mnt/backup | ||
echo "running backup as \$(whoami) in \$(pwd)" | ||
mkdir -p \$JENKINS_BACKUP | ||
cp \$JENKINS_HOME/secrets/master.key \$JENKINS_BACKUP | ||
cp -r \$JENKINS_HOME/*.xml \$JENKINS_BACKUP | ||
cp -r \$JENKINS_HOME/jobs \$JENKINS_BACKUP | ||
cp -r \$JENKINS_HOME/builds \$JENKINS_BACKUP | ||
cp -r \$JENKINS_HOME/workspace \$JENKINS_BACKUP | ||
mkdir -p \$JENKINS_BACKUP/plugins | ||
cp -r \$JENKINS_HOME/plugins/*.hpi \$JENKINS_BACKUP/plugins | ||
cp -r \$JENKINS_HOME/plugins/*.jpi \$JENKINS_BACKUP/plugins | ||
chown -R 2000:2000 $JENKINS_BACKUP | ||
tar zcvf jenkins_backup.tar.gz --directory=/mnt backup | ||
EOF | ||
|
||
chmod +x backup.sh | ||
``` | ||
1. Transfer the backup script above to the running unit of the Jenkins-k8s charm and run it | ||
```bash | ||
JENKINS_UNIT=jenkins-k8s/0 | ||
juju scp --container jenkins ./backup.sh $JENKINS_UNIT:/backup.sh | ||
juju ssh --container jenkins $JENKINS_UNIT /backup.sh | ||
``` | ||
2. Retrieve the compressed backup file | ||
```bash | ||
JENKINS_UNIT=jenkins-k8s/0 | ||
juju scp --container jenkins $JENKINS_UNIT:/jenkins_backup.tar.gz jenkins_backup.tar.gz | ||
``` | ||
3. With the data backed-up, we can remove the jenkins-k8s application. | ||
```bash | ||
JENKINS_APP=jenkins-k8s | ||
juju remove-application $JENKINS_APP | ||
juju deploy jenkins-k8s-new --storage jenkins-home=10GB | ||
``` | ||
|
||
## Restore the backup on a new charm instance | ||
1. When the application has been deleted, create a new application with the `--storage` flag. In this example we'll deploy the charm with a storage of 10GB | ||
```bash | ||
juju deploy jenkins-k8s --storage jenkins-home=10GB | ||
``` | ||
2. Wait for the charm to be ready, then restore the backup on the new unit. | ||
```bash | ||
JENKINS_UNIT=jenkins-k8s/0 | ||
juju scp --container jenkins ./jenkins_backup.tar.gz $JENKINS_UNIT:/jenkins_backup.tar.gz | ||
juju ssh --container jenkins $JENKINS_UNIT tar zxvf jenkins_backup.tar.gz | ||
juju ssh --container jenkins $JENKINS_UNIT chown -R 2000:2000 /backup | ||
juju ssh --container jenkins $JENKINS_UNIT cp -R /backup/* /var/lib/jenkins | ||
juju ssh --container jenkins $JENKINS_UNIT rm -rf /backup /jenkins_backup.tar.gz | ||
``` | ||
3. Finally restart pebble | ||
```bash | ||
juju ssh --container jenkins $JENKINS_UNIT pebble restart jenkins | ||
``` | ||
### Restore the created backup onto the newly created Jenkins charm instance | ||
Follow the `Restore the backup on a new (or existing) charm instance` section of [the charm's backup and restore documentation](https://charmhub.io/jenkins-k8s/docs/backup-and-restore-jenkins) to create an archive of the Jenkins data on your host system. Remember to update the `JENKINS_UNIT` environment variable. For our example we have `JENKINS_UNIT=jenkins-k8s-new/0` | ||
|