diff --git a/duplicity-backup.conf.example b/duplicity-backup.conf.example index bad1092..763a818 100644 --- a/duplicity-backup.conf.example +++ b/duplicity-backup.conf.example @@ -401,6 +401,24 @@ MAIL="mailx" # default command for Linux mail #MAIL="/path/to/custom/mail_script.py" +# ------------------------------------------------------------------------------ +# NOTIFICATIONS +# ------------------------------------------------------------------------------ +# +# Third-pary notification services. If no NOTIFICATION_SERVICE provided, no +# notifications will be sent. + +# NOTIFICATION_SERVICE="slack" +NOTIFICATION_SERVICE= +NOTIFICATION_FAILURE_ONLY="yes" # send notifications only if there was an error while creating backup + +# Provider: Slack +SLACK_HOOK_URL="https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX" +SLACK_CHANNEL="#general" +SLACK_USERNAME="duplicity-backup" +SLACK_EMOJI="package" + + # ------------------------------------------------------------------------------ # TROUBLESHOOTING # ------------------------------------------------------------------------------ diff --git a/duplicity-backup.sh b/duplicity-backup.sh index ba8df93..94e16db 100755 --- a/duplicity-backup.sh +++ b/duplicity-backup.sh @@ -372,6 +372,15 @@ email_logfile() fi } +send_notification() +{ + if [ ! -z "$NOTIFICATION_SERVICE" ]; then + if [ "$NOTIFICATION_SERVICE" = "slack" ]; then + curl -X POST -H 'Content-type: application/json' --data "{\"text\": \"$NOTIFICATION_CONTENT\", \"channel\": \"$SLACK_CHANNEL\", \"username\": \"$SLACK_USERNAME\", \"icon_emoji\": \":$SLACK_EMOJI:\"}" ${SLACK_HOOK_URL} + fi + fi +} + get_lock() { echo "Attempting to acquire lock ${LOCKFILE}" >> ${LOGFILE} @@ -861,6 +870,20 @@ else email_logfile fi +if [ "$NOTIFICATION_FAILURE_ONLY" = "yes" ]; then + if [ ${BACKUP_ERROR} ]; then + NOTIFICATION_CONTENT="BACKUP ERROR: ${HOSTNAME} - \`$LOGFILE\`" + send_notification + fi +else + if [ ${BACKUP_ERROR} ]; then + NOTIFICATION_CONTENT="BACKUP ERROR: ${HOSTNAME} - \`$LOGFILE\`" + else + NOTIFICATION_CONTENT="BACKUP OK: ${HOSTNAME} - \`$LOGFILE\`" + fi + send_notification +fi + # remove old logfiles # stops them from piling up infinitely [[ -n "${REMOVE_LOGS_OLDER_THAN}" ]] && find ${LOGDIR} -type f -mtime +"${REMOVE_LOGS_OLDER_THAN}" -delete