rework code for email and notifications (more DRY)

This commit is contained in:
zertrin 2016-03-28 23:46:40 +02:00
parent 279a5580fe
commit f3f4ddcd89

View file

@ -858,34 +858,24 @@ esac
echo -e "--------- END DUPLICITY-BACKUP SCRIPT ---------\n" >> "${LOGFILE}"
if [ "${EMAIL_FAILURE_ONLY}" = "yes" ]; then
if [ ${BACKUP_ERROR} ]; then
EMAIL_SUBJECT="BACKUP ERROR: ${EMAIL_SUBJECT}"
email_logfile
fi
# send email
if [ "${BACKUP_ERROR}" ]; then
EMAIL_SUBJECT="BACKUP ERROR: ${EMAIL_SUBJECT}"
else
if [ ${BACKUP_ERROR} ]; then
EMAIL_SUBJECT="BACKUP ERROR: ${EMAIL_SUBJECT}"
else
EMAIL_SUBJECT="BACKUP OK: ${EMAIL_SUBJECT}"
fi
email_logfile
EMAIL_SUBJECT="BACKUP OK: ${EMAIL_SUBJECT}"
fi
if [ "${NOTIFICATION_FAILURE_ONLY}" = "yes" ]; then
if [ ${BACKUP_ERROR} ]; then
NOTIFICATION_CONTENT="BACKUP ERROR: ${HOSTNAME} - \`${LOGFILE}\`"
send_notification
fi
[[ ${BACKUP_ERROR} || ! "$EMAIL_FAILURE_ONLY" = "yes" ]] && email_logfile
# send notification
if [ "${BACKUP_ERROR}" ]; then
NOTIFICATION_CONTENT="BACKUP ERROR: ${HOSTNAME} - \`$LOGFILE\`"
else
if [ ${BACKUP_ERROR} ]; then
NOTIFICATION_CONTENT="BACKUP ERROR: ${HOSTNAME} - \`${LOGFILE}\`"
else
NOTIFICATION_CONTENT="BACKUP OK: ${HOSTNAME} - \`${LOGFILE}\`"
fi
send_notification
NOTIFICATION_CONTENT="BACKUP OK: ${HOSTNAME} - \`$LOGFILE\`"
fi
[[ ${BACKUP_ERROR} || ! "$NOTIFICATION_FAILURE_ONLY" = "yes" ]] && send_notification
# remove old logfiles
# stops them from piling up infinitely
[[ -n "${REMOVE_LOGS_OLDER_THAN}" ]] && find "${LOGDIR}" -type f -mtime +"${REMOVE_LOGS_OLDER_THAN}" -delete