From 47f548d77e5b4c82705f31e251104d8c1900280b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lisowski?= Date: Tue, 30 Nov 2021 12:26:37 +0100 Subject: [PATCH] Fix #45: send email also on the main command failure --- templates/restic_script_Linux.j2 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/templates/restic_script_Linux.j2 b/templates/restic_script_Linux.j2 index 96151ec..93a15d3 100644 --- a/templates/restic_script_Linux.j2 +++ b/templates/restic_script_Linux.j2 @@ -136,6 +136,13 @@ then echo "$(date -u '+%Y-%m-%d %H:%M:%S') OK" {{ backup_result_log }} else echo "$(date -u '+%Y-%m-%d %H:%M:%S') ERROR" {{ backup_result_log }} + {% if item.mail_on_error is defined and item.mail_on_error == true %} + mail -s "restic backup failed on {{ ansible_hostname }}" {{ item.mail_address }} <<< "Something went wrong while running restic backup script running at {{ ansible_hostname }} at $(date -u '+%Y-%m-%d %H:%M:%S'). + {%- if item.src is defined -%} + {{ ' ' }}We tried to backup '{{ item.src }}'. + {%- endif -%} + {{ ' ' }}Please repair the restic-{{ item.name | replace(' ', '') }} job." + {% endif %} fi