This is currently broken, I'll fix it soon
This is a set of scripts to notify you via email if your Borgmatic-run Borg backups failed or not. It will also send the log so you can see the size of your backup and other details.
This could probably all be in one bash script but I was writing it quickly cause I am super not cool with no notifications for my backups.
Written entirely in bash
msmtp package
A working borgmatic job
An SMTP server (I use gmail)
https://hostpresto.com/community/tutorials/how-to-send-email-from-the-command-line-with-msmtp-and-mutt/
https://guides.codechewing.com/bash/conditionally-assign-value-to-variable-bash
https://github.com/witten/borgmatic
https://www.borgbackup.org/
https://wiki.debian.org/msmtp
First we assume you have some sort of cron entry for borgmatic and also are generating a log file, this would look similar to the below:
0 3 * * * root PATH=$PATH:/usr/local/bin /root/.local/bin/borgmatic -v 2 > /var/log/borgmatic.log 2>&1
This cron entry runs borgmatic at 3 AM nightly and copies the output to a log file at /var/log/borgmatic.log (I have it in /etc/cron.d/borgmatic)
If your log is going to be elsewhere edit the Borgmatic Mailer scripts to reflect the location.
-
Install msmtp (For Debian: apt-get install msmtp)
-
Configure your .msmtprc file in /home/username or /root/ (This is your msmtp configuration file), I've included an example for Gmail.
-
Test ability to send an email with: echo "This is a test message" | msmtp -a default [email protected]
-
Copy the Borgmatic Mailer scripts to a directory anywhere you'd like and note down the path
-
Make the scripts executable by cd-ing into the directory you put the scripts and running: chmod +x *
-
Configure the variables in mailmaker.sh and borg_log_mailer.sh
-
Edit your borgmatic config.yaml to execute the Borgmatic Mailer main script (These options are under the hooks section, remember to change the paths):
after_backup:
- bash /Path/To/borg_log_mailer.sh
on_error:
- bash /Path/To/borg_log_mailer.sh -
Test run your backup job with: borgmatic -v 2 > /var/log/borgmatic.log 2>&1