How To Backup Jenkins Data and Configurations

jenkins thin backup plugin settings

It is very important to have Jenkins backup with its data and configurations. It includes, job configs, build logs, plugins, plugin configuration etc.

In this article, we will cover different scenarios for backing up Jenkins data and configurations.

Jenkins Backup Using Thin Backup Plugin

Jenkins Thin Backup is a popular plugin for backing up Jenkins. It backs up all the data based on your schedule and it handles the backup retention as well.

To get started, first install the plugin.

1. Go to Manage Jenkins –> Manage Plugins

2. Click the Available tab and search for “Thin backup”

jenkins thin backup plugin

3. Install the plugin and restart Jenkins.

[irp posts=”1289″ name=”How to Setup Custom UI Theme For Jenkins”]

Backup Configuration

Once installed, follow the steps given below for configuring backup settings.

1. Go to Manage Jenkins — > ThinBackup

2. Click settings option.

jenkins thin backup plugin settings

3. Enter the backup options as shown below and save it. All the options are self-explanatory. The backup directory you specify should be writable by the user which is running the Jenkins service. All the jenkins backup will be saved to the backup directory you specify.

jenkins backup configuration

4. Now, you can test if the backup is working by clicking the Backup Now option. It will create a backup of jenkins data in the backup directory you specified in the settings.

jenkins think backup test

5. If you check the backup directory in the server, you can see the backup created. For every new backup, it will attach the timestamp to the folder name and keeps the old backup based on the retention policy you mentioned in the settings.

An example is shown below.

[[email protected] backup]$ pwd
/var/lib/jenkins/backup
[[email protected] backup]$ ls
FULL-2017-08-20_05-42  FULL-2017-08-20_05-43  FULL-2017-08-20_05-44
[[email protected] backup]$

Backing up the Backup

It is not a good idea to keep the jenkins back in Jenkins itself. It is a must to move thin backups to cloud storage or any other backup location. So that, even if Jenkins server crashes you will have all the data.

If you are on AWS, Azure or Google CLoud, you can upload the backups respective storage solutions.

Jenkins Backup Using Disk Snapshots

As you know, Jenkins doesn’t have a database. All the configurations are stored as files in the /var/lib/jenkins folder.

If your environment supports disk snapshots, here is what you can do for backing up jenkins data.

  1. Attach an external disk to your Jenkins server.
  2. Mount the disk to the server on a folder, say /jenkins_data
  3. If you have existing data, move all data from /var/lib/jenkins to /jenkins_data folder first.
  4. Symlink /var/lib/jenkins to /jenkins_data.
  5. Restart Jenkins and check if you jenkins is using the newly mounted disk.
  6. Now, you can take a timely snapshot of the extra disk. This will serve as a point in time backup for your jenkins.

Also, we suggest you use the Thin backup plugin in conjunction with disk snapshots.

jenkins thin backup plugin settings

How To Use Multiple gcloud Configuration From a Single Workstation

multiple gcloud configuration

Sometimes you might work with different google cloud accounts and want to have all the gcloud configuration on a single workstation.

In this post I will explain how to configure multiple gcloud configuration on a single workstation.

All the gcloud configs are present in  ~/.config/gcloud/configurations folder

The configs present in the configurations folder would look like the following.

config_default       config_devopscube

As you can see, all the configurations start with the config_ keyword.

Follow the steps given below for the configuration

1. cd in to the config directory.

~/.config/gcloud/configurations

2. Create a new configuration file with config_ prefix

vi config_demo-account

3. Enter the required parameters in the config file and save it. An example is shown below. You should change the values according to your google cloud account, project, zone and region.

[core]
account = [email protected]
project = devopscube

[compute]
zone = asia-east1-b	
region = asia-east1

4. For using any new configuration, you need to activate it. Use the following command to activate the configuration you created. You just need to specify the suffix of the configuration name as shown below.

gcloud config configurations activate demo-account

5. Once activated, login to the google cloud account using the following command.

gcloud auth login

6. Once logged in, you will be able to make all the gcloud api calls for the new configuration.

Like this you can maintain multiple gcloud configuration and use it when ever you need it.

Hope this article helps!

 

 

multiple gcloud configuration