From 4e019f79eb78aeeb8b1dbb7eaa717522ef5a6a12 Mon Sep 17 00:00:00 2001 From: Yanks Yoon <37652070+yanksyoon@users.noreply.github.com> Date: Tue, 30 Apr 2024 19:32:34 +0900 Subject: [PATCH] docs: update backup file docs (#149) * update backup file path * docs: copy pasteable * docs: add docstring returns --- docs/how-to/resize-jenkins-storage.md | 51 +++++++++++++++------------ tests/integration/test_plugins.py | 5 ++- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/docs/how-to/resize-jenkins-storage.md b/docs/how-to/resize-jenkins-storage.md index a989a7c7..05baeb89 100644 --- a/docs/how-to/resize-jenkins-storage.md +++ b/docs/how-to/resize-jenkins-storage.md @@ -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 < 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 @@ -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 -``` \ No newline at end of file +juju ssh --container jenkins $JENKINS_UNIT pebble restart jenkins +``` diff --git a/tests/integration/test_plugins.py b/tests/integration/test_plugins.py index c1bb4dfd..461dccd0 100644 --- a/tests/integration/test_plugins.py +++ b/tests/integration/test_plugins.py @@ -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- 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