How do you backup Jenkins jobs & master configs?
I'd like to backup all Jenkins jobs and config files. What's the easiest way of doing it?
All jobs (jobs/) and master config files (config.xml) can be found in backup Jenkins home folder (JENKINS_HOME ) in the following structure:
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)
Most of the config are in XML format, so backing all .xml files should be enough.
All the settings, build logs, artefact archives are stored under the JENKINS_HOME directory. Simply archive this directory to make a back up. Similarly, restoring the data is just replacing the contents of the JENKINS_HOME directory from a backup.
Back ups can be taken without stopping the server, but when you restore, please do stop the server.
For consistent backups it is good practice to keep the JENKINS_HOME directory under the Git repository.
For example:
cd $JENKINS_HOME
git init
shopt -s globstar
git add **/config.xml git commit -m'Added job config files' -aand pushing the files to the external repository. You can also add the following .gitignore file to ignore some files.