How to backup Jenkins

There are a couple of plugins out there to backup Jenkins. Some of them focus on jobs configuration while others focus on Jenkins global configuration. All of them have in common that store a file (or set of files) in a certain location in the same box where Jenkins is running. In  my opinion this is not enough because in case of a hardware failure you could lose Jenkins and also the backups.

Maybe there is a plugin that solves this situation but I didn’t find it, so I decided to do the following:

  1. Create a code repository
  2. Create a PowerShell script to copy all jobs configuration files to the repository folder and commit them
  3. Create a Windows Scheduled Task to trigger the script once a day

To write the script mentioned in (2) you need to know some internal details about Jenkins. For each job you create, Jenkins creates a folder with the job name under the location $JENKINS_HOME/jobs. Inside the job folder you will find a lot of files but the only important for us is the config.xml which contains the job configuration.

If this explanation is not clear enough or if you simply don’t want to waste time writing the script, you can take a look at the script I wrote.

One more detail: I am wrapping my PS script with a cmd script in order to redirect the output to a file that I used as a log file.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.