New feature - email alert using mailx

This commit is contained in:
Razvan Marescu 2010-12-07 20:58:50 -08:00
parent 1159584072
commit 4e00543450
2 changed files with 34 additions and 6 deletions

6
README
View file

@ -11,6 +11,9 @@ Most importantly, you can easily backup the script and your gpg key in a
convenient passphrase-encrypted file. This comes in in handy if/when your convenient passphrase-encrypted file. This comes in in handy if/when your
machine ever does go belly up. machine ever does go belly up.
Optionally, you can set up an email address where the log file will be sent.
Useful when the script is used via cron.
More information about this script avaiable at: More information about this script avaiable at:
http://damontimm.com/code/dt-s3-backup http://damontimm.com/code/dt-s3-backup
@ -37,6 +40,7 @@ REQUIREMENTS
* gpg * gpg
* Amazon S3 * Amazon S3
* s3cmd (optional) * s3cmd (optional)
* mailx (optional)
COMMON USAGE EXAMPLES COMMON USAGE EXAMPLES
===================== =====================
@ -81,6 +85,6 @@ NEXT VERSION WISH LIST
* --restore-dir option * --restore-dir option
* restore files from a specific time period * restore files from a specific time period
* support multiple MTAs for the email alert feature
Thanks to Mario Santagiuliana for his help. Thanks to Mario Santagiuliana for his help.

View file

@ -100,6 +100,18 @@ LOG_FILE="duplicity-`date +%Y-%m-%d_%H-%M`.txt"
LOG_FILE_OWNER="foobar_user_name:foobar_user_name" LOG_FILE_OWNER="foobar_user_name:foobar_user_name"
VERBOSITY="-v3" VERBOSITY="-v3"
# EMAIL ALERT
# Provide an email address to receive the logfile by email. If no email
# address is provided, no alert will be sent.
# You can set a custom from email address and a custom subject (both optionally)
# If no value is provided for the subject, the following value will be
# used by default: "DT-S3 Alert ${LOG_FILE}"
# MTA used: mailx
#EMAIL="admin@example.com"
EMAIL_TO=
EMAIL_FROM=
EMAIL_SUBJECT=
# TROUBLESHOOTING: If you are having any problems running this script it is # TROUBLESHOOTING: If you are having any problems running this script it is
# helpful to see the command output that is being generated to determine if the # helpful to see the command output that is being generated to determine if the
# script is causing a problem or if it is an issue with duplicity (or your # script is causing a problem or if it is an issue with duplicity (or your
@ -114,6 +126,7 @@ VERBOSITY="-v3"
LOGFILE="${LOGDIR}${LOG_FILE}" LOGFILE="${LOGDIR}${LOG_FILE}"
DUPLICITY="$(which duplicity)" DUPLICITY="$(which duplicity)"
S3CMD="$(which s3cmd)" S3CMD="$(which s3cmd)"
MAIL="$(which mailx)"
NO_S3CMD="WARNING: s3cmd is not installed, remote file \ NO_S3CMD="WARNING: s3cmd is not installed, remote file \
size information unavailable." size information unavailable."
@ -419,6 +432,17 @@ fi
echo -e "-------- END DT-S3-BACKUP SCRIPT --------\n" >> ${LOGFILE} echo -e "-------- END DT-S3-BACKUP SCRIPT --------\n" >> ${LOGFILE}
if [ $EMAIL_TO ]; then
if [ ! -x "$MAIL" ]; then
echo -e "Email coulnd't be sent. mailx not available." >> ${LOGFILE}
else
EMAIL_FROM=${EMAIL_FROM:+"-r ${EMAIL_FROM}"}
EMAIL_SUBJECT=${EMAIL_SUBJECT:="DT-S3 Alert ${LOG_FILE}"}
${MAIL} -s """${EMAIL_SUBJECT}""" $EMAIL_FROM ${EMAIL_TO} < ${LOGFILE}
echo -e "Email alert sent to ${EMAIL_TO} using ${MAIL}" >> ${LOGFILE}
fi
fi
if [ ${ECHO} ]; then if [ ${ECHO} ]; then
echo "TEST RUN ONLY: Check the logfile for command output." echo "TEST RUN ONLY: Check the logfile for command output."
fi fi