From 269c04d22fdaef23e513ef1f92c4d8d23f75ce19 Mon Sep 17 00:00:00 2001 From: L3D Date: Thu, 29 Apr 2021 11:20:40 +0200 Subject: [PATCH] Try to improve Mail Reporting --- README.md | 22 +++++++++++++++------- defaults/main.yml | 1 + templates/restic_forget_snapshots.j2 | 22 ++++++++++++++++++++-- vars/main.yml | 2 +- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 27bd146..9715cf6 100644 --- a/README.md +++ b/README.md @@ -41,11 +41,11 @@ restic_archiver__repos: {} # keep_within: 1 # how long should we store all backups by default -restic_archiver__keep: 9 -restic_archiver__keep_hourly: 28 -restic_archiver__keep_daily: 26 +restic_archiver__keep: 5 +restic_archiver__keep_hourly: 16 +restic_archiver__keep_daily: 14 restic_archiver__keep_weekly: 8 -restic_archiver__keep_monthly: 13 +restic_archiver__keep_monthly: 16 restic_archiver__keep_yearly: 12 # owner and user of all restic stuff @@ -67,13 +67,21 @@ restic_archiver__umount_after_usage: false restic_archiver__package: - cron -restic_archiver__log_output: true -restic_archiver__logrotate: true + restic_archiver__log_output: true + restic_archiver__logrotate: true + + restic_archiver__mailsummary: false + restic_archiver__mail_on_error: false + restic_archiver__mailaddress: 'root@localhost' # restic default options restic_archiver__default_opt: '' +# additional msgs +restic_archiver__additional_mail_msg: '' # version check for this playbook (true is recomended) submodules_versioncheck: false -``` +restic_archiver__cache_config: false +restic_archiver__cache_dir: '~/.cache/restic' +``` diff --git a/defaults/main.yml b/defaults/main.yml index 8e40d88..eee40d8 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -50,6 +50,7 @@ restic_archiver__log_output: true restic_archiver__logrotate: true restic_archiver__mailsummary: false +restic_archiver__mail_on_error: false restic_archiver__mailaddress: 'root@localhost' # restic default options diff --git a/templates/restic_forget_snapshots.j2 b/templates/restic_forget_snapshots.j2 index b196346..fc9c6af 100644 --- a/templates/restic_forget_snapshots.j2 +++ b/templates/restic_forget_snapshots.j2 @@ -7,12 +7,17 @@ export XDG_CACHE_HOME={{ restic_archiver__cache_dir }} {% endif %} +{% if restic_archiver__mail_on_error | bool %} +# Send a mail on error! +restic_archiver__send_mail_on_error=false +{% endif %} {% if restic_archiver__mail_report | default(false) %} # This file is also designed to create a overview # over the restic backup and # send it by mail - if wanted +found_error=false cat < /tmp/mailcontent @@ -194,15 +199,20 @@ restic {{ restic_archiver__default_opt }} check {% endif %} } || { # catch -echo -e "

ALARM, ALRM

\n

SOMETING IN $RESTIC_REPOSITORY went wrong

" >> /tmp/mailcontent -awk 'NR==3{print "

ALARM, ALRM

\n

SOMETING IN $RESTIC_REPOSITORY went wrong

"}1' /tmp/mailcontent >> /tmp/mailcontentx +echo -e "

ALARM, ALARM

\n

SOMETING IN $RESTIC_REPOSITORY went wrong

" >> /tmp/mailcontent +awk 'NR==3{print "

ALARM, ALARM

\n

SOMETING IN $RESTIC_REPOSITORY went wrong

"}1' /tmp/mailcontent >> /tmp/mailcontentx mv /tmp/mailcontentx /tmp/mailcontent +found_error=true +{% if restic_archiver__mail_on_error | bool %} +restic_archiver__send_mail_on_error=true +{% endif %} } {% endfor %} sync +{% if restic_archiver__mail_report | default(false) %} cat <> /tmp/mailcontent





@@ -216,7 +226,15 @@ $(df -h) EOT + mail -a "Content-type: text/html" -s "restic backup report" {{ restic_archiver__mailaddress }} < /tmp/mailcontent +{% endif %} + +{% if restic_archiver__mail_on_error | bool %} +if [ "$restic_archiver__send_mail_on_error" == true ]; then +mail -s "restic backup report" {{ restic_archiver__mailaddress }} <<< 'Something went wrong while running restic backup archiver at {{ ansible_hostname }}' +fi +{% endif %} {% if restic_archiver__umount_after_usage %} umount {{ restic_archiver__mount_disk }} diff --git a/vars/main.yml b/vars/main.yml index fe582a1..75514ab 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,3 +1,3 @@ --- -playbook_version_number: 42 # should be int +playbook_version_number: 43 # should be int playbook_version_path: 'role-restic_archiver_roles-ansible_github.com.version'