Monitoring Backups using Domoticz

Backups are important

I am using these great scripts to backup my server and all the services. It uses Borg to do the actual heavy lifting and I am very happy with the setup.
When the backup is done, you get an E-Mail. Nice enough but because it runs every night, I have an E-Mail every morning in my inbox. I do not like this, I just want to know when something went wrong so that I can act upon it. If everything is working fine just leave me alone, that is my strategy.

Enter Domoticz and device monitoring

Backups of the server can also be seen as a thing or device that can be monitored by Domoticz, we just need a couple of changes in the scripts.

  1. Create a text sensor in Domoticz and write down the Idx of it.
  2. At the end of the script mentioned above just make these changes, comment out E-Mail sending and add the line with the date and curl. Change Domoticz IP and the Idx value to your own.
# Send mail to admin
#
# Important: An MTA has to be installed for sending mails.
# TODO: Add your own e-mail address here.
#mail -s "Server backup finished" root@localhost < "${logFile}"
endTimeForUpdate=$(date +"%Y%m%d_%H%M%S")
curl -s 'http://your_domoticz_ip:8080/json.htm?type=command&param=udevice&idx=your_idx&nvalue=0&svalue='+$endTimeForUpdate

If everything went fine you can run the backup script and you will get something like this when it is finished.

textsensor.jpg

So now when the backup runs, the value of the sensor will get updated with the current time it finished. All you have to now is to monitor this new device using the script given here. Then you will get an E-Mail only if this device doesn't get updated regularly e.g. something went wrong with your backup!

Happy Hacking!!

License: CC BY-SA 4.0 Discuss on Mastodon