Created
January 23, 2019 18:42
-
-
Save gustavoapolinario/5fc588bf58efceae7aecf1281c5f852f to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# Generate timestamped filename | |
TIMESTAMPED_TAG=`date +%Y-%m-%d-%H%M%S` | |
BACKUP_ARCHIVE="./jenkins-backup-${TIMESTAMPED_TAG}.tar.gz" | |
# Inconceivable race condition avoidance | |
if [-f $BACKUP_ARCHIVE ]; then | |
rm ${BACKUP_ARCHIVE} | |
fi | |
# Archive everything on jenkins but workspace, .file, .folders and m2 files, whatever these are | |
# If the jenkins folder changes half way through, tar will fail; retry up to 5 times | |
COUNTER=0 | |
until [ $COUNTER -ge 5 ] | |
do | |
tar -czvf ${BACKUP_ARCHIVE} --exclude="workspace" --exclude=".m2" --exclude=builds --exclude=".*" --exclude="hudson.model.JDK" --exclude="caches" --exclude="cache" --exclude="builds" /ebs/jenkins_home/ && break | |
# If we get here, tar failed! | |
echo "Archive creation failed, retrying..." | |
COUNTER=$[$COUNTER+1] | |
sleep 15 | |
done | |
# Place on s3 and cleanup | |
aws s3 --profile backup cp ${BACKUP_ARCHIVE} s3://backet-backup/jenkins/ | |
rm ${BACKUP_ARCHIVE} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment