I used this script to notify me before and after backups:
#!/bin/bash
# Examples
# Command to run before backup
# sh /root/notify-slack.sh Begin Superman $BACKUP_DEST
# Command to run after backup
# sh /root/notify-slack.sh End Superman $BACKUP_DEST $BACKUP_STATUS
# Command line parameters
verb=$1
server=$2
destination=$3
status=$4
message="$1 $2 backup to $3 $4"
echo $message
# Read the Slack Hook URL from the .env file
source /root/.env
# Post to Slack
curl -X POST -H 'Content-type: application/json' --data "{'text':'$message'}" $SLACK_HOOK
If you’re interested in using it, please check out the instructions on Github:
If you’re an open source Shell script developer, please see if you can help us improve the script. The following are current outstanding tasks:
-
Instead of outputting
1
or0
for backup success and fail, use a word such as SUCCESS or FAIL -
Make Slack do something special when it fails, e.g. present the output in the colour red, or play a sound
-
Keeping track of backup times is super NB. It would be great that when the verb is read as “begin” (case insensitive) that a timer is created, which is read again afterwards if “end” is encountered