From ffe99130f9526eb227a449e49890608c3ab011a8 Mon Sep 17 00:00:00 2001 From: mg Date: Fri, 18 Dec 2020 22:07:03 +0100 Subject: [PATCH] Error-Mail wenn restic-backup einen Exit-Code !=0 hat (#5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Link Typo Bugfix: Postfix - tlx-param Mailversand - wip Syntax Rolle postfix als Voraussetzung für restic Co-authored-by: Michael Grote <38253905+quotengrote@users.noreply.github.com> Reviewed-on: https://git.mgrote.net/mg/ansible/pulls/5 --- group_vars/all.yml | 2 +- roles/mgrote.restic/meta/main.yml | 3 +++ roles/mgrote.restic/templates/restic_backup.sh | 8 +++++++- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 roles/mgrote.restic/meta/main.yml diff --git a/group_vars/all.yml b/group_vars/all.yml index 0b49676c..752a9919 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -7,7 +7,7 @@ gmail_mail_nach_cronjob: false gmail_smtp_server: smtp.gmail.com gmail_smtp_server_port: 587 - gmail_smtp_use_tls: yes + gmail_smtp_use_tls: "yes" ### mgrote.set_apt_sources acng_server: acng.grote.lan acng_server_port: 9999 diff --git a/roles/mgrote.restic/meta/main.yml b/roles/mgrote.restic/meta/main.yml new file mode 100644 index 00000000..b3cb6676 --- /dev/null +++ b/roles/mgrote.restic/meta/main.yml @@ -0,0 +1,3 @@ +--- + dependencies: + - role: mgrote.postfix-gmail diff --git a/roles/mgrote.restic/templates/restic_backup.sh b/roles/mgrote.restic/templates/restic_backup.sh index 931d99fe..f96a08b6 100644 --- a/roles/mgrote.restic/templates/restic_backup.sh +++ b/roles/mgrote.restic/templates/restic_backup.sh @@ -19,12 +19,18 @@ function unlock() { # Damit prueft ob das Script ob es schon laeuft exlock ( - echo "--------------------------------------------------" +echo "--------------------------------------------------" echo $(date) mount -t cifs -o credentials="/etc/restic/smb_password.txt",vers=3.0 {{ restic_repository }} {{ restic_mount }} restic -r {{ restic_mount }} --password-file /etc/restic/password.txt backup --exclude-file /etc/restic/exclude.txt {{ restic_folders_to_backup }} +# Mail wenn Restix Exit != 0 #https://stackoverflow.com/a/45817972 +retVal=$? +if [ $retVal -ne 0 ]; then + echo "ERROR - Restic - $HOSTNAME" | mail -s "ERROR - Restic - $HOSTNAME" {{ empfaenger_mail }} +fi + umount {{ restic_mount }} echo "--------------------------------------------------"