Last active
January 3, 2020 12:25
-
-
Save JackCuthbert/1db41d737ac74f6c5b68d4d4e24bed49 to your computer and use it in GitHub Desktop.
Borg Backup script, modified from https://borgbackup.readthedocs.io/en/stable/quickstart.html#automating-backups
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/sh | |
# sudo crontab -e | |
# * 3 * * * export BORG_PASSPHRASE=repo_passphrase; /path/to/backup.sh /path/to/repo.borg /source/folder/to/backup >> /path/to/backup.log 2>&1 | |
# some helpers and error handling: | |
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; } | |
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM | |
info "Starting backup" | |
borg create \ | |
--verbose \ | |
--filter AME \ | |
--list \ | |
--stats \ | |
--show-rc \ | |
--compression lz4 \ | |
--exclude-if-present .nobackup \ | |
"$1"::"{hostname}-{utcnow}" "$2" | |
backup_exit=$? | |
info "Pruning repository" | |
borg prune \ | |
--list \ | |
--prefix '{hostname}-' \ | |
--show-rc \ | |
--keep-daily 3 \ | |
--keep-weekly 2 \ | |
--keep-monthly 3 \ | |
"$1" | |
prune_exit=$? | |
# use highest exit code as global exit code | |
global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit )) | |
if [ ${global_exit} -eq 0 ]; then | |
info "Backup and Prune finished successfully" | |
elif [ ${global_exit} -eq 1 ]; then | |
info "Backup and/or Prune finished with warnings" | |
else | |
info "Backup and/or Prune finished with errors" | |
fi | |
exit ${global_exit} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment