Backup:
cd $JENKINS_HOME
tar zcf jenkins-full-16.11.24.tar.gz *`
Restore:
-
deploy a Jenkins container;
-
When asking for plugins to install, choose "choose plugins myself", unselect all, and click 'install' button;
-
Stop Jenkins server;
-
Extract Jenkins backup tarball into $JENKINS_HOME:
cd $JENKINS_HOME tar zxf jenkins-full-16.11.24.tar.gz` chown -R $USER:$USER ./
-
Start Jenkins server;
--- old ---
Backup
Working directory: We will backup all files into folder "bvtBackup" in current working directory. In this case the CWD is ~/docs, so all files will be backuped into ~/docs/bvtBackup.
Backup Job Configuration Files
rsync -rtvu --include='config.xml' --exclude='**/**/**' bvt@10.0.2.74:/home/bvt/.jenkins/jobs/ bvtBackupjobs/
Here "--exclude='//**'" limits the recursive depth is 2 (all subdirectories of "jobs" deeper than 2 are ignored).
Backup Plugins
rsync -rtvu --exclude='*/' bvt@10.0.2.74:/home/bvt/.jenkins/plugins/ bvtBackup/plugins/
Exclude all directories, because they will be automatically extracted from .jpi(or .hpi) files when Jenkins startup.
Backup System Level Configurations
rsync -rtvu --include='*.xml' --exclude='*' bvt@10.0.2.74:/home/bvt/.jenkins/ bvtBackup/
Here we can see that option include has higher priority than exclude.
Other Things not Backuped
User information, stored in "users" directory. And some security stuff.
Put them all together
For efficiency, we save all above actions in one script bvt_backup.sh in ~/docs, and we can simply sync all above files by run this script:
1 2 3 4 |
|
Restore
Restore to a Running Jenkins Server
-
Copy modified new configuration files to the home directory of Jenkins;
-
java -jar jenkins-cli.jar -s http://localhost:8088 reload-configuration
Start a New Jenkins Server from Backuped Files
-
Copy above file to the home directory of Jenkins;
-
Specify Jenkins home directory: export JENKINS_HOME=...;
-
Start Jenkins server: java -jar jenkins.war