1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_restic_archiver.git synced 2024-08-16 10:09:49 +02:00

Try to improve Mail Reporting

This commit is contained in:
L3D 2021-04-29 11:20:40 +02:00
parent 5e3970d2fa
commit 269c04d22f
Signed by: l3d
GPG key ID: CD08445BFF4313D1
4 changed files with 37 additions and 10 deletions

View file

@ -41,11 +41,11 @@ restic_archiver__repos: {}
# keep_within: 1 # keep_within: 1
# how long should we store all backups by default # how long should we store all backups by default
restic_archiver__keep: 9 restic_archiver__keep: 5
restic_archiver__keep_hourly: 28 restic_archiver__keep_hourly: 16
restic_archiver__keep_daily: 26 restic_archiver__keep_daily: 14
restic_archiver__keep_weekly: 8 restic_archiver__keep_weekly: 8
restic_archiver__keep_monthly: 13 restic_archiver__keep_monthly: 16
restic_archiver__keep_yearly: 12 restic_archiver__keep_yearly: 12
# owner and user of all restic stuff # owner and user of all restic stuff
@ -67,13 +67,21 @@ restic_archiver__umount_after_usage: false
restic_archiver__package: restic_archiver__package:
- cron - cron
restic_archiver__log_output: true restic_archiver__log_output: true
restic_archiver__logrotate: true restic_archiver__logrotate: true
restic_archiver__mailsummary: false
restic_archiver__mail_on_error: false
restic_archiver__mailaddress: 'root@localhost'
# restic default options # restic default options
restic_archiver__default_opt: '' restic_archiver__default_opt: ''
# additional msgs
restic_archiver__additional_mail_msg: ''
# version check for this playbook (true is recomended) # version check for this playbook (true is recomended)
submodules_versioncheck: false submodules_versioncheck: false
```
restic_archiver__cache_config: false
restic_archiver__cache_dir: '~/.cache/restic'
```

View file

@ -50,6 +50,7 @@ restic_archiver__log_output: true
restic_archiver__logrotate: true restic_archiver__logrotate: true
restic_archiver__mailsummary: false restic_archiver__mailsummary: false
restic_archiver__mail_on_error: false
restic_archiver__mailaddress: 'root@localhost' restic_archiver__mailaddress: 'root@localhost'
# restic default options # restic default options

View file

@ -7,12 +7,17 @@
export XDG_CACHE_HOME={{ restic_archiver__cache_dir }} export XDG_CACHE_HOME={{ restic_archiver__cache_dir }}
{% endif %} {% 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) %} {% if restic_archiver__mail_report | default(false) %}
# This file is also designed to create a overview # This file is also designed to create a overview
# over the restic backup and # over the restic backup and
# send it by mail - if wanted # send it by mail - if wanted
found_error=false
cat <<EOT > /tmp/mailcontent cat <<EOT > /tmp/mailcontent
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@ -194,15 +199,20 @@ restic {{ restic_archiver__default_opt }} check
{% endif %} {% endif %}
} || { # catch } || { # catch
echo -e "<h1>ALARM, ALRM</h1>\n<h2>SOMETING IN $RESTIC_REPOSITORY went wrong</h2>" >> /tmp/mailcontent echo -e "<h1>ALARM, ALARM</h1>\n<h2>SOMETING IN $RESTIC_REPOSITORY went wrong</h2>" >> /tmp/mailcontent
awk 'NR==3{print "<h1>ALARM, ALRM</h1>\n<h2>SOMETING IN $RESTIC_REPOSITORY went wrong</h2>"}1' /tmp/mailcontent >> /tmp/mailcontentx awk 'NR==3{print "<h1>ALARM, ALARM</h1>\n<h2>SOMETING IN $RESTIC_REPOSITORY went wrong</h2>"}1' /tmp/mailcontent >> /tmp/mailcontentx
mv /tmp/mailcontentx /tmp/mailcontent mv /tmp/mailcontentx /tmp/mailcontent
found_error=true
{% if restic_archiver__mail_on_error | bool %}
restic_archiver__send_mail_on_error=true
{% endif %}
} }
{% endfor %} {% endfor %}
sync sync
{% if restic_archiver__mail_report | default(false) %}
cat <<EOT >> /tmp/mailcontent cat <<EOT >> /tmp/mailcontent
<br/><br/><br/> <br/><br/><br/>
<br/><br/><br/> <br/><br/><br/>
@ -216,7 +226,15 @@ $(df -h)
</html> </html>
EOT EOT
mail -a "Content-type: text/html" -s "restic backup report" {{ restic_archiver__mailaddress }} < /tmp/mailcontent 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 %} {% if restic_archiver__umount_after_usage %}
umount {{ restic_archiver__mount_disk }} umount {{ restic_archiver__mount_disk }}

View file

@ -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' playbook_version_path: 'role-restic_archiver_roles-ansible_github.com.version'