From 8985d9c432bb5731f7b944cc9eef481e47030cc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Paszkiewicz?= Date: Wed, 2 Sep 2015 10:17:14 +0200 Subject: [PATCH 1/2] - 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 --- duplicity-backup.conf.example | 5 +++++ duplicity-backup.sh | 21 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/duplicity-backup.conf.example b/duplicity-backup.conf.example index ca2e0ae..16bc6b2 100644 --- a/duplicity-backup.conf.example +++ b/duplicity-backup.conf.example @@ -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 diff --git a/duplicity-backup.sh b/duplicity-backup.sh index 2c6c9c0..382f751 100755 --- a/duplicity-backup.sh +++ b/duplicity-backup.sh @@ -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 From e5d57852cec56e802665a41ee1bc356a3d675c08 Mon Sep 17 00:00:00 2001 From: zertrin Date: Thu, 8 Oct 2015 10:15:56 +0200 Subject: [PATCH 2/2] also send email on cleanup failure + replace introduced tabs with spaces --- duplicity-backup.sh | 64 +++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/duplicity-backup.sh b/duplicity-backup.sh index 382f751..699c590 100755 --- a/duplicity-backup.sh +++ b/duplicity-backup.sh @@ -540,33 +540,41 @@ duplicity_cleanup() { echo "----------------[ Duplicity Cleanup ]----------------" >> ${LOGFILE} if [[ "${CLEAN_UP_TYPE}" != "none" && ! -z ${CLEAN_UP_TYPE} && ! -z ${CLEAN_UP_VARIABLE} ]]; then - eval ${ECHO} ${DUPLICITY} ${CLEAN_UP_TYPE} ${CLEAN_UP_VARIABLE} ${STATIC_OPTIONS} --force \ - ${ENCRYPT} \ - ${DEST} >> ${LOGFILE} + { + eval ${ECHO} ${DUPLICITY} ${CLEAN_UP_TYPE} ${CLEAN_UP_VARIABLE} ${STATIC_OPTIONS} --force \ + ${ENCRYPT} \ + ${DEST} >> ${LOGFILE} + } || { + BACKUP_ERROR=1 + } echo >> ${LOGFILE} fi if [ ! -z ${REMOVE_INCREMENTALS_OLDER_THAN} ] && [[ ${REMOVE_INCREMENTALS_OLDER_THAN} =~ ^[0-9]+$ ]]; then - eval ${ECHO} ${DUPLICITY} remove-all-inc-of-but-n-full ${REMOVE_INCREMENTALS_OLDER_THAN} \ - ${STATIC_OPTIONS} --force \ - ${ENCRYPT} \ - ${DEST} >> ${LOGFILE} + { + eval ${ECHO} ${DUPLICITY} remove-all-inc-of-but-n-full ${REMOVE_INCREMENTALS_OLDER_THAN} \ + ${STATIC_OPTIONS} --force \ + ${ENCRYPT} \ + ${DEST} >> ${LOGFILE} + } || { + BACKUP_ERROR=1 + } echo >> ${LOGFILE} fi } duplicity_backup() { -{ - eval ${ECHO} ${DUPLICITY} ${OPTION} ${VERBOSITY} ${STATIC_OPTIONS} \ - ${ENCRYPT} \ - ${EXCLUDE} \ - ${INCLUDE} \ - ${EXCLUDEROOT} \ - ${ROOT} ${DEST} \ - >> ${LOGFILE} -} || { - BACKUP_ERROR=1 -} + { + eval ${ECHO} ${DUPLICITY} ${OPTION} ${VERBOSITY} ${STATIC_OPTIONS} \ + ${ENCRYPT} \ + ${EXCLUDE} \ + ${INCLUDE} \ + ${EXCLUDEROOT} \ + ${ROOT} ${DEST} \ + >> ${LOGFILE} + } || { + BACKUP_ERROR=1 + } } setup_passphrase() @@ -838,17 +846,17 @@ 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 + 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 + if [ ${BACKUP_ERROR} ]; then + EMAIL_SUBJECT="BACKUP ERROR: ${EMAIL_SUBJECT}" + else + EMAIL_SUBJECT="BACKUP OK: ${EMAIL_SUBJECT}" + fi + email_logfile fi # remove old logfiles