Created
November 5, 2017 10:57
-
-
Save chluehr/65465681ec401d8dd119d685a68ececd to your computer and use it in GitHub Desktop.
Backup via restic to Backblaze
This file contains 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
#!/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