8c0f58d8f0cb84aaf51db0f7e4eb709e2975d3a7

Author
zertrin <zertrin@gmail.com>
Committer
zertrin <zertrin@gmail.com>
Date

Message

Merge branch 'sparanoid-patch-1' into dev

Diff

 1diff --git a/duplicity-backup.conf.example b/duplicity-backup.conf.example
 2index bad10926266873875b46a7f2dde8a1e54d59980e..763a8181131529c2c6e79dbfdfd79e420bdef3e3 100644
 3--- a/duplicity-backup.conf.example
 4+++ b/duplicity-backup.conf.example
 5@@ -401,6 +401,24 @@ MAIL="mailx"     # default command for Linux mail
 6 #MAIL="/path/to/custom/mail_script.py"
 7 
 8 
 9+# ------------------------------------------------------------------------------
10+# NOTIFICATIONS
11+# ------------------------------------------------------------------------------
12+#
13+# Third-pary notification services. If no NOTIFICATION_SERVICE provided, no
14+# notifications will be sent.
15+
16+# NOTIFICATION_SERVICE="slack"
17+NOTIFICATION_SERVICE=
18+NOTIFICATION_FAILURE_ONLY="yes" # send notifications only if there was an error while creating backup
19+
20+# Provider: Slack
21+SLACK_HOOK_URL="https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
22+SLACK_CHANNEL="#general"
23+SLACK_USERNAME="duplicity-backup"
24+SLACK_EMOJI="package"
25+
26+
27 # ------------------------------------------------------------------------------
28 # TROUBLESHOOTING
29 # ------------------------------------------------------------------------------
30diff --git a/duplicity-backup.sh b/duplicity-backup.sh
31index ba8df930bdadd82ee6e3da7995e83a63c8bbf571..94e16dbd3184d78dc9af903a1b8f4b3ae7fa01ea 100755
32--- a/duplicity-backup.sh
33+++ b/duplicity-backup.sh
34@@ -372,6 +372,15 @@ email_logfile()
35   fi
36 }
37 
38+send_notification()
39+{
40+  if [ ! -z "$NOTIFICATION_SERVICE" ]; then
41+    if [ "$NOTIFICATION_SERVICE" = "slack" ]; then
42+      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}
43+    fi
44+  fi
45+}
46+
47 get_lock()
48 {
49   echo "Attempting to acquire lock ${LOCKFILE}" >> ${LOGFILE}
50@@ -861,6 +870,20 @@ else
51   email_logfile
52 fi
53 
54+if [ "$NOTIFICATION_FAILURE_ONLY" = "yes" ]; then
55+  if [ ${BACKUP_ERROR} ]; then
56+    NOTIFICATION_CONTENT="BACKUP ERROR: ${HOSTNAME} - \`$LOGFILE\`"
57+    send_notification
58+  fi
59+else
60+  if [ ${BACKUP_ERROR} ]; then
61+    NOTIFICATION_CONTENT="BACKUP ERROR: ${HOSTNAME} - \`$LOGFILE\`"
62+  else
63+    NOTIFICATION_CONTENT="BACKUP OK: ${HOSTNAME} - \`$LOGFILE\`"
64+  fi
65+  send_notification
66+fi
67+
68 # remove old logfiles
69 # stops them from piling up infinitely
70 [[ -n "${REMOVE_LOGS_OLDER_THAN}" ]] && find ${LOGDIR} -type f -mtime +"${REMOVE_LOGS_OLDER_THAN}" -delete