- sync
JENKINS_HOME
toBACKUP_DIR
- commit file changes (addition/deletion)
- log action to file
backup.log
inJENKINS_LOG
directory
Backup JENKINS_HOME
by syncing it to
BACKUP_DIR
and commit the diffs into git.
Restore an older version of JENKINS_HOME
by checking out
an old commit into BACKUP_DIR
and rsync
this to JENKINS_HOME
.
Old commits are listed to be selected as user input.
BACKUP_DIR
is the folder of the local git repository keeping the
changes of Jenkins configuration.
JENKINS_HOME
jenkins home directory, set in/etc/default/jenkins
GIT_USER
name of the commiterGIT_EMAIL
email of the commiterBACKUP_DIR
keeps a synced copy ofJENKINS_HOME
in local git repoCOMMIT_MESSAGE
We assume a working git repo in BACKUP_DIR
and
- user
jenkins
to have credentials to write toBACKUP_DIR
- user
jenkins
to have credentials to pull/push the local git repo inBACKUP_DIR
- user
jenkins
to start/restart service jenkins
To backup Jenkins, type:
sudo -u jenkins /path/to/backup_to_git.sh "Commit message"
To restore Jenkins, type:
sudo -u jenkins /restore_from_git.sh
LOGGING TO /var/log/jenkins/backup.log
[Wed Feb 3 14:34:54 UTC 2016]
[Wed Feb 3 14:34:54 UTC 2016] Starting to restore Service Jenkins on AMI i-0f83ec56e936ca5ad
[Wed Feb 3 14:34:54 UTC 2016] Showing you available git commits
f22178d jenkins: Job [Test-Colorize2] hierarchy renamed from [Test Colorize2] to [Test-Colorize2]
bacdb57 jenkins: Job [Test Colorize2] configuration updated
b2cd8f0 jenkins: Job [Test-Colorize] hierarchy renamed from [Test Colorize] to [Test-Colorize]
17734e4 jenkins: Job [Test Colorize] configuration updated
b62547b jenkins: User [Michael Turner] configuration updated
5dbdf91 jenkins: Job [Docker-Build-Apache] configuration updated
0121d30 jenkins: Plugin configuration files updated
Enter your commit:
The orginal idea is from
- https://github.com/nghiant2710/jenkins-backup and
- https://github.com/luisalima/backup_jenkins_config
- functions.sh provides functions
- backup_to_git.sh
rsync
fromJENKINS_HOME
toBACKUP_DIR
- commit new files into the git repo
- push_backup_to_remote.sh
- push commits into the remote git repo
- restore_from_git.sh
- show recent commits
- let user select a commit
- check out this commit into the backup directory
rsync
fromBACKUP_DIR
toJENKINS_HOME