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/email.sh $xferOK $host $type $client $hostIP $share $XferMethod $sshPath $cmdType
where /theg/email.sh is the custom script.

Below are the contents of the email.sh script :

 

#!/bin/bash
# script to send simple email
# Email To ?
EMAIL=”your_email_address”
# Email text/message
EMAILMESSAGE=”/tmp/

emailmessage.txt”

# Grab the status variables
xferOK=$1
host=$2
type=$3
client=$4
hostIP=$5
share=$6
XferMethod=$7
sshPath=$8
cmdType=$9

# Check if backup succeeded or not.
if [[ $xferOK == 1 ]]; then
        STATUS=”SUCCESS”
else
        STATUS=”FAILED”
fi

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

# Email text/message
echo “Filesystem backup for $host $STATUS” > $EMAILMESSAGE
echo “” >>$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 🙂
Advertisements

6 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/email.sh 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 .
      /theg/email.sh

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s