Les Stott wrote:
Nick Triantafillou wrote:
Alexander Moisseev wrote:
Slightly modified perl script with warnings on errors and outdated
backups (Originally written by Holger Parplies) for email reports.
This works brilliantly, thanks a lot for sharing.
Nick.
Maybe i missed a post......
Thanks to Holger, his script works great!! I have wanted something like
this for a long time.
Can the modified version, as stated above be posted to the list also?
Holger, thanks for sending me the updated script. Kudos to you and
Alexander for writing it.
I wish I knew perl.......it would be so handy ;)
I was wondering if you could help out with two additional changes........
I want to run this script as a DumpPostUserCmd such that i can email a
small report with some detail about what the backup did.
The output of the script is great, but it runs for all hosts, I'd like
it to only run for the host that is being backed up. How can i make it
use say $1 as an argument for the host (i.e. using $client from the
DumpPostUserCmd)??
Second.....
if it shows xfer errors how easy would it be to append the xferlog to
the email?
Jean-Michel Beuken wrote the attached scripts (Re: [BackupPC-users] Email summary after backup 19/10/2007) which do email reporting
and attach the xferlog if errors are detected.
If your script and Jean-Michel's were combined i think we'd have a great
little summary report to accompany an email on success or failure after
the backup for a host.
Thanks in advance for your assistance,
Regards,
Les
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
BackupPC-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/backuppc-users
http://backuppc.sourceforge.net/
-------------------------------------------------------------------------
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
BackupPC-users@lists.sourceforge.net
List: https://lists.sourceforge.net/lists/listinfo/backuppc-users
Wiki: http://backuppc.wiki.sourceforge.net
Project: http://backuppc.sourceforge.net/