From 268987fd8e87e3bb652caea80c015b862489745b Mon Sep 17 00:00:00 2001 From: Esa Nuuros Date: Mon, 26 Oct 2020 15:00:49 +0200 Subject: [PATCH 1/3] Install curl for webhooks --- Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 85cb830..0e332f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,8 +6,7 @@ RUN unzip rclone-current-linux-amd64.zip && mv rclone-*-linux-amd64/rclone /bin/ FROM restic/restic:0.9.6 -# install mailx -RUN apk add --update --no-cache heirloom-mailx fuse +RUN apk add --update --no-cache heirloom-mailx fuse curl COPY --from=rclone /bin/rclone /bin/rclone From 265c33f2d9f6606a79538fb665bce7690061eedf Mon Sep 17 00:00:00 2001 From: Esa Nuuros Date: Mon, 26 Oct 2020 15:12:19 +0200 Subject: [PATCH 2/3] 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=$? From 4d2034ccd4188d91e32289c2d0b644272d664f30 Mon Sep 17 00:00:00 2001 From: Esa Nuuros Date: Mon, 26 Oct 2020 15:13:37 +0200 Subject: [PATCH 3/3] Pass backup exit code to post-backup.sh hook We can write our own hook that can choose what to do based on the exit code. For example, we may only want to sent notifications on failures. --- backup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backup.sh b/backup.sh index 809ebb9..12ce6dc 100755 --- a/backup.sh +++ b/backup.sh @@ -69,7 +69,7 @@ fi if [ -f "/hooks/post-backup.sh" ]; then echo "Starting post-backup script ..." - /hooks/post-backup.sh + /hooks/post-backup.sh $backupRC else echo "Post-backup script not found ..." fi