EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Jenkins Backup

Home » Software Development » Software Development Tutorials » Jenkins Tutorial » Jenkins Backup

Jenkins Backup

Introduction to Jenkins Backup

Jenkins backup is a solution for keeping the backup of critical configuration settings related to Jenkins. Jenkins has a backup plugin that can used to backup. Jenkins Backup and restore refers to services and practices for making periodic copies of data like configuration and access rights settings. All the backup data which includes setting related to IAM (Identity Access Management), plugin, artifacts archives and build logs saved inJENKINS_HOME directory. The easiest way to backup is just to set the new folder with new backup and just copy it back whenever it’s required the same.

For any organization Backing up data is crucial to any business and Jenkins is not an exception. If you have right back up, it provides great confidence to any business in case of recovery needed with any unexpected situations like datacenter outage, Jenkins system failure, or accidental deletion of data.
There are multiple methods to back up the Jenkins configurations such as:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

1. using thin backup

2. using the git repo

The easiest approach which is mostly used that is a Jenkins plugin for the backup.

For example, for any organization the setting access rights and the job configuration by selecting the necessary plugin is quite a time taken the job, so it’s a good idea to organize regular backups of all the necessary settings and parameters. The Jenkins directory contains a list of build jobs configured and all the related settings for these jobs. Also, one of the Jenkins features provides an option for renaming an existing job at any time. We need to click on the reload config from the Jenkins home page to reflect the applied changes. Since Jenkins has several plugins that make it exceedingly useable many times by the users. It’s already has a plugin that can be used for the backup management i.e. “Thin Backup plugin”.

Process of Setting up a Backup and Restore Jenkins

We will consider the process of setting up a backup and restore Jenkins to a new server step by step:

Login to Jenkins UI

Step 1: Manage Jenkins ->manage plugins -> click on available ->select “Thin Backup”->install without start.

Popular Course in this category
Jenkins Training (4 Courses, 2+ Projects)4 Online Courses | 2 Hands-on Projects | 16+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,069 ratings)
Course Price

View Course

Related Courses
Java Training (40 Courses, 29 Projects, 4 Quizzes)All in One Software Development Bundle (600+ Courses, 50+ projects)

install without start

Step 2: By clicking on the manage Jenkins from the Jenkins home page redirected to the next page which is having an option for Manage plugins. On the next page, we can see the available tab, now select Thin Backup plugin and click on Install without restart button.

without restart button

We can see the plugin installed successfully after restarting Jenkins. We can found the newly installed plugin “Thin Backup plugin “under Manage Jenkins link.

Jenkins Thin Backup Setting

Step 1: After installing the plugin first thing we have to is the “Thin Backup” configurations ->manage Jenkins ->Thin Backup->setting

Backup Setting

We can see backup configuration settings are available below. The user who is running the Jenkins services is responsible to define all the below configuration. The first configuration to define the directory where all the settings and configurations related to Jenkins are going to store. We can also schedule the backup for time to time update.

Performing Backup

Step 1: To test whether the above configured backup setting is working or not, we have an option available“Backup Now”. Post clicking the Backup Now option, basically it creates a backup of Jenkins data and setting based on the below-configured directory. Generally backup will be trigger automatically as per the configured time in the backup schedule. We can also trigger the backup manually by following the below steps:

Performing Backup

Restoring Backup

The best way to check your backup data is, navigate to the specified back up directory. You could see the backup is created with the attached timestamp to the folder name. You can also find your old backup file which is available based on your retention policy settings.

Output directory where backup generated

ubuntu@ip-172-31-94-14:/var/lib/jenkins/backup$ ls -lrth
total 4.0K
drwxr-xr-x 4 jenkinsjenkins 4.0K May 27 10:06 FULL-2020-05-27_10-06
ubuntu@ip-172-31-94-14:/var/lib/jenkins/backup$

Note: Perform sanity once Jenkins restore task has been successfully done.

Let’s take a scenario where I have deleted some files from Jenkins directory and recovered it from the backup.

directory where backup generated

rm/Jenkins/hudson.plugins.git.GitTool.xml

