Created
June 20, 2017 01:20
-
-
Save ErmisCat/2d35f7cc4dbbaba841641a4c542ce7d1 to your computer and use it in GitHub Desktop.
Backup Jenkins config to an S3 bucket.
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 | |
| # MKDIR /backup | |
| # git clone this script there | |
| # SETUP CRONTAB: | |
| # crontab -e | |
| # PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin | |
| # 0 0 * * * cd /backup && ./jenkins-backup-s3.sh | |
| set -ex | |
| ndate=`date +%Y-%m-%d` | |
| JENKINS_HOME=/var/lib/jenkins | |
| BACKUP_DIR=/backup | |
| JENKINS_BACKUP=jenkins-backup | |
| JENKINS_DIR=/backup/jenkins-backup | |
| S3_BUCKET=s3://<CHANGEYOURBUCKET> | |
| rm -rf ${JENKINS_DIR} | |
| mkdir ${JENKINS_DIR} | |
| cd ${JENKINS_DIR} | |
| rsync -av --delete --exclude="jobConfigHistory" \ | |
| --exclude="war" \ | |
| --exclude="config-history" \ | |
| --exclude=".hudson" \ | |
| --exclude=".ivy2" \ | |
| --exclude=".m2" \ | |
| --exclude="lost+found" \ | |
| --include="*config.xml" \ | |
| --include="jobs/*/builds/*/log" \ | |
| --include="users/*" \ | |
| --include="*.hpi" \ | |
| --include="*.jpi" \ | |
| --include="*pinned" \ | |
| --include="*disabled" \ | |
| --include="scriptler/*" \ | |
| --include="secrets/*" \ | |
| --include="*.xml" \ | |
| --include="*.key" \ | |
| --exclude="*" \ | |
| --prune-empty-dirs ${JENKINS_HOME}/ . | |
| echo "${ndate} - Backup Jenkins" > ${JENKINS_DIR}/jenkins_backup.log | |
| cd /backup | |
| rm -rf *.tgz | |
| tar zcfv jenkins-backup-${ndate}.tgz ${JENKINS_BACKUP} | |
| aws s3 cp jenkins-backup-${ndate}.tgz ${S3_BUCKET} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment