From 53f0b8557289a406c40780626cd3acefa28fb9a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Sch=C3=A4ferdiek?= Date: Thu, 26 Jan 2023 00:42:05 +0100 Subject: [PATCH] Allow override of mail in notifier and explain notifier examples for restic backup (sending mail on start and finish of backups) --- usr/local/bin/notifier | 11 +++++++++++ usr/share/doc/system-helpers/restic/mybackup/check.sh | 10 +++++++++- .../doc/system-helpers/restic/mybackup/create.sh | 8 ++++++++ usr/share/doc/system-helpers/restic/mybackup/prune.sh | 10 +++++++++- .../doc/system-helpers/restic/mybackup/report.sh | 4 ++-- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/usr/local/bin/notifier b/usr/local/bin/notifier index bbc1845..ccea046 100755 --- a/usr/local/bin/notifier +++ b/usr/local/bin/notifier @@ -33,6 +33,12 @@ NOTIFIER_MAIL_ENABLED="true"; NOTIFIER_GOTIFY_ENABLED="false"; NOTIFIER_MAIL_ADDRESS=$3; +argsMailProvided="false" + +if [[ -n "${NOTIFIER_MAIL_ADDRESS}" ]]; then + argsMailProvided="true" +fi + # check for config file apply_config() { local config=$1; @@ -95,6 +101,11 @@ source_config() { source_config "$HOME/.notifier.conf" "/etc/notifier.conf" check_requirements "${NOTIFIER_MAIL_ENABLED}" "${NOTIFIER_GOTIFY_ENABLED}" "${NOTIFIER_MAIL_ADDRESS}" +if [[ "${argsMailProvided}" == "true" ]]; then + NOTIFIER_MAIL_ADDRESS=$3 + echo "Overwriting mail with argument value" +fi + SUBJECT="${NOTIFIER_SUBJECT}" MESSAGE="${NOTIFIER_CONTENT}" diff --git a/usr/share/doc/system-helpers/restic/mybackup/check.sh b/usr/share/doc/system-helpers/restic/mybackup/check.sh index 0bead4a..65cd399 100755 --- a/usr/share/doc/system-helpers/restic/mybackup/check.sh +++ b/usr/share/doc/system-helpers/restic/mybackup/check.sh @@ -2,6 +2,14 @@ # pre action or use ExecStartPre +# Example using notifier: +# me="$0" +# notifier "[restic - $(hostname)] $me - START" "Started $me." + /usr/bin/restic check -# post action or adapt ExecStartPost \ No newline at end of file +# post action or adapt ExecStartPost + +# Example using notifier: +# me="$0" +# notifier "[restic - $(hostname)] $me - END" "Ended $me." diff --git a/usr/share/doc/system-helpers/restic/mybackup/create.sh b/usr/share/doc/system-helpers/restic/mybackup/create.sh index f912f53..56572a7 100755 --- a/usr/share/doc/system-helpers/restic/mybackup/create.sh +++ b/usr/share/doc/system-helpers/restic/mybackup/create.sh @@ -2,6 +2,10 @@ # pre action or use ExecStartPre +# Example using notifier: +# me="$0" +# notifier "[restic - $(hostname)] $me - START" "Started $me." + /usr/bin/restic backup \ $(echo $RESTIC_ADDITIONAL_CREATE_PARAMS) \ --exclude-file "${RESTIC_FILE_EXCLUDE}" \ @@ -10,3 +14,7 @@ /usr/bin/restic forget $(echo $RESTIC_KEEP) # post action or adapt ExecStartPost + +# Example using notifier: +# me="$0" +# notifier "[restic - $(hostname)] $me - END" "Ended $me." diff --git a/usr/share/doc/system-helpers/restic/mybackup/prune.sh b/usr/share/doc/system-helpers/restic/mybackup/prune.sh index 22287e9..d5002bd 100755 --- a/usr/share/doc/system-helpers/restic/mybackup/prune.sh +++ b/usr/share/doc/system-helpers/restic/mybackup/prune.sh @@ -2,6 +2,14 @@ # pre action or use ExecStartPre +# Example using notifier: +# me="$0" +# notifier "[restic - $(hostname)] $me - START" "Started $me." + /usr/bin/restic prune -# post action or adapt ExecStartPost \ No newline at end of file +# post action or adapt ExecStartPost + +# Example using notifier: +# me="$0" +# notifier "[restic - $(hostname)] $me - END" "Ended $me." diff --git a/usr/share/doc/system-helpers/restic/mybackup/report.sh b/usr/share/doc/system-helpers/restic/mybackup/report.sh index 9048707..282e3b4 100755 --- a/usr/share/doc/system-helpers/restic/mybackup/report.sh +++ b/usr/share/doc/system-helpers/restic/mybackup/report.sh @@ -13,5 +13,5 @@ echo -e "$STATS\n\n$SNAPSHOTS" me="$0" echo -e "$STATS\n\n$SNAPSHOTS" | mailx -Ssendwait -s "[restic - $(hostname)] $me - REPORT" "${RESTIC_REPORT_MAIL}" -# or -# notifier "[restic - $(hostname)] $me - REPORT" "$(echo -e "$STATS\n\n$SNAPSHOTS" )" +# Example when using notifier (you can omit RESTIC_REPORT_MAIL though to have it send to default): +# notifier "[restic - $(hostname)] $me - REPORT" "$(echo -e "$STATS\n\n$SNAPSHOTS" )" "${RESTIC_REPORT_MAIL}"