8985d9c432bb5731f7b944cc9eef481e47030cc6

Author
Sławomir Paszkiewicz <paszczus@uni.opole.pl>
Committer
Sławomir Paszkiewicz <paszczus@uni.opole.pl>
Date

Message

- 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

Diff

 1diff --git a/duplicity-backup.conf.example b/duplicity-backup.conf.example
 2index ca2e0aebe4fef837406cd0c754be32285d065f5f..16bc6b2139ecb85095b6e1afa1bda8786a787551 100644
 3--- a/duplicity-backup.conf.example
 4+++ b/duplicity-backup.conf.example
 5@@ -77,6 +77,10 @@
 6 #
 7 ROOT="/home"
 8 
 9+# Set hostname for this duplicity instance, usefull for e-mail reports
10+#
11+HOSTNAME=$(hostname -f)
12+
13 # ------------------------------------------------------------------------------
14 # BACKUP DESTINATION INFORMATION
15 # ------------------------------------------------------------------------------
16@@ -371,6 +375,7 @@ VERBOSITY="-v3"
17 EMAIL_TO=
18 EMAIL_FROM=
19 EMAIL_SUBJECT=
20+EMAIL_FAILURE_ONLY="yes" # send e-mail only if there was an error while creating backup
21 
22 # command to use to send mail
23 MAIL="mailx"     # default command for Linux mail
24diff --git a/duplicity-backup.sh b/duplicity-backup.sh
25index 2c6c9c09b2d72303324a579bd214d28de12e8028..382f751c19b8a6ac179b297b12f7785c8c06657a 100755
26--- a/duplicity-backup.sh
27+++ b/duplicity-backup.sh
28@@ -555,6 +555,7 @@ duplicity_cleanup()
29 }
30 
31 duplicity_backup()
32+{
33 {
34   eval ${ECHO} ${DUPLICITY} ${OPTION} ${VERBOSITY} ${STATIC_OPTIONS} \
35   ${ENCRYPT} \
36@@ -563,6 +564,9 @@ duplicity_backup()
37   ${EXCLUDEROOT} \
38   ${ROOT} ${DEST} \
39   >> ${LOGFILE}
40+} || {
41+  BACKUP_ERROR=1
42+}
43 }
44 
45 setup_passphrase()
46@@ -680,7 +684,7 @@ backup_this_script()
47 check_variables
48 check_logdir
49 
50-echo -e "--------    START DUPLICITY-BACKUP SCRIPT    --------\n" >> ${LOGFILE}
51+echo -e "--------    START DUPLICITY-BACKUP SCRIPT for ${HOSTNAME}   --------\n" >> ${LOGFILE}
52 
53 get_lock
54 
55@@ -832,7 +836,20 @@ esac
56 
57 echo -e "---------    END DUPLICITY-BACKUP SCRIPT    ---------\n" >> ${LOGFILE}
58 
59-email_logfile
60+if [ ${EMAIL_FAILURE_ONLY} == "yes" ]
61+then
62+	if [ ${BACKUP_ERROR} ]; then
63+		EMAIL_SUBJECT="BACKUP ERROR: ${EMAIL_SUBJECT}"
64+		email_logfile
65+	fi
66+else
67+	if [ ${BACKUP_ERROR} ]; then
68+		EMAIL_SUBJECT="BACKUP ERROR: ${EMAIL_SUBJECT}"
69+	else
70+		EMAIL_SUBJECT="BACKUP OK: ${EMAIL_SUBJECT}"
71+	fi
72+		email_logfile
73+fi
74 
75 # remove old logfiles
76 # stops them from piling up infinitely