From 2441b9094f3f6e4f2a3a4fe67781780e6f6890bd Mon Sep 17 00:00:00 2001 From: cbarratt Date: Wed, 25 Mar 2009 04:50:58 +0000 Subject: [PATCH 1/1] * Moved call to NmbLookupFindHostCmd in BackupPC_dump to after the check of whether a backup needs to be done. This makes wakeonlan work correctly, rather than waking up the client every WakeupSchedule. Reported by David Lasker. * Improved settings for compression and compext in BackupPC_archiveStart based on compression type, as proposed by Paul Dugas. compext is now empty, .gz or .bz2 based on ArchiveComp. * Fixed netbios name comparison in bin/BackupPC_dump and bin/BackupPC_restore to just use the first 15 characters of the host name. Patch from Dan MacNeil. * Fixed nmblookup parsing in BackupPC::Lib::NetBiosInfoGet to ignore entries with the tag. Based on patch from Dan MacNeil. * Fixed BackupPC_dump so that the XferLOG file is saved when DumpPreUserCmd fails. Reported by John Rouillard. * Additional fr.pm fix from Vincent Fleuranceau. --- ChangeLog | 21 ++++++- bin/BackupPC | 4 +- bin/BackupPC_archiveStart | 10 ++-- bin/BackupPC_dump | 103 +++++++++++++++++++++------------- bin/BackupPC_restore | 4 +- lib/BackupPC/Lang/fr.pm | 2 +- lib/BackupPC/Lib.pm | 8 ++- lib/BackupPC/Xfer/Protocol.pm | 3 +- lib/BackupPC/Xfer/Rsync.pm | 5 +- 9 files changed, 106 insertions(+), 54 deletions(-) diff --git a/ChangeLog b/ChangeLog index c114378..f604831 100644 --- a/ChangeLog +++ b/ChangeLog @@ -81,6 +81,15 @@ * Added --config-override to configure.pl, allow config settings to be set on the command line. Proposed by Les Stott and Holger Parplies. +* Moved call to NmbLookupFindHostCmd in BackupPC_dump to after the + check of whether a backup needs to be done. This makes wakeonlan + work correctly, rather than waking up the client every WakeupSchedule. + Reported by David Lasker. + +* Improved settings for compression and compext in BackupPC_archiveStart + based on compression type, as proposed by Paul Dugas. compext is now + empty, .gz or .bz2 based on ArchiveComp. + * Changed bin/BackupPC_dump to not ping or lookup the host if $Conf{BackupsDisable} is set. Requested by John Rouillard. @@ -98,11 +107,21 @@ and also set the file extension to .gz when compression is on. Reported by Stephen Vaughan. +* Fixed netbios name comparison in bin/BackupPC_dump and + bin/BackupPC_restore to just use the first 15 characters + of the host name. Patch from Dan MacNeil. + +* Fixed nmblookup parsing in BackupPC::Lib::NetBiosInfoGet to ignore + entries with the tag. Based on patch from Dan MacNeil. + +* Fixed BackupPC_dump so that the XferLOG file is saved when + DumpPreUserCmd fails. Reported by John Rouillard. + * Updated BackupPC.pod for $Conf{BackupsDisable}, reported by Nils Breunese. * Minor updates to lib/BackupPC/Lang/fr.pm from Nicolas STRANSKY - applied by GFK. + applied by GFK, and also from Vincent Fleuranceau. * Minor updates to lib/BackupPC/Lang/de.pm from Klaus Weidenbach. diff --git a/bin/BackupPC b/bin/BackupPC index 2edf36d..79d89c7 100755 --- a/bin/BackupPC +++ b/bin/BackupPC @@ -47,7 +47,7 @@ # #======================================================================== # -# Version 3.2.0, released 31 Dec 2008. +# Version 3.2.0beta0, released 17 Jan 2009. # # See http://backuppc.sourceforge.net. # @@ -961,6 +961,8 @@ sub Main_Check_Job_Messages if ( $Status{$host}{dhcpCheckCnt} > 0 ); } elsif ( $mesg =~ /^xferPids (.*)/ ) { $Jobs{$host}{xferPid} = $1; + } elsif ( $mesg =~ /^completionPercent (.*)/ ) { + $Jobs{$host}{completionPercent} = $1; } elsif ( $mesg =~ /^started_restore/ ) { $Jobs{$host}{type} = "restore"; print(LOG $bpc->timeStamp, diff --git a/bin/BackupPC_archiveStart b/bin/BackupPC_archiveStart index 12553b5..ceee9a4 100755 --- a/bin/BackupPC_archiveStart +++ b/bin/BackupPC_archiveStart @@ -35,7 +35,7 @@ # #======================================================================== # -# Version 3.2.0, released 31 Dec 2008. +# Version 3.2.0beta0, released 17 Jan 2009. # # See http://backuppc.sourceforge.net. # @@ -94,9 +94,11 @@ for ( my $i = 0 ; ; $i++ ) { my %ArchiveReq = ( archiveloc => $bpc->{Conf}{ArchiveDest}, archtype => 0, - compression => $bpc->{Conf}{ArchiveComp} eq "none" ? $bpc->{Conf}{CatPath} - : $bpc->{Conf}{ArchiveComp}, - compext => $bpc->{Conf}{ArchiveComp} eq "none" ? '.raw' : '.gz', + compression => $bpc->{Conf}{ArchiveComp} eq 'none' ? $bpc->{Conf}{CatPath} + : ($bpc->{Conf}{ArchiveComp} eq 'gzip' + ? $bpc->{Conf}{GzipPath} : $bpc->{Conf}{Bzip2Path}), + compext => $bpc->{Conf}{ArchiveComp} eq 'none' ? '' + : ($bpc->{Conf}{ArchiveComp} eq 'gzip' ? '.gz' : '.bz2'), parfile => $bpc->{Conf}{ArchivePar}, splitsize => '0000000', host => $ArchiveHost, diff --git a/bin/BackupPC_dump b/bin/BackupPC_dump index 288ee85..89e4bfe 100755 --- a/bin/BackupPC_dump +++ b/bin/BackupPC_dump @@ -70,7 +70,7 @@ # #======================================================================== # -# Version 3.2.0, released 31 Dec 2008. +# Version 3.2.0beta0, released 17 Jan 2009. # # See http://backuppc.sourceforge.net. # @@ -158,6 +158,7 @@ if ( !defined($Hosts->{$client}) ) { my $Dir = "$TopDir/pc/$client"; my @xferPid = (); my $tarPid = -1; +my $completionPercent; # # Re-read config file, so we can include the PC-specific config @@ -234,33 +235,6 @@ if ($Conf{XferMethod} eq "archive" ) { exit(0); } -if ( !$opts{d} && !$Conf{BackupsDisable} ) { - # - # In the non-DHCP case, make sure the host can be looked up - # via NS, or otherwise find the IP address via NetBios. - # - if ( $Conf{ClientNameAlias} ne "" ) { - $host = $Conf{ClientNameAlias}; - } else { - $host = $client; - } - if ( !defined(gethostbyname($host)) ) { - # - # Ok, NS doesn't know about it. Maybe it is a NetBios name - # instead. - # - print(STDERR "Name server doesn't know about $host; trying NetBios\n") - if ( $opts{v} ); - if ( !defined($hostIP = $bpc->NetBiosHostIPFind($host)) ) { - print(LOG $bpc->timeStamp, "Can't find host $host via netbios\n"); - print("host not found\n"); - exit(1); - } - } else { - $hostIP = $host; - } -} - ########################################################################### # Figure out what to do and do it ########################################################################### @@ -490,6 +464,33 @@ if ( !$bpc->HardlinkTest($Dir, "$TopDir/cpool") ) { exit(1); } +if ( !$opts{d} ) { + # + # In the non-DHCP case, make sure the host can be looked up + # via NS, or otherwise find the IP address via NetBios. + # + if ( $Conf{ClientNameAlias} ne "" ) { + $host = $Conf{ClientNameAlias}; + } else { + $host = $client; + } + if ( !defined(gethostbyname($host)) ) { + # + # Ok, NS doesn't know about it. Maybe it is a NetBios name + # instead. + # + print(STDERR "Name server doesn't know about $host; trying NetBios\n") + if ( $opts{v} ); + if ( !defined($hostIP = $bpc->NetBiosHostIPFind($host)) ) { + print(LOG $bpc->timeStamp, "Can't find host $host via netbios\n"); + print("host not found\n"); + exit(1); + } + } else { + $hostIP = $host; + } +} + # # Check if $host is alive # @@ -594,8 +595,9 @@ UserCommandRun("DumpPreUserCmd"); if ( $? && $Conf{UserCmdCheckStatus} ) { print(LOG $bpc->timeStamp, "DumpPreUserCmd returned error status $?... exiting\n"); - print("dump failed: DumpPreUserCmd returned error status $?\n"); - exit(1); + $XferLOG->write(\"DumpPreUserCmd returned error status $?... exiting\n"); + $stat{hostError} = "DumpPreUserCmd returned error status $?"; + BackupFailCleanup(); } $NeedPostCmd = 1; @@ -621,19 +623,21 @@ for my $shareName ( @$ShareNames ) { if ( $? && $Conf{UserCmdCheckStatus} ) { print(LOG $bpc->timeStamp, "DumpPreShareCmd returned error status $?... exiting\n"); - print("dump failed: DumpPreShareCmd returned error status $?\n"); UserCommandRun("DumpPostUserCmd") if ( $NeedPostCmd ); - exit(1); + $XferLOG->write(\"DumpPreShareCmd returned error status $?... exiting\n"); + $stat{hostError} = "DumpPreShareCmd returned error status $?"; + BackupFailCleanup(); } $xfer = BackupPC::Xfer::create($Conf{XferMethod}, $bpc); if ( !defined($xfer) ) { my $errStr = BackupPC::Xfer::errStr(); print(LOG $bpc->timeStamp, "dump failed: $errStr\n"); - print("dump failed: $errStr\n"); UserCommandRun("DumpPostShareCmd", $shareName) if ( $NeedPostCmd ); UserCommandRun("DumpPostUserCmd") if ( $NeedPostCmd ); - exit(1); + $XferLOG->write(\"BackupPC::Xfer::create failed: $errStr\n"); + $stat{hostError} = $errStr; + BackupFailCleanup(); } my $useTar = $xfer->useTar; @@ -723,14 +727,14 @@ for my $shareName ( @$ShareNames ) { compress => $Conf{CompressLevel}, XferMethod => $Conf{XferMethod}, logLevel => $Conf{XferLogLevel}, - pidHandler => \&pidHandler, partialNum => $partialNum, + pidHandler => \&pidHandler, + completionPercent => \&completionPercent, }); if ( !defined($logMsg = $xfer->start()) ) { - print(LOG $bpc->timeStamp, "xfer start failed: ", $xfer->errStr, "\n"); - print("dump failed: ", $xfer->errStr, "\n"); - print("link $clientURI\n") if ( $needLink ); + my $errStr = "xfer start failed: " . $xfer->errStr . "\n"; + print(LOG $bpc->timeStamp, $errStr); # # kill off the tar process, first nicely then forcefully # @@ -746,7 +750,9 @@ for my $shareName ( @$ShareNames ) { } UserCommandRun("DumpPostShareCmd", $shareName) if ( $NeedPostCmd ); UserCommandRun("DumpPostUserCmd") if ( $NeedPostCmd ); - exit(1); + $XferLOG->write(\"xfer start failed: $errStr\n"); + $stat{hostError} = $errStr; + BackupFailCleanup(); } @xferPid = $xfer->xferPid; @@ -1564,7 +1570,7 @@ sub CorrectHostCheck || $Conf{NmbLookupCmd} eq "" ); my($netBiosHost, $netBiosUser) = $bpc->NetBiosInfoGet($hostIP); return "host $host has mismatching netbios name $netBiosHost" - if ( $netBiosHost ne $host ); + if ( lc($netBiosHost) ne lc(substr($host, 0, 15)) ); return; } @@ -1585,6 +1591,23 @@ sub pidHandler print("xferPids $str\n"); } +# +# The Xfer method might tell us from time to time about progress +# in the backup or restore +# +sub completionPercent +{ + my($percent) = @_; + + $percent = 100 if ( $percent > 100 ); + $percent = 0 if ( $percent < 0 ); + if ( !defined($completionPercent) + || int($completionPercent + 0.5) != int($percent) ) { + printf("completionPercent %.0f\n", $percent); + } + $completionPercent = $percent; +} + # # Run an optional pre- or post-dump command # diff --git a/bin/BackupPC_restore b/bin/BackupPC_restore index 4549ccf..1a5e487 100755 --- a/bin/BackupPC_restore +++ b/bin/BackupPC_restore @@ -29,7 +29,7 @@ # #======================================================================== # -# Version 3.1.0, released 25 Nov 2007. +# Version 3.2.0beta0, released 17 Jan 2009. # # See http://backuppc.sourceforge.net. # @@ -461,7 +461,7 @@ sub CorrectHostCheck || $Conf{NmbLookupCmd} eq "" ); my($netBiosHost, $netBiosUser) = $bpc->NetBiosInfoGet($hostIP); return "host $host has mismatching netbios name $netBiosHost" - if ( $netBiosHost ne $host ); + if ( lc($netBiosHost) ne lc(substr($host, 0, 15)) ); return; } diff --git a/lib/BackupPC/Lang/fr.pm b/lib/BackupPC/Lang/fr.pm index d66b604..1f709fc 100644 --- a/lib/BackupPC/Lang/fr.pm +++ b/lib/BackupPC/Lang/fr.pm @@ -51,7 +51,7 @@ $Lang{Admin_Start_Server} = < Le serveur BackupPC sur \$Conf{ServerHost}, port \$Conf{ServerPort} n'est pas en fonction (vous l'avez peut-être arrêté, ou vous ne l'avez pas encore démarré).
-Voulez-vous le démarrer? +Voulez-vous le démarrer ? diff --git a/lib/BackupPC/Lib.pm b/lib/BackupPC/Lib.pm index 7e63431..c13fc48 100644 --- a/lib/BackupPC/Lib.pm +++ b/lib/BackupPC/Lib.pm @@ -29,7 +29,7 @@ # #======================================================================== # -# Version 3.2.0, released 31 Dec 2008. +# Version 3.2.0beta0, released 17 Jan 2009. # # See http://backuppc.sourceforge.net. # @@ -130,7 +130,7 @@ sub new my $bpc = bless { %$paths, - Version => '3.2.0', + Version => '3.2.0beta0', }, $class; $bpc->{storage} = BackupPC::Storage->new($paths); @@ -1046,6 +1046,10 @@ sub NetBiosInfoGet }; $nmbCmd = $bpc->cmdVarSubstitute($bpc->{Conf}{NmbLookupCmd}, $args); foreach ( split(/[\n\r]+/, $bpc->cmdSystemOrEval($nmbCmd, undef, $args)) ) { + # + # skip and other non entries + # + next if ( /<\w{2}> - /i ); next if ( !/^\s*([\w\s-]+?)\s*<(\w{2})\> - .*/i ); $netBiosHostName ||= $1 if ( $2 eq "00" ); # host is first 00 $netBiosUserName = $1 if ( $2 eq "03" ); # user is last 03 diff --git a/lib/BackupPC/Xfer/Protocol.pm b/lib/BackupPC/Xfer/Protocol.pm index ae6b4c4..73e18a0 100644 --- a/lib/BackupPC/Xfer/Protocol.pm +++ b/lib/BackupPC/Xfer/Protocol.pm @@ -29,7 +29,7 @@ # #======================================================================== # -# Version 3.1.0, released 25 Nov 2007. +# Version 3.2.0beta0, released 17 Jan 2009. # # See http://backuppc.sourceforge.net. # @@ -270,7 +270,6 @@ sub logWrite return ( $XferLOG->write(\$msg) ) if ( $level <= $t->{logLevel} ); } - ############################################################################## # File Inclusion/Exclusion ############################################################################## diff --git a/lib/BackupPC/Xfer/Rsync.pm b/lib/BackupPC/Xfer/Rsync.pm index f92e667..0c1c336 100644 --- a/lib/BackupPC/Xfer/Rsync.pm +++ b/lib/BackupPC/Xfer/Rsync.pm @@ -29,7 +29,7 @@ # #======================================================================== # -# Version 3.2.0, released 31 Dec 2008. +# Version 3.2.0beta0, released 17 Jan 2009. # # See http://backuppc.sourceforge.net. # @@ -286,6 +286,9 @@ sub start pidHandler => sub { $t->{pidHandler}(@_); }, + completionPercent => sub { + $t->{completionPercent}(@_); + }, clientCharset => $conf->{ClientCharset}, fio => BackupPC::Xfer::RsyncFileIO->new({ xfer => $t, -- 2.20.1