Skip to content

Instantly share code, notes, and snippets.

@rendicott
Last active November 23, 2018 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rendicott/37d9a8c9ed5fcb94f22728964cef2e60 to your computer and use it in GitHub Desktop.
Save rendicott/37d9a8c9ed5fcb94f22728964cef2e60 to your computer and use it in GitHub Desktop.
quick backup script to tar and gzip the jenkins home directory and upload it to Artifactory for backup
5 18 * * * /root/jenkins-backup-to-artifactory.sh >/var/log/jenkinsbackup/jenkinsbackup.`date +\%Y\%m\%d\%H\%M\%S`.log 2>&1
#!/bin/bash
# Backs up the /var/lib/jenkins directory and uploads the archive to artifactory
TIMESTAMP="$(date +'%Y%m%d-%H%M%S')"
logger JENKINSBACKUP: Starting Jenkins backup at $TIMESTAMP
ARCHIVENAME=jenkins-config-$TIMESTAMP.tar.gz
UPLOADREPO="https://artifacts.company.com/artifactory/jenkins-backups/"
BACKUPFOLDER=/var/lib/jenkins
tar -zcf jenkins-config-$TIMESTAMP.tar.gz $BACKUPFOLDER
logger JENKINSBACKUP: Wrote archive $ARCHIVENAME
logger JENKINSBACKUP: Uploading $ARCHIVENAME to $UPLOADREPO
curl -v --data-binary @$ARCHIVENAME -X PUT $UPLOADREPO/$ARCHIVENAME
logger JENKINSBACKUP: Deleting archive file $ARCHIVENAME
rm -f $ARCHIVENAME
logger JENKINSBACKUP: Backup complete!
Dec 14 08:24:40 jenkins root: JENKINSBACKUP: Starting Jenkins backup at 20161214-082440
Dec 14 08:24:53 jenkins systemd: Started Session 25205 of user root.
Dec 14 08:24:53 jenkins systemd-logind: New session 25205 of user root.
Dec 14 08:24:53 jenkins systemd: Starting Session 25205 of user root.
Dec 14 08:25:42 jenkins root: JENKINSBACKUP: Wrote archive jenkins-config-20161214-082440.tar.gz
Dec 14 08:25:42 jenkins root: JENKINSBACKUP: Uploading jenkins-config-20161214-082440.tar.gz to https://artifacts.company.com/artifactory/jenkins-backups/
Dec 14 08:25:56 jenkins root: JENKINSBACKUP: Deleting archive file jenkins-config-20161214-082440.tar.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment