Skip to content

Commit

Permalink
docs: update backup file docs (#149)
Browse files Browse the repository at this point in the history
* update backup file path

* docs: copy pasteable

* docs: add docstring returns
  • Loading branch information
yanksyoon authored Apr 30, 2024
1 parent 5f2316f commit 4e019f7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
51 changes: 29 additions & 22 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
```
5 changes: 4 additions & 1 deletion tests/integration/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,13 @@ async def test_thinbackup_plugin(ops_test: OpsTest, unit_web_client: UnitWebClie
)
res.raise_for_status()

async def has_backup():
async def has_backup() -> bool:
"""Get whether the backup is created.
The backup folder of format FULL-<backup-date> should be created.
Returns:
Whether the backup file has successfully been created.
"""
ret, stdout, stderr = await ops_test.juju(
"ssh", "--container", "jenkins", unit_web_client.unit.name, "ls", backup_path
Expand Down

0 comments on commit 4e019f7

Please sign in to comment.