Skip to content

Instantly share code, notes, and snippets.

@stevenschobert
Last active August 26, 2016 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenschobert/16832f188dabedb216dd51ca22df01aa to your computer and use it in GitHub Desktop.
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
#!/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