Jenkins backup and Restore

To backup Jenkins, backup the JENKINS_HOME folder.

To restore Jenkins, sync back the JENKINS_HOME folder and restart jenkins.

JENKINS_HOME  directory structure  looks like the following:

JENKINS_HOME
 +- config.xml     (jenkins root configuration)
 +- *.xml          (other site-wide configuration files)
 +- userContent    (files in this directory will be served under your http://server/userContent/)
 +- fingerprints   (stores fingerprint records)
 +- plugins        (stores plugins)
 +- workspace (working directory for the version control system)
     +- [JOBNAME] (sub directory for each job)
 +- jobs
     +- [JOBNAME]      (sub directory for each job)
         +- config.xml     (job configuration file)
         +- latest         (symbolic link to the last successful build)
         +- builds
             +- [BUILD_ID]     (for each build)
                 +- build.xml      (build result summary)
                 +- log            (log file)
                 +- changelog.xml  (change log)

 

Script to Backup Jenkins:

Backup Jobs configuration file :

 rsync -av --include='config.xml' --exclude='**/**/**' /var/lib/jenkins/jobs/ root@192.168.1.2:/var/lib/jenkins/jobs/

Backup main configuration files:

 rsync -av --include='config.xml' --exclude='**/**/**' /var/lib/jenkins/plugins/ root@192.168.1.2:/var/lib/jenkins/plugins/

Backup main configuration files:

 rsync -av --include='*.xml' --exclude='**/**/**' /var/lib/jenkins/ root@192.168.1.2:/var/lib/jenkins/

Backup users configuration :

 rsync -av /var/lib/jenkins/user* root@192.168.1.2:/var/lib/jenkins/

Script to restore Jenkins:

Copy back the /var/lib/jenkins/ folder in 192.168.1.2 to the Jenkins main server and restart the jenkins service.

rsync -av /var/lib/jenkins/ roo@192.168.1.1:/var/lib/jenkins/
systemctl restart jenkins