- added EMAIL_FAILURE_ONLY option to send e-mails only if there was an error while doing backup

- added HOSTNAME option to inform in e-mail report for which server is this report for
- e-mail subject is rewrited now to know if backup was OK or not
This commit is contained in:
Sławomir Paszkiewicz 2015-09-02 10:17:14 +02:00
parent 142f4c6b89
commit 8985d9c432
2 changed files with 24 additions and 2 deletions

View file

@ -77,6 +77,10 @@
#
ROOT="/home"
# Set hostname for this duplicity instance, usefull for e-mail reports
#
HOSTNAME=$(hostname -f)
# ------------------------------------------------------------------------------
# BACKUP DESTINATION INFORMATION
# ------------------------------------------------------------------------------
@ -371,6 +375,7 @@ VERBOSITY="-v3"
EMAIL_TO=
EMAIL_FROM=
EMAIL_SUBJECT=
EMAIL_FAILURE_ONLY="yes" # send e-mail only if there was an error while creating backup
# command to use to send mail
MAIL="mailx" # default command for Linux mail

View file

@ -555,6 +555,7 @@ duplicity_cleanup()
}
duplicity_backup()
{
{
eval ${ECHO} ${DUPLICITY} ${OPTION} ${VERBOSITY} ${STATIC_OPTIONS} \
${ENCRYPT} \
@ -563,6 +564,9 @@ duplicity_backup()
${EXCLUDEROOT} \
${ROOT} ${DEST} \
>> ${LOGFILE}
} || {
BACKUP_ERROR=1
}
}
setup_passphrase()
@ -680,7 +684,7 @@ backup_this_script()
check_variables
check_logdir
echo -e "-------- START DUPLICITY-BACKUP SCRIPT --------\n" >> ${LOGFILE}
echo -e "-------- START DUPLICITY-BACKUP SCRIPT for ${HOSTNAME} --------\n" >> ${LOGFILE}
get_lock
@ -832,7 +836,20 @@ esac
echo -e "--------- END DUPLICITY-BACKUP SCRIPT ---------\n" >> ${LOGFILE}
email_logfile
if [ ${EMAIL_FAILURE_ONLY} == "yes" ]
then
if [ ${BACKUP_ERROR} ]; then
EMAIL_SUBJECT="BACKUP ERROR: ${EMAIL_SUBJECT}"
email_logfile
fi
else
if [ ${BACKUP_ERROR} ]; then
EMAIL_SUBJECT="BACKUP ERROR: ${EMAIL_SUBJECT}"
else
EMAIL_SUBJECT="BACKUP OK: ${EMAIL_SUBJECT}"
fi
email_logfile
fi
# remove old logfiles
# stops them from piling up infinitely