-
-
Save btamayo/c74c18a51b0a75a1cff9923d914668b0 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 18 * * * /root/jenkins-backup-to-artifactory.sh >/var/log/jenkinsbackup/jenkinsbackup.`date +\%Y\%m\%d\%H\%M\%S`.log 2>&1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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