rm: remove regular file ./lenkIns/hudson.plugins.git.GitTool.xml’? y

ls -l /Jenkins/hudson.plugins.git.GitTool.xml

ls: cannot access /jenkins/hudson.plugins.git.GitTool.xml: No such file or directory

Post deletion of some files, we have restored the data from the backup.

For restoring

Step 1: Manage Jenkins -> Thin Backup -> Restore

Jenkins Backup6

Step 2: Select the backup point from which you want to restore it back.

Jenkins Backup7

Now we have run the command to verify the file which was deleted is successfully restored or not.

Type the command “ls –l  /apps/jenkins/hudson.plugins.git.GitTool.xml” verify the file.

rm /aaps/jenkins/hudson.plugins.git.GitTool.xml

rm: remove regular file ‘/apps/jenkins/hudson.plugins.git.GitTool.xml’? y

ls -l /apps/jenkins/hudson.plugins.git.GitTool.xml

ls: cannot access /apps/jenkins/hudson.plugins.git.GitTool.xml: No such the or directory

ls -l /apps/jenkins/hudson.plugins.git.GitTool.xml

-rw-r–r–. 1 Jenkins Jenkins 370 May 27 04:31 /apps/jenkins/hudson.plugins.git.GitTool.xml

Using the git repo

Let’s suppose in any organization, it has followed the devops practice and configured Jenkins as part of their build process. Basically DevOps team wants to configure a process and as part of process to set up a periodic backup for any disaster.

Pipeline Script to take backup

Step 1: Create a new Jenkins Job. You should choose Freestyle project

Jenkins Backup8

Step 2: Let’s add a job that will completely backup Jenkins including all jobs, playbooks, whatever else you have there. It will backup everything located at /var/lib/Jenkins. Select the “Build Periodically” build trigger and configure to run as frequently as you like.

build trigger

commit the file

Create a new file Backup_config  and add the below script. Once the script added commit the file into source code repository.

Code:

pipeline {
agentany
stages {
stage("BACKUP"){ steps{
sh """#!/bin/bash
pushdbackup_config
sudogitconfig --local user.email "mahes.sharma23@gmail.com"
sudogitconfig --global user.name "Smaheshwar85"
find .|xargsgitrm
popd
cp -v var/lib/jenkins/*xml $WORKSPACE/backup_config
pushdvar/lib/jenkins/
fori in \$( find jobs|grep config.xml ); do
mkdir -p $WORKSPACE/backup_config/`dirname \$i`
cp \$i $WORKSPACE/backup_config/`dirname \$i`
done
popd
cp -rfvvar/lib/jenkins/secret* $WORKSPACE/backup_config/
cp -rfvvar/lib/jenkins/user* $WORKSPACE/backup_config/
pushdbackup_config
find .|xargsgit add
sudogit commit -a -m"Jenkins Backup Job"
"""
}} //steps // stage
stage("PUSH"){ steps{
sshagent(["$GIT_CREDENTIAL_ID"]) {
sh "cdbackup_config&&git push origin HEAD:$BACKUP_BRANCH"
} // sshagent
}} //steps // stage
}} //stages // pipeline

Output:

Jenkins Backup11

Once you have triggered the building backup is generated.

Recommended Articles

This is a guide to Jenkins Backup. Here we discuss an introduction to Jenkins Backup, the process of setting up and steps for restoration to understand better. You can also go through our other related articles to learn more –

  1. Uses of Jenkins
  2. What Is Cloud Computing?
  3. How To Install Joomla
  4. Jenkins Interview Questions And Answers

Jenkins Training (4 Courses, 2+ Projects)

4 Online Courses

2 Hands-on Projects

16+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Jenkins Tutorial
  • Basics
    • What is Jenkins
    • Is Jenkins Free
    • How to Install Jenkins
    • Uses of Jenkins
    • Jenkins Plugins
    • Jenkins Backup
    • Jenkins Email Notification
    • Jenkins Interview Questions

Related Courses

Jenkins Training Course

Java Training Course

Software Development Course Training

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - Jenkins Training (4 Courses, 2+ Projects) Learn More