Diff
1diff --git a/README b/README
2index 83ec4bb5f40eace16cc644e64d046351c3c2b07d..3cb90bb3e49438cd816605893bbe4fd796fd48e0 100644
3--- a/README
4+++ b/README
5@@ -9,7 +9,10 @@ passphrases.
6
7 Most importantly, you can easily backup the script and your gpg key in a
8 convenient passphrase-encrypted file. This comes in in handy if/when your
9-machine ever does go belly up.
10+machine ever does go belly up.
11+
12+Optionally, you can set up an email address where the log file will be sent.
13+Useful when the script is used via cron.
14
15 More information about this script avaiable at:
16 http://damontimm.com/code/dt-s3-backup
17@@ -35,8 +38,9 @@ REQUIREMENTS
18
19 * duplicity
20 * gpg
21-* Amazon S3
22+* Amazon S3
23 * s3cmd (optional)
24+* mailx (optional)
25
26 COMMON USAGE EXAMPLES
27 =====================
28@@ -51,7 +55,7 @@ COMMON USAGE EXAMPLES
29 $ dt-s3-backup.sh --full
30
31 * Restore your entire backup:
32- $ dt-s3-backup.sh --restore
33+ $ dt-s3-backup.sh --restore
34 You will be prompted for a restore directory
35
36 $ dt-s3-backup.sh --restore /home/user/restore-folder
37@@ -80,7 +84,7 @@ NEXT VERSION WISH LIST
38 ======================
39
40 * --restore-dir option
41-* restore files from a specific time period
42-
43+* restore files from a specific time period
44+* support multiple MTAs for the email alert feature
45
46-Thanks to Mario Santagiuliana for his help.
47+Thanks to Mario Santagiuliana for his help.
48diff --git a/dt-s3-backup.sh b/dt-s3-backup.sh
49index 2afd9820254a127ddf1cfcff4be41525288c5343..e38efa8dad1247228019d27d594ff1b0c8bafa7e 100755
50--- a/dt-s3-backup.sh
51+++ b/dt-s3-backup.sh
52@@ -100,6 +100,18 @@ LOG_FILE="duplicity-`date +%Y-%m-%d_%H-%M`.txt"
53 LOG_FILE_OWNER="foobar_user_name:foobar_user_name"
54 VERBOSITY="-v3"
55
56+# EMAIL ALERT
57+# Provide an email address to receive the logfile by email. If no email
58+# address is provided, no alert will be sent.
59+# You can set a custom from email address and a custom subject (both optionally)
60+# If no value is provided for the subject, the following value will be
61+# used by default: "DT-S3 Alert ${LOG_FILE}"
62+# MTA used: mailx
63+#EMAIL="admin@example.com"
64+EMAIL_TO=
65+EMAIL_FROM=
66+EMAIL_SUBJECT=
67+
68 # TROUBLESHOOTING: If you are having any problems running this script it is
69 # helpful to see the command output that is being generated to determine if the
70 # script is causing a problem or if it is an issue with duplicity (or your
71@@ -114,6 +126,7 @@ VERBOSITY="-v3"
72 LOGFILE="${LOGDIR}${LOG_FILE}"
73 DUPLICITY="$(which duplicity)"
74 S3CMD="$(which s3cmd)"
75+MAIL="$(which mailx)"
76
77 NO_S3CMD="WARNING: s3cmd is not installed, remote file \
78 size information unavailable."
79@@ -419,6 +432,17 @@ fi
80
81 echo -e "-------- END DT-S3-BACKUP SCRIPT --------\n" >> ${LOGFILE}
82
83+if [ $EMAIL_TO ]; then
84+ if [ ! -x "$MAIL" ]; then
85+ echo -e "Email coulnd't be sent. mailx not available." >> ${LOGFILE}
86+ else
87+ EMAIL_FROM=${EMAIL_FROM:+"-r ${EMAIL_FROM}"}
88+ EMAIL_SUBJECT=${EMAIL_SUBJECT:="DT-S3 Alert ${LOG_FILE}"}
89+ ${MAIL} -s """${EMAIL_SUBJECT}""" $EMAIL_FROM ${EMAIL_TO} < ${LOGFILE}
90+ echo -e "Email alert sent to ${EMAIL_TO} using ${MAIL}" >> ${LOGFILE}
91+ fi
92+fi
93+
94 if [ ${ECHO} ]; then
95 echo "TEST RUN ONLY: Check the logfile for command output."
96 fi