Allow override of mail in notifier and explain notifier examples for restic backup (sending mail on start and finish of backups)
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Alexander Schäferdiek 2023-01-26 00:42:05 +01:00
parent 7a5c6a7461
commit 53f0b85572
5 changed files with 39 additions and 4 deletions

View file

@ -33,6 +33,12 @@ NOTIFIER_MAIL_ENABLED="true";
NOTIFIER_GOTIFY_ENABLED="false"; NOTIFIER_GOTIFY_ENABLED="false";
NOTIFIER_MAIL_ADDRESS=$3; NOTIFIER_MAIL_ADDRESS=$3;
argsMailProvided="false"
if [[ -n "${NOTIFIER_MAIL_ADDRESS}" ]]; then
argsMailProvided="true"
fi
# check for config file # check for config file
apply_config() { apply_config() {
local config=$1; local config=$1;
@ -95,6 +101,11 @@ source_config() {
source_config "$HOME/.notifier.conf" "/etc/notifier.conf" source_config "$HOME/.notifier.conf" "/etc/notifier.conf"
check_requirements "${NOTIFIER_MAIL_ENABLED}" "${NOTIFIER_GOTIFY_ENABLED}" "${NOTIFIER_MAIL_ADDRESS}" 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}" SUBJECT="${NOTIFIER_SUBJECT}"
MESSAGE="${NOTIFIER_CONTENT}" MESSAGE="${NOTIFIER_CONTENT}"

View file

@ -2,6 +2,14 @@
# pre action or use ExecStartPre # pre action or use ExecStartPre
# Example using notifier:
# me="$0"
# notifier "[restic - $(hostname)] $me - START" "Started $me."
/usr/bin/restic check /usr/bin/restic check
# post action or adapt ExecStartPost # post action or adapt ExecStartPost
# Example using notifier:
# me="$0"
# notifier "[restic - $(hostname)] $me - END" "Ended $me."

View file

@ -2,6 +2,10 @@
# pre action or use ExecStartPre # pre action or use ExecStartPre
# Example using notifier:
# me="$0"
# notifier "[restic - $(hostname)] $me - START" "Started $me."
/usr/bin/restic backup \ /usr/bin/restic backup \
$(echo $RESTIC_ADDITIONAL_CREATE_PARAMS) \ $(echo $RESTIC_ADDITIONAL_CREATE_PARAMS) \
--exclude-file "${RESTIC_FILE_EXCLUDE}" \ --exclude-file "${RESTIC_FILE_EXCLUDE}" \
@ -10,3 +14,7 @@
/usr/bin/restic forget $(echo $RESTIC_KEEP) /usr/bin/restic forget $(echo $RESTIC_KEEP)
# post action or adapt ExecStartPost # post action or adapt ExecStartPost
# Example using notifier:
# me="$0"
# notifier "[restic - $(hostname)] $me - END" "Ended $me."

View file

@ -2,6 +2,14 @@
# pre action or use ExecStartPre # pre action or use ExecStartPre
# Example using notifier:
# me="$0"
# notifier "[restic - $(hostname)] $me - START" "Started $me."
/usr/bin/restic prune /usr/bin/restic prune
# post action or adapt ExecStartPost # post action or adapt ExecStartPost
# Example using notifier:
# me="$0"
# notifier "[restic - $(hostname)] $me - END" "Ended $me."

View file

@ -13,5 +13,5 @@ echo -e "$STATS\n\n$SNAPSHOTS"
me="$0" me="$0"
echo -e "$STATS\n\n$SNAPSHOTS" | mailx -Ssendwait -s "[restic - $(hostname)] $me - REPORT" "${RESTIC_REPORT_MAIL}" echo -e "$STATS\n\n$SNAPSHOTS" | mailx -Ssendwait -s "[restic - $(hostname)] $me - REPORT" "${RESTIC_REPORT_MAIL}"
# or # 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" )" # notifier "[restic - $(hostname)] $me - REPORT" "$(echo -e "$STATS\n\n$SNAPSHOTS" )" "${RESTIC_REPORT_MAIL}"