Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.