Skip to content

Commit

Permalink
modified: docs/how-to/resize-jenkins-storage.md
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Apr 30, 2024
1 parent bbbfdca commit 30797ad
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions docs/how-to/resize-jenkins-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,43 @@ From [Backing-up/Restoring Jenkins](https://www.jenkins.io/doc/book/system-admin
* Plugins (`.hpi` and `.jpi` files) in the `./plugins` folder

```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
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
juju scp --container jenkins ./backup.sh jenkins-k8s/0:/backup.sh
juju ssh --container jenkins jenkins-k8s/0 /bin/bash
bash /backup.sh
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
juju scp --container jenkins jenkins-k8s/0:/backup/jenkins_backup.tar.gz jenkins_backup.tar.gz
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
juju remove-application jenkins-k8s
JENKINS_APP=jenkins-k8s
juju remove-application $JENKINS_APP
```

## Restore the backup on a new charm instance
Expand All @@ -50,13 +56,14 @@ 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
juju scp --container jenkins ./jenkins_backup.tar.gz jenkins-k8s/0:/jenkins_backup.tar.gz
tar zxvf jenkins_backup.tar.gz
chown -R 2000:2000 /backup
cp -R /backup/* /var/lib/jenkins
rm -rf /backup /jenkins_backup.tar.gz
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
pebble restart jenkins
juju ssh --container jenkins $JENKINS_UNIT pebble restart jenkins
```

0 comments on commit 30797ad

Please sign in to comment.