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:

 +- 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@

Backup main configuration files:

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

Backup main configuration files:

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

Backup users configuration :

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

Script to restore Jenkins:

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

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