Create a Jenkins backup/restore Unix/Linux

I told in the notes about installing, configuring, scaling, and jobs in Jenkins. come To a head yet that you need to have backups in order to rollback ago. I googled a couple of solutions. But I haven’t decided what is better. This will tell you about them.

Useful reading:

Installing Jenkins on Unix/Linux

Working with Jenkins-CLI in Unix/Linux

Installing Jenkins and Jenkins-slave in Unix/Linux

Language setup in Jenkins

Create a Jenkins backup/restore Unix/Linux

And so, we will need to install a plugin(s) (can be single choice, I used a few for comparison):

  • Thin backup
  • Backup Plugin
  • Periodic Backup
  • SCM Sync configuration

You can use other solutions:

  • To use Git and get “$JENKINS_HOME” under it.
  • To write a BASH script to create the job to execute.

Let’s move on to solutions!

The use of the Thin backup plugin for backup/restore Jenkins-Unix/Linux

Go to “Manage Jenkins” -> “Manage Plugins” and install “Thin backup”. I usually always restart Jenkins in order to apply all the settings and everything worked.

PS: To restart the Jenkins server, I use the “Restart Safely” plugin.

Settings backup, go to “Manage Jenkins” -> “ThinBackup”:

The ThinBackup plugin for Jenkins-and

In this plugin are:

  • Backup Now Button to make a backup now.
  • Restore — used to restore data.
  • Settings — backup.

Let’s start with the settings, click on it:

Configuring the thinBackup plugin to backup Jenkins

I said I needed fields and clicked on the “Save” button. Ie I will run backups on a specified schedule and skladyvaetsya in the “/backups” folder. Now you can run the “Backup now” to run a backup.

That’s all. You can use this plugin for Bekaa and restaurants.

Using the Backup Plugin of plugin for backup/restore Jenkins-Unix/Linux

Go to “Manage Jenkins” -> “Manage Plugins” and install “Backup plugin”. I usually always restart Jenkins in order to apply all the settings and everything worked.

Settings backup, go to “Manage Jenkins” -> “Backup manager”:

In this plugin are:

  • Setup — use to configure the backups.
  • Backup Hudson configuration to create a backup.
  • Restore Hudson configuration To restore a backup.

I brought a setup like the following:

After the settings click on “Save”. Click on “Backup Hudson configuration” to create a backup.

Using the Periodic Backup plugin for backup/restore Jenkins-Unix/Linux

Go to “Manage Jenkins” -> “Manage Plugins” and install “Periodic Backup”. I usually always restart Jenkins in order to apply all the settings and everything worked.

Settings backup, go to “Manage Jenkins” -> “Periodic Backup Manager”:

Menu Periodic Backup plugin

The plugin is not configured and needs to tconfigure. So, I will now click on “Configure”:

Configure Periodic Backup plugin

That’s all. You can perform a backup! This plugin is liked more than others!

Using the SCM Sync configuration plugin for backup/restore Jenkins-Unix/Linux

Go to “Manage Jenkins” -> “Manage Plugins” and install “SCM Sync configuration”. I usually always restart Jenkins in order to apply all the settings and everything worked.

Create the project in Galaba, for example “configurations/jenkins”.In this project I will keep all the settings.

Go to the “Manage Jenkins” -> “Configure System” and find the field “SCM” and fill the field. I couldn’t make friends with that plugin at all. Demolished it!

Use the bash script for backup/restore Jenkins-Unix/Linux

You can write scripts for every taste, using bash. There is a plugin to run scripts through the job. Now put the plug-in.

Go to “Manage Jenkins” -> “Manage Plugins” and install the “Exclusive Execution”. I usually always restart Jenkins in order to apply all the settings and everything worked. Create structure: Projects->Configurations. Ie folder Projects will be the projects, in this case, “Configurations” — configs (To create a folder, click “New item” and select “folder”).

Go to project and click on “New item” and click on the “Freestyle project”. Enter a name for the project, I have “jenkins-backup” and click “OK”:

Then go to created project and click on “Configure” and find the field “Source Code Management” and specify the URL where it will lie script for backup I have a complete solution of the brow, for example:

configuring SCM

Go ahead and go to “Build Triggers” tab and complete:

Ie fill the periodicity with which to run the script.

H 3 * * *

After this, go in “Build” tab and then from the list select “Execute shell”. and set the settings to start:

The startup configuration script with parameters via Build-execute shell

Added to the field the following text:

./jenkins-backup.sh $JENKINS_HOME /backups/backup_'date +"%Y_%m_%d_%H:%M:%S"`.tar.gz

Then click on “Save”. This will run the backup at the specified time. If necessary, you can start the job, manually (by Clicking on “Build Now”).

PS: you Can make a backup of rotat to all the old backups are deleted by the machine, for example, add another “Execute shell” command:

find /backups/backup_* -mtime +7 -delete

Ie, the backups will be kept 7 days, the rest will be removed.

Here is another example of a script that you can use:

#!/bin/bash

# Setup
#
# - Create a new Jenkins Job
# - Mark "None" for Source Control Management
# - Select the "Build Periodically" build trigger
# - configure to run as frequently as you like
# - Add a new "Execute Shell" build step
# - Paste the contents of this file as the command
# - Save
# 
# NOTE: before this job will work, you'll need to manually navigate to the $JENKINS_HOME directory 
# and do the initial set up of the git repository. 
# Make sure the appropriate remote is added and the default remote/branch set up.
# 

# Jenkins Configuraitons Directory
cd $JENKINS_HOME

# Add general configurations, job configurations, and user content
git add -- *.xml jobs/*/*.xml named usercontent/*

# only add the user configurations if they exist
if [ -d users ]; then
 user_configs=`ls users/*/config.xml`

 if [ -n "$user_configs" ]; then
 git add $user_configs
fi
fi

# mark as deleted anything that's been, well, deleted
to_remove=`git status | grep "deleted" | awk '{print $3}"

if [ -n "$to_remove" ]; then
 git rm --ignore-unmatch $to_remove
fi

git commit-m "Automated commit of Jenkins"

git push -q -u origin master

As for me, everything is logical and understandable, what is he doing… the Same way you can do the job and run periodically. Thus, all config files will be in git.

Conclusion: I’ve tested several plugins and chose to use scripts or Thin backup, Periodic Backup plugins. But if there are other solutions — write, will complement the material.

And I have all of the article “creating a Jenkins backup/restore Unix/Linux” is completed.

Source: linux-notes.org

(Visited 135 times, 1 visits today)