I recently setup a raid1 array to handle all my household backups, and decided on using backintime to handle this task. Given how important these backups are, I wanted to keep a close watch on them to make sure they were happening without issue.
After a bit of reading I decided to use backintimes user callback functionality to email me when backups were created, and if any errors had occurred.
- Install ssmtp
Code:sudo apt-get install ssmtp- Configure for sending through gmail
Modify the following in ssmtp.confCode:sudo gedit /etc/ssmtp/ssmtp.conf
Code:root=youraddress@gmail.com mailhub=smtp.gmail.com:587 AuthUser=gmailusername AuthPass=gmailpassword UseSTARTTLS=YES- Test out ssmtp by sending email to your gmail
Then type the following:Code:ssmtp youraddress@gmail.com
Press ctrl+D when you finish.Code:To:youraddress@gmail.com From:youraddress@gmail.com Subject:Testing ssmtp This is a test
*Note there are 2 newlines after the Subject line.
- Setup backintime
The gui is very self explanitory. Setup your backups and their frequency for whatever suits your needs.Code:sudo apt-get install backintime
- Setup user.callback
Backintime is setup to call a user defined callback at certain times during the backup process. Backintime will look for a file called "user.callback" at ~/.config/backintime during its execution, and call it with a specific set of arguments if it exists.
Lets create that file now:
Add the following to the file:Code:gedit ~/.config/backintime/user.callback
Code:#!/bin/sh address ="<youruser>@gmail.com" msg="To:<youruser>@gmail.com\n"; msg="${msg}Subject:Backup\n\n"; mailmsg=0; case "$1" in 1);; ##Backup starting 2);; ##Backup finishing 3)msg="${msg} Backup completed for ${2} ${3}" mailmsg=1 ;; 4)msg="${msg} An error occurred:" mailmsg=1 case "$2" in 1)msg="${msg} Application not configured";; 2)msg="${msg} Process already running";; 3)msg="${msg} Can't find directory";; 4)msg="${msg} A snapshot for 'now' already exists";; esac ;; esac if [ $mailmsg = 1 ] then /bin/echo -e $msg | /usr/sbin/ssmtp $address fi
Replace <youruser> with your gmail user name.
*Note: I only want to be notified when a snapshot is taken, or an error occurs. I'm not interested in when the backup starts or finishes. This is why the first two items in the case statement are left blank.
- Save the file and set the appropriate permissions
Code:chmod 755 ~/.config/backintime/user.callback- Test out script manually
If everything worked well, you should have recieved an email with one of the error conditions listed.Code:./.config/backintime/user.callback 4 3
You should now receive an email whenever a backup occurs, or an error is encountered. If you setup backintime to do frequent backups i.e. more than once a day, and the emails start to get annoying, just delete the user.callback file. This will not effect your backups.
Bookmarks