Dear  Martin,
> I am searching after some script or possibility to send email at some 
> addresses after every backup, and in this email i need :
>
> 1. What has been backed up.
> 2. When
> 3. If backup was successfull or not
> 4. If not - why
>   
almost all yours requests ;-)

in config.pl (or in PC-config file) :

- send email after a backup :

$Conf{DumpPostUserCmd} = '/usr/local/BackupPC/bin/BackupNotify $user 
$xferOK $host $type $client $hostIP ';

- or only if the backup is ok

$Conf{DumpPostUserCmd} = '/usr/local/BackupPC/bin/BackupNotify_succes 
$user $xferOK $host $type $client $hostIP ';
 
- or only if the backup is not ok

$Conf{DumpPostUserCmd} = '/usr/local/BackupPC/bin/BackupNotify_echec 
$user $xferOK $host $type $client $hostIP ';


above 2 scripts (not yet finished but working...) :
 
- one sends email with the results (BackupNotify)
- second (analyse_backups) extracts errors from XferLOG  (I'm taken some 
part of code in the package BackupPC (BackupPC_dump))

regards

jmb

----------------------------------------------------------------------------
[EMAIL PROTECTED] /usr/local/BackupPC/bin > cat BackupNotify

#!/usr/local/bin/perl
#################
#
# BackupNotify              : send mail after a good or a bad backup
# BackupNotify_succes : send email only after a good backup
# BackupNotify_echec  : send email only after a bad backup
#
# jmb 20/06/2006
# jmb 10/10/2007
#
# parameters : $user $xferOK $host $type $client $hostIP
#
use Socket;

$mailprog = '/usr/sbin/sendmail';

$user = $ARGV[0];
$xferOK = $ARGV[1];
$host = $ARGV[2];
$type = $ARGV[3];
$client = $ARGV[4];
$hostIP = $ARGV[5];

$recipient = $user;

$script = $0;
$succes = 1;
$echec = 1;

if ($script  =~ 'succes'){ $echec = 0; }
if ($script =~ 'echec'){ $succes = 0; }

#
# extract only errors from XferLOG
#
my $status=`/usr/local/BackupPC/bin/analyse_backups $client`;
($xferErr,$badFile,$TopDir,$xferlognum) = split(/-/,$status);
chop($xferlognum);
$xferErr = int($xferErr);
$xferlognum = int($xferlognum);
my $list_error=`/usr/local/BackupPC/bin/BackupPC_zcat 
$TopDir/pc/$client/XferLOG.$xferlognum.z | grep DENIED | grep -v 'System 
Volume Information' | grep -v RECYCLER |grep -v Watson`;

#
#
$msg = "Rapport de sauvegarde de BackupPC pour le PC \"$client 
($hostIP)\" : \n\n";
if ( $xferOK) {
        if ( length($list_error) > 0) {
                $msg .= "Le backup ($type) s'est PRESQUE bien 
deroule...\n\n";
                $msg .= "Des erreurs de transfert se sont produites...\n\n";
                $msg .= "Voici la liste des erreurs :\n";
                $msg .= "$list_error\n";
                $msg .= "Ceci peut se produire dans les situations 
suivantes :\n";
                $msg .= "   - lorsqu'un fichier est en cours 
d'utilisation\n";
                $msg .= "   - lorsqu'un dossier/fichier a des droits 
d'acces trop restrictifs\n\n";
                $msg .= "De toute facon, les gestionnaires sont 
prevenus...\n";
                $ccrecipient = "[EMAIL PROTECTED]";
                $subject = "Backup de $client : ok MAIS... !";
                if ( $succes ){ &sendmail($msg); };
        } else {
                $msg .= "Le backup ($type) s'est bien deroule\n";
                $ccrecipient = "";
                $subject = "Backup de $client : OK !";
                if ( $succes ){ &sendmail($msg); };
        }
} else {
        $msg .= "Le backup ($type) a pose probleme ! \n";
        $subject = "Probleme de backup de $client...";
        if ( $echec ) { &sendmail($msg); };
}

sub sendmail {
   my($msg) = @_;
   open(MAIL, "|$mailprog -t") && do {
        print MAIL "To: $recipient\n";
        print MAIL "From: [EMAIL PROTECTED]";
        print MAIL "Cc: $ccrecipient\n";
#        print MAIL "Bcc:\n";
        print MAIL "Subject: $subject \n\n";
        print MAIL "$msg\n";
        print MAIL "\nVisiter regulierement le site 
<http://www.uclouvain.be/backuppc>\n";
        print MAIL "\nContact support : mailto:[EMAIL PROTECTED]";
        close (MAIL);
   };
}
----------------------------------------------------------------------------

[EMAIL PROTECTED] /usr/local/BackupPC/bin > cat analyse_backups 
#!/usr/local/bin/perl
#============================================================= -*-perl-*-
#
# BackupPC_

use strict;
no  utf8;
use lib "/usr/local/BackupPC3/lib";
use BackupPC::Lib;
use BackupPC::FileZIO;
use BackupPC::Storage;
use BackupPC::Xfer::Smb;
use BackupPC::Xfer::Tar;
use BackupPC::Xfer::Rsync;
use BackupPC::Xfer::BackupPCd;
use Encode;
use Socket;
use File::Path;
use File::Find;
use Getopt::Std;

###########################################################################
# Initialize
###########################################################################

die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
my $TopDir = $bpc->TopDir();
my $BinDir = $bpc->BinDir();
my %Conf   = $bpc->Conf();
my $NeedPostCmd;
my $Hosts;
my $SigName;
my $Abort;

$bpc->ChildInit();

my %opts;
if ( !getopts("defiv", \%opts) || @ARGV != 1 ) {
    print("usage: $0 [-d] [-e] [-f] [-i] [-v] <client>\n");
    exit(1);
}
if ( $ARGV[0] !~ /^([\w\.\s-]+)$/ ) {
    print("$0: bad client name '$ARGV[0]'\n");
    exit(1);
}

my $client = $1;   # BackupPC's client name (might not be real host name)
my $hostIP;        # this is the IP address
my $host;          # this is the real host name
my($clientURI, $user);
my $Dir     = "$TopDir/pc/$client";
my @xferPid = ();
my $tarPid  = -1;
my($needLink, @Backups, $type);
my($incrBaseTime, $incrBaseBkupNum, $incrBaseLevel, $incrLevel);
my $lastFullTime = 0;
my $lastIncrTime = 0;
my $partialIdx = -1;
my $partialNum;
my $lastBkupNum;
my $lastPartial = 0;
my(@lastIdxByLevel, $incrCntSinceFull);

#
# Read Backup information, and find times of the most recent full and
# incremental backups.  Also figure out which backup we will use
# as a starting point for an incremental.
#
#    my $flds = {
#        BackupFields => [qw(
#                    num type startTime endTime
#                    nFiles size nFilesExist sizeExist nFilesNew sizeNew
#                    xferErrs xferBadFile xferBadShare tarErrs
#                    compress sizeExistComp sizeNewComp
#                    noFill fillFromNum mangle xferMethod level
#                    charset
#                )],
#
@Backups = $bpc->BackupInfoRead($client);
## @Backups = sort( { $a->{startTime} <=> $b->{startTime} }, @Backups);
my $maxbackups;
for ( my $i = 0 ; $i < @Backups ; $i++ ) {
    $needLink = 1 if ( $Backups[$i]{nFilesNew} eq ""
                        || -f "$Dir/NewFileList.$Backups[$i]{num}" );
    if ( $Backups[$i]{type} eq "full" ) {
        $incrCntSinceFull = 0;
        $lastBkupNum = $Backups[$i]{num};
        $lastIdxByLevel[0] = $i;
        if ( $lastFullTime < $Backups[$i]{startTime} ) {
            $lastFullTime = $Backups[$i]{startTime};
        }
    } elsif ( $Backups[$i]{type} eq "incr" ) {
        $incrCntSinceFull++;
        $lastBkupNum = $Backups[$i]{num};
        $lastIdxByLevel[$Backups[$i]{level}] = $i;
        $lastIncrTime = $Backups[$i]{startTime}
                if ( $lastIncrTime < $Backups[$i]{startTime} );
    } elsif ( $Backups[$i]{type} eq "partial" ) {
        $partialIdx  = $i;
        $lastPartial = $Backups[$i]{startTime};
        $partialNum  = $Backups[$i]{num};
    }
    $maxbackups = $i;
}
print 
"$Backups[$maxbackups]{xferErrs}-$Backups[$maxbackups]{xferBadFile}-$TopDir-$lastBkupNum\n";

exit(0);


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
BackupPC-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/backuppc-users
http://backuppc.sourceforge.net/

Reply via email to