1
0
Fork 0

Compare commits

..

3 commits

Author SHA1 Message Date
3c15c5a9f5 Run prune before checking the backup repository 2022-04-18 10:44:21 +01:00
9efacf4f8c Add example variables for mail sender/recicipients for backup 2022-04-18 10:27:49 +01:00
a278fdd40a Small adjustments to restic-backup
Reflect status of script from the VPS, mainly add a sleep interval after backup.
2022-04-18 10:22:53 +01:00

View file

@ -2,11 +2,14 @@
# Use setcap'd binary in home directory # Use setcap'd binary in home directory
#PATH="/home/restic/bin/:$PATH" #PATH="/home/restic/bin/:$PATH"
# Now uses binary in /usr/bin, which is also setcap'd #Not necessary anymore : binary in /usr/bin setcap'd
backup_origin="/backups/restic" backup_origin="/backups/restic"
backup_container="central-backup" backup_container="central-backup"
mail_sender='"Name""<sender@example.com>"'
mail_recipients="first@example.com,second@example.com"
if [[ -z "$1" || "$1" != "daily" && "$1" != "weekly" && "$1" != "monthly" ]]; then if [[ -z "$1" || "$1" != "daily" && "$1" != "weekly" && "$1" != "monthly" ]]; then
echo "Usage : backup [daily|weekly|monthly]" echo "Usage : backup [daily|weekly|monthly]"
exit 1 exit 1
@ -64,6 +67,19 @@ if [ $? -ne 0 ]; then
error_message="$error_message""$(cat backup_output.log)" error_message="$error_message""$(cat backup_output.log)"
fi fi
# Sleep to allow time for propagation
sleep 60
# Remove old and stale data
if [ -z "$error_message" ]; then
restic forget --verbose --prune --group-by tag --tag "$1" --keep-last "$backup_count" > forget_output.log 2>&1
fi
if [ $? -ne 0 ]; then
error_message="Restic forget failed ! See log bellow.\n\n"
error_message="$error_message""$(cat forget_output.log)"
fi
# Check repository status
if [ -z "$error_message" ]; then if [ -z "$error_message" ]; then
restic check --verbose > check_output.log 2>&1 restic check --verbose > check_output.log 2>&1
fi fi
@ -76,14 +92,6 @@ fi
# Clean up and remove old backups # Clean up and remove old backups
rm -rf temp/* rm -rf temp/*
if [ -z "$error_message" ]; then
restic forget --verbose --prune --group-by tag --tag "$1" --keep-last "$backup_count" > forget_output.log 2>&1
fi
if [ $? -ne 0 ]; then
error_message="Restic forget failed ! See log bellow.\n\n"
error_message="$error_message""$(cat forget_output.log)"
fi
if [ -n "$error_message" ]; then if [ -n "$error_message" ]; then
echo -e "$error_message" | mail -aFrom:"$mail_sender" -s "[$(uname -n)] ⚠️ Backup error $(date +%D-%Hh%M)" "$mail_recipients" echo -e "$error_message" | mail -aFrom:"$mail_sender" -s "[$(uname -n)] ⚠️ Backup error $(date +%D-%Hh%M)" "$mail_recipients"