diff --git a/do-backup b/do-backup index 171cec0..6e8de5a 100755 --- a/do-backup +++ b/do-backup @@ -81,10 +81,16 @@ source /etc/mail.conf "backups" 2>/dev/null || { # Make sure BACKUP_MOUNTPOINT is a mountpoint. mountpoint "$BACKUP_MOUNTPOINT" >/dev/null 2>&1 || { [[ -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 + if [[ -n "${EMAIL_TO[*]}" ]]; then + mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "Backup failure: $RSYNC_SOURCE" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \ + printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2 + '$BACKUP_MOUNTPOINT' is not a mountpoint. + EOF + exit 1 + else + printf "%s: %s\\n" "${0##*/}" "no recipient configured for mail delivery" >&2 + exit 1 + fi } # Do the backup. @@ -94,15 +100,20 @@ ERR="$?" # Send a notification and mail a log if there were errors. (( ERR != 0 )) && (( ERR != 10 )) && (( ERR != 24 )) && { [[ -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") - EOF - rm -f "$RSYNC_LOG" - exit 1 + if [[ -n "${EMAIL_TO[*]}" ]]; then + mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "Backup failure: $RSYNC_SOURCE" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \ + printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2 + Exit code: $ERR + Output: + $(< "$RSYNC_LOG") + EOF + RET=1 + else + printf "%s: %s\\n" "${0##*/}" "no recipient configured for mail delivery" >&2 + RET=1 + fi } rm -f "$RSYNC_LOG" -exit 0 +exit "${RET:-0}"