diff --git a/VPS/restic-backup.sh b/VPS/restic-backup.sh index dfeb0ac..b92cbe2 100755 --- a/VPS/restic-backup.sh +++ b/VPS/restic-backup.sh @@ -70,26 +70,28 @@ fi # Sleep to allow time for propagation sleep 60 +# Remove old and stale data if [ -z "$error_message" ]; then - restic check --verbose > check_output.log 2>&1 + 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 check failed ! See log below.\n" - error_message="$error_message""Backup purge will not be run.\n\n" - error_message="$error_message""$(cat check_output.log)" + 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 + restic check --verbose > check_output.log 2>&1 +fi +if [ $? -ne 0 ]; then + error_message="Restic check failed ! See log below.\n" + error_message="$error_message""Backup purge will not be run.\n\n" + error_message="$error_message""$(cat check_output.log)" fi # Clean up and remove old backups 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 echo -e "$error_message" | mail -aFrom:"$mail_sender" -s "[$(uname -n)] ⚠️ Backup error $(date +%D-%Hh%M)" "$mail_recipients"