Only use pushover if it's installed, an email if there's a recipient.

This commit is contained in:
Darren 'Tadgy' Austin 2023-10-29 17:43:56 +00:00
commit 7e1bd8c9ae
2 changed files with 7 additions and 5 deletions

View file

@ -3,6 +3,8 @@
# Copyright (c) 2023:
# Darren 'Tadgy' Austin <darren (at) afterdark.org.uk>
# Licensed under the terms of the GNU General Public License version 3.
#
# Perform backup tasks in a generic way.
# Base configuration.
BACKUP_MOUNTPOINT="/localdata"
@ -72,8 +74,8 @@ source /etc/mail.conf "backups" 2>/dev/null || {
# Make sure BACKUP_MOUNTPOINT is a mountpoint.
mountpoint "$BACKUP_MOUNTPOINT" >/dev/null 2>&1 || {
CONFIG_FILE="backups" /opt/bin/pushover -T "Backup" -p '-1' -m "Failure: $RSYNC_SOURCE"
mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "Backup failure: $RSYNC_SOURCE" "${EMAIL_TO[@]}" <<-EOF
[[ -x "/opt/bin/pushover" ]] && CONFIG_FILE="backups" /opt/bin/pushover -T "Backup" -p '-1' -m "Failure: $RSYNC_SOURCE"
[[ -n "${EMAIL_TO[*]}" ]] && mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "Backup failure: $RSYNC_SOURCE" "${EMAIL_TO[@]}" <<-EOF
'$BACKUP_MOUNTPOINT' is not a mountpoint.
EOF
exit 1
@ -85,8 +87,8 @@ ERR="$?"
# Send a notification and mail a log if there were errors.
(( ERR != 0 )) && (( ERR != 10 )) && (( ERR != 24 )) && {
CONFIG_FILE="backups" /opt/bin/pushover -T "Backup" -p '-1' -m "Failure: $RSYNC_SOURCE"
mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "Backup failure: $RSYNC_SOURCE" "${EMAIL_TO[@]}" <<-EOF
[[ -x "/opt/bin/pushover" ]] && CONFIG_FILE="backups" /opt/bin/pushover -T "Backup" -p '-1' -m "Failure: $RSYNC_SOURCE"
[[ -n "${EMAIL_TO[*]}" ]] && mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "Backup failure: $RSYNC_SOURCE" "${EMAIL_TO[@]}" <<-EOF
Exit code: $ERR
Output:
$(< "$RSYNC_LOG")

View file

@ -1,5 +1,5 @@
#!/bin/bash
# Version: 0.0.1
# Version: 0.1.0
# Copyright (c) 2023:
# Darren 'Tadgy' Austin <darren (at) afterdark.org.uk>
# Licensed under the terms of the GNU General Public License version 3.