Get notification after every successful backup from BackupPC

Edit the configuration in BackupPC is as below :

Edit config –> Backup Settings –> User commands -> DumpPostUserCmd as
/theg/ $xferOK $host $type $client $hostIP $share $XferMethod $sshPath $cmdType
where /theg/ is the custom script.

Below are the contents of the script :


# script to send simple email
# Email To ?
# Email text/message

# Grab the status variables

# Check if backup succeeded or not.
if [[ $xferOK == 1 ]]; then

# email subject
SUBJECT=”[BackupPC] $STATUS for host: $client”

# Email text/message
echo “Filesystem backup for $host $STATUS” > $EMAILMESSAGE
echo “Type: $type” >>$EMAILMESSAGE
echo “Client: $client” >>$EMAILMESSAGE
echo “Host: $host” >>$EMAILMESSAGE
echo “Host IP: $hostIP” >>$EMAILMESSAGE
echo “Share: $share” >>$EMAILMESSAGE
echo “XferMethod: $XferMethod” >>$EMAILMESSAGE
echo “sshPath: $sshPath” >>$EMAILMESSAGE
echo “cmdType: $cmdType” >>$EMAILMESSAGE

# send an email using /bin/mail
/bin/mail -s “$SUBJECT” “$EMAIL” < $EMAILMESSAGE

Enjoy 🙂

17 thoughts on “Get notification after every successful backup from BackupPC

  1. I needed to change the script a little bit for postfix.

    instead of /bin/mail -s “$SUBJECT” “$EMAIL” < $EMAILMESSAGE

    i did /usr/sbin/sendmail -v "$EMAIL" "$SUBJECT" < $EMAILMESSAGE

    i'm currently running ubuntu 12.04.04 and it didn't came with /bin/mail.
    This also works fine.

  2. I followed the link and give me this error ‘Output from DumpPostUserCmd: Exec of /etc/backuppc/ failed’ could you help me!

    • You can keep the script wherever you want provided you have the permission. In my case, I created one directory /theg and kept it there .

  3. Hopefully it’s not too late to comment. I’m getting the following when I run the script:

    ./ line 26: ”FAILED”: command not found
    ./ line 29: ”/tmp/emailmessage.txt”: No such file or directory
    ./ line 30: ”/tmp/emailmessage.txt”: No such file or directory
    ./ line 31: ”/tmp/emailmessage.txt”: No such file or directory
    ./ line 32: ”/tmp/emailmessage.txt”: No such file or directory

    There’s also more of the exact same errors as you see from line number 29 to 41.

    I’ve given it executable rights also.

    Any suggestions, please?

      • Thanks for the quick response. I tried making the file you suggested and I’m still getting the same errors, that the /tmp/emailmessage.txt doesn’t exist when I run the script. And I’m still getting the error “FAILED”: command not found again.

  4. Just a few notes on some things I had to change to make this work:
    Change /bin/mail to /usr/bin/mail
    Change “ to ” (used notepad find and replace for this)
    I saved my script here for easy referece: /etc/backuppc/

    Works beautifully! Thank you so much for this!

      • Not sure if you’re still using Backuppc yourself but I was wondering if there would be a way of including the LOG file contents in the body of the email? That would just be the icing on the cake!

        Ps. If you’re not using Backuppc anymore – may I ask what you’re using now and why no longer Backuppc?

  5. Hi i was wondering if someone could shed some light, as for the script some odd reason it wont work keeps telling me
    �/tmp/emailmessage.txt�: No such file or directory
    i think it has to do with the ” i was reading the comments and i tried no luck a
    Thank you

    • manually check if that file has been created by typing

      stat /tmp/emailmessage.txt

      if it finds it then type the quotes again from the variable at the top. There is some issue copying and pasting from this website as it changes the quotes into something else when pasting it in terminal.

      If it does not exist then it means the script has not created the email message file.


  6. Hello, for some reason i get email through without SUBJECT. I changed /bin/mail to /usr/sbin/sendmail -v “$EMAIL” “$SUBJECT” < $EMAILMESSAGE

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s