Open samrocketman opened 6 years ago
Sometimes it is necessary to read-only backup on the remote host. The following script is designed to backup Jenkins on a remote host that is read-only.
The following example will execute backup.sh
to compress the remote Jenkins configuration and write it to local disk on your computer without writing to disk on the remote host.
bash backup.sh user@hostname > backup.tgz
The script supports up to 3 arguments:
user@hostname
to connect to the remote host.-maxdepth
to optimize the time it takes. By default the depth is 2
. For a jenkins-bootstrap-jervis version of Jenkins the value should be 7
.Customize the user home (-maxdepth 2
is still used).
bash backup.sh user@hostname /path/to/jenkins_home > backup.tgz
To backup a remote Jervis-based Jenkins instance, the following command should be used (-maxdepth 7
).
bash backup.sh user@hostname /var/lib/jenkins 7 > backup.tgz
I prefer GPG. The following is an example using my own GPG key.
bash backup.sh user@hostname /var/lib/jenkins 7 | gpg -er E8F732347257E65F -o backup.tgz.gpg
When a backup successfully runs you should see output similar to the following.
+ echo 'Backup as the following user:'
Backup as the following user:
+ whoami
root
+ cd /var/lib/jenkins
+ find . -maxdepth 7 '(' -path './config-history/*' -o -path './plugins/*' -o -path './secret*' -o -path './*.xml' -o -path ./jenkins-versions.manifest -o -path './*.groovy.d/*' -o -path './userContent/*' -o -type f '(' -name config.xml -o -name nextBuildNumber ')' ')'
+ sed 's#^./##'
+ tar czT -
If you encrypted your backup locally, then you'll need to decrypt it.
gpg -do backup.tgz < backup.tgz.gpg
To extract your local backup run the following.
mkdir restore
cd restore/
tar -xzf ../backup.tgz
Please note, if your $JENKINS_HOME
was on Linux and you try to extract on Mac OS X, then you'll encounter errors due to differences in the filesystem used by Mac. Extract the Linux tar on a Linux machine and you shouldn't get errors.
Back up jenkins config without build history.