Skip to content

Instantly share code, notes, and snippets.

@devops-rob
Last active December 4, 2017 20:46
Show Gist options
  • Save devops-rob/2e5c81b1d71ec2cfba659a65c98d5f07 to your computer and use it in GitHub Desktop.
Save devops-rob/2e5c81b1d71ec2cfba659a65c98d5f07 to your computer and use it in GitHub Desktop.
Script to backup Jenkins Configurations to git
#!/bin/bash
#Jenkins backup script by DevOpsRob
#This script requires a git repo called jenkins_backup to be created
#You will need to add your ssh public key to the deploy keys of this newly created repo and allow read/write permissions
#Clone the repo into /var/lib/ folder
#Save this script to the /root/ folder
#Setup a crontab to run this script as per your requirement
#install git command line tools
yum install git -y
#Variables
backupdate=$(date +"%m-%d-%y")
#Copy Jenkins configuration files to the git repo clone folder
cp -frv /var/lib/jenkins/ /var/lib/jenkins_backup
#Add the config files to the index
cd /var/lib/jenkins_backup
git add /var/lib/jenkins_backup/jenkins/
#Commit the back up
git commit -m "backup-$backupdate"
#Push the backup to git
git push -u origin master
#Delete the local backup files
rm -rfv /var/lib/jenkins_backup/jenkins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment