Last active
August 26, 2016 15:15
-
-
Save stevenschobert/16832f188dabedb216dd51ca22df01aa to your computer and use it in GitHub Desktop.
My go-to hacky backup solutions: gzip directories up to Dropbox! Uses https://github.com/andreafabrizi/Dropbox-Uploader
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 | |
MAX_NUM_BACKUPS=10 | |
DB_LOCATION=/root/dropbox_uploader.sh | |
DB_CONFIG=/root/.dropbox_uploader | |
BACKUP_FILENAME=ss_ranch_bkup | |
BKP_DIRS="/home/docker/rancher /home/docker/nginx" | |
EXCLUDE_DIRS="/home/docker/nginx/ssl" | |
TMP_DIR="/tmp/" | |
DATE=$(date +"%Y-%m-%d_%H%M%S") | |
BKP_FILE="$TMP_DIR$BACKUP_FILENAME_$DATE.tar" | |
# Upload new backup | |
tar cf "$BKP_FILE" --exclude="$EXCLUDE_DIRS" $BKP_DIRS | |
gzip "$BKP_FILE" | |
$DB_LOCATION -f $DB_CONFIG upload "$BKP_FILE.gz" "/$DATE/$BACKUP_FILENAME.gz" | |
rm -fr "$BKP_FILE.gz" | |
# Remove old backups | |
NEW_DIRS=$($DB_LOCATION list / | awk 'NR != 1 { print $3; }' | sort -r) | |
DIRS_TO_REMOVE=$(echo "$NEW_DIRS" | awk "NR > $MAX_NUM_BACKUPS { print; }") | |
for dir in $DIRS_TO_REMOVE | |
do | |
$DB_LOCATION delete $dir | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment