From 265c33f2d9f6606a79538fb665bce7690061eedf Mon Sep 17 00:00:00 2001 From: Esa Nuuros Date: Mon, 26 Oct 2020 15:12:19 +0200 Subject: [PATCH] Do not exit on backup failure Exit caused email notifications to be not sent when backup fails. We especially want to be notified if a backup fails. --- backup.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/backup.sh b/backup.sh index 2187c31..809ebb9 100755 --- a/backup.sh +++ b/backup.sh @@ -31,18 +31,17 @@ logLast "AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}" # Do not save full backup log to logfile but to backup-last.log restic backup /data ${RESTIC_JOB_ARGS} --tag=${RESTIC_TAG?"Missing environment variable RESTIC_TAG"} >> ${lastLogfile} 2>&1 -rc=$? +backupRC=$? logLast "Finished backup at $(date)" -if [[ $rc == 0 ]]; then - echo "Backup Successfull" +if [[ $backupRC == 0 ]]; then + echo "Backup Successfull" else - echo "Backup Failed with Status ${rc}" + echo "Backup Failed with Status ${backupRC}" restic unlock copyErrorLog - exit 1 fi -if [ -n "${RESTIC_FORGET_ARGS}" ]; then +if [[ $backupRC == 0 ]] && [ -n "${RESTIC_FORGET_ARGS}" ]; then echo "Forget about old snapshots based on RESTIC_FORGET_ARGS = ${RESTIC_FORGET_ARGS}" restic forget ${RESTIC_FORGET_ARGS} >> ${lastLogfile} 2>&1 rc=$?