DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Jenkins Backup and Restore


Backup:

cd $JENKINS_HOME
tar zcf jenkins-full-16.11.24.tar.gz *`

Restore:

  1. deploy a Jenkins container;

  2. When asking for plugins to install, choose "choose plugins myself", unselect all, and click 'install' button;

  3. Stop Jenkins server;

  4. Extract Jenkins backup tarball into $JENKINS_HOME:

    cd $JENKINS_HOME tar zxf jenkins-full-16.11.24.tar.gz` chown -R $USER:$USER ./

  5. 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
#!/bin/sh
rsync -rtvu --include='config.xml' --exclude='**/**/**' bvt@10.0.2.74:/home/bvt/.jenkins/jobs/ bvtBackup/jobs/ 
rsync -rtvu --exclude='*/' bvt@10.0.2.74:/home/bvt/.jenkins/plugins/ bvtBackup/plugins/ 
rsync -rtvu --include='*.xml' --exclude='*' bvt@10.0.2.74:/home/bvt/.jenkins/ bvtBackup/

Restore

Restore to a Running Jenkins Server

  1. Copy modified new configuration files to the home directory of Jenkins;

  2. java -jar jenkins-cli.jar -s http://localhost:8088 reload-configuration

Start a New Jenkins Server from Backuped Files

  1. Copy above file to the home directory of Jenkins;

  2. Specify Jenkins home directory: export JENKINS_HOME=...;

  3. Start Jenkins server: java -jar jenkins.war



Published

Aug 1, 2013

Last Updated

Aug 1, 2013

Category

Tech

Tags

  • jenkins 26

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor