BackupPC-users

Re: [BackupPC-users] DumpPreUserCmd to send an email before and after backup

2009-01-29 05:51:43
Subject: Re: [BackupPC-users] DumpPreUserCmd to send an email before and after backup
From: Les Stott <les AT cyberpro.com DOT au>
To: backuppc-users AT lists.sourceforge DOT net
Date: Thu, 29 Jan 2009 21:33:58 +1100
Madcha wrote:
> Thanks,
>
> But how write this command, for send an email to $host? or $user?
>
>   
Here is one way to do it, maybe not the most elegant but it works. Use 
it as a guide and improve on it. I set this up ages ago for a client, 
never tweaked it since then.

These will send a note before to say its starting, and then send a note 
after if it completes, whether successful or not. It will also log to 
the hosts backuppc log file. If there is an error it will log that also.

You need to create 4 files. the sample scripts below assume you put them 
in /usr/local/bin

startbkpemail.txt      -> body text for email before
startbkpemail.sh       -> script to send the email before
endbkpemail.txt       -> body text for email after
endbkpemail.sh         -> script to send email after

Modify the variables at the top of the scripts to suit your setup.

Call them in BackupPC like so....
$Conf{DumpPreUserCmd}    = '/usr/local/bin/startbkpemail.sh $user 
$xferOK $host $type $cmdType';
$Conf{DumpPostUserCmd}    = '/usr/local/bin/endbkpemail.sh $user $xferOK 
$host $type $cmdType';

they should contain something like:

startbkpemail.txt
---------------------------------------------------------
THIS IS AN AUTOMATED SYSTEM MESSAGE!!
PLEASE DO NOT REPLY!!

Your Computer is being backed up by the
Automated System Backup Server.

During this time you may experience some slowness on
the network. This is usually only for a short period.

You will receive a confirmation E-mail when the
Backup Completes.
---------------------------------------------------------

startbkpemail.sh
---------------------------------------------------------
#!/bin/sh
#
#$Conf{DumpPreUserCmd}    = '/usr/local/bin/startbkpemail.sh $user 
$xferOK $host $type $cmdType';
#$Conf{DumpPostUserCmd}    = '/usr/local/bin/endbkpemail.sh $user 
$xferOK $host $type $cmdType';

varDate=`date '+%F %T'`
DOMAIN=yourdomain.com.au
BACKUPPCPATH=/path/to/data/directory
BACKUPPCLOG=$BACKUPPCPATH/log/LOG
NOTIFY=${1}@${DOMAIN}

/bin/mail -s"A Backup of $3 has started..." ${NOTIFY} < 
/usr/local/bin/startbkpemail.txt
/bin/echo "$varDate Backup Started E-mail sent to:(' $1' )" >>$BACKUPPCLOG
---------------------------------------------------------

endbkpemail.txt
---------------------------------------------------------
THIS IS AN AUTOMATED SYSTEM MESSAGE!!
PLEASE DO NOT REPLY!!

Your Computer has been backed up by the
Automated System Backup Server.
---------------------------------------------------------

endbkpemail.sh
---------------------------------------------------------
#!/bin/sh
#
#$Conf{DumpPreUserCmd}    = '/usr/local/bin/startbkpemail.sh $user 
$xferOK $host $type $cmdType';
#$Conf{DumpPostUserCmd}    = '/usr/local/bin/endbkpemail.sh $user 
$xferOK $host $type $cmdType';

varDate=`date '+%F %T'`
DOMAIN=yourdomain.com.au
BACKUPPCPATH=/path/to/data/directory
BACKUPPCLOG=$BACKUPPCPATH/log/LOG
NOTIFY=${1}@${DOMAIN}

### If $2 is a 1, backup completed.

if [ $2 = 1 ]
then
   /bin/mail -s"Backup of $3 has Completed Successfully." ${NOTIFY} < 
/usr/local/bin/endbkpemail.txt
   /bin/echo "$varDate Backup Completed E-mail sent to:(' $1' )" 
 >>$BACKUPPCLOG
else
   /bin/mail -s"Backup of $3 has Failed. Contact your System Admin." 
${NOTIFY} < /usr/local/bin/endbkpemail.txt
   /bin/echo $varDate 'Exit code:(' $2 ') Asset Tag:(' $3')  E-Mail:(' 
$1' )' >>$BACKUPPCLOG
fi
---------------------------------------------------------

That should give you a good starting point.

Regards,

Les

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
BackupPC-users mailing list
BackupPC-users AT lists.sourceforge DOT net
List:    https://lists.sourceforge.net/lists/listinfo/backuppc-users
Wiki:    http://backuppc.wiki.sourceforge.net
Project: http://backuppc.sourceforge.net/

<Prev in Thread] Current Thread [Next in Thread>