Skip to content

Instantly share code, notes, and snippets.

@chluehr
Created November 5, 2017 10:57
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chluehr/65465681ec401d8dd119d685a68ececd to your computer and use it in GitHub Desktop.
Save chluehr/65465681ec401d8dd119d685a68ececd to your computer and use it in GitHub Desktop.
Backup via restic to Backblaze
#!/bin/bash
#
# Setup:
# wget https://github.com/restic/restic/releases/download/v0.7.3/restic_0.7.3_linux_amd64.bz2
# bunzip2 restic_0.7.3_linux_amd64.bz2
# mv restic_0.7.3_linux_amd64 /usr/local/bin/restic
# chmod a+x /usr/local/bin/restic
#
# crontab -e
# 0 1 * * * /root/bin/restic-backup.sh 2>&1 >>/var/log/restic-backup.log
#
echo -n "BACKUP restic START: " ; date
unset HISTFILE
export B2_ACCOUNT_ID=""
export B2_ACCOUNT_KEY=""
export RESTIC_REPOSITORY="b2:my-repo-name"
export RESTIC_PASSWORD=""
export DBNAME=""
export BACKUP_PATH="/var/www/sites"
# only needed once:
# restic init
# exit
echo "Dumping database $DBNAME ... "
mysqldump --add-drop-table $DBNAME |gzip > /var/www/sites/$DBNAME.sql.gz
echo "restic backup ... "
# this can fail if repo is locked!
restic backup $BACKUP_PATH
# cleanup old snapshots - prune is expensive!
$echo "restic forget ... "
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --keep-yearly 5
echo "restic prune ... "
restic prune
echo -n "BACKUP restic END: " ; date
# eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment