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.

  1. Install ssmtp
    Code:
     sudo apt-get install ssmtp
  2. Configure for sending through gmail
    Code:
     sudo gedit /etc/ssmtp/ssmtp.conf
    Modify the following in ssmtp.conf
    Code:
    root=youraddress@gmail.com
    mailhub=smtp.gmail.com:587
    AuthUser=gmailusername
    AuthPass=gmailpassword
    UseSTARTTLS=YES
  3. Test out ssmtp by sending email to your gmail
    Code:
    ssmtp youraddress@gmail.com
    Then type the following:
    Code:
    To:youraddress@gmail.com
    From:youraddress@gmail.com
    Subject:Testing ssmtp
    
    This is a test
    Press ctrl+D when you finish.
    *Note there are 2 newlines after the Subject line.

  4. Setup backintime
    Code:
     sudo apt-get install backintime
    The gui is very self explanitory. Setup your backups and their frequency for whatever suits your needs.

  5. 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:
    Code:
     gedit ~/.config/backintime/user.callback
    Add the following to the file:
    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.

  6. Save the file and set the appropriate permissions
    Code:
     chmod 755 ~/.config/backintime/user.callback
  7. Test out script manually
    Code:
     ./.config/backintime/user.callback 4 3
    If everything worked well, you should have recieved an email with one of the error conditions listed.

    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.