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.

Deja una respuesta

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Salir /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Salir /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Salir /  Cambiar )

Conectando a %s

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.