Skip to content

Instantly share code, notes, and snippets.

@strebl
Last active October 4, 2015 04: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 strebl/3d9e629eda6959516534 to your computer and use it in GitHub Desktop.
Save strebl/3d9e629eda6959516534 to your computer and use it in GitHub Desktop.
Simple Shell Backup to Drobox

Before first run

cd /home/strebel
curl "https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh" -o dropbox_uploader.sh
chmod 775 dropbox_uploader.sh
./dropbox_uploader.sh
``

To configure dropbox_uploader.sh, you'll need to create a Dropbox API key.
#!/usr/bin/env bash
TIME=`date +%Y%m%d` # Current date (format: yyymmdd)
DELDATE=`date --date="-30 day" +%Y%m%d` # Current date minus 30 days. (format: yyymmdd)
FILENAME=teamspeak-backup-$TIME.tar.gz # The filename of the backup.
SRCDIR=/home/strebel/teamspeak # Location of Important Data Directory (Source of backup).
DROPBOX_UPLOADER=/home/strebel/dropbox_uploader.sh # Dropbox Uploader Path
DROPBOX_UPLOADER_CONFIG=/home/strebel/.dropbox_uploader # Dropbox Uploader Config Path
# Tar directory
echo "Compressing \"$SRCDIR\" to \"$FILENAME\"..."
tar -cpzf -C /tmp/$FILENAME $SRCDIR .
# Upload the new file
$DROPBOX_UPLOADER -f $DROPBOX_UPLOADER_CONFIG upload /tmp/$FILENAME .
# Delete old backups
BACKUPS=$($DROPBOX_UPLOADER -f $DROPBOX_UPLOADER_CONFIG list | sed -n 's/.*\([0-9]\{8\}\)\.tar.*/\1/p')
for time in $BACKUPS; do
if (($time <= $DELDATE))
then
echo "Deleting backup from date $time."
$DROPBOX_UPLOADER -f $DROPBOX_UPLOADER_CONFIG delete teamspeak-backup-$time.tar.gz
else
echo "Backup from date $time isn't old enought to delete."
fi
done
# Delete tar
rm /tmp/$FILENAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment