Localization for 2.1.0
[BackupPC.git] / bin / BackupPC_dump
index d1509b7..23720ca 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/perl -T
+#!/bin/perl
 #============================================================= -*-perl-*-
 #
 # BackupPC_dump: Dump a single client.
@@ -70,7 +70,7 @@
 #
 #========================================================================
 #
-# Version 2.1.0_CVS, released 3 Jul 2003.
+# Version 2.1.0_CVS, released 8 Feb 2004.
 #
 # See http://backuppc.sourceforge.net.
 #
@@ -126,20 +126,19 @@ if ( $opts{d} ) {
     #
     $hostIP = $client;
     if ( $bpc->CheckHostAlive($hostIP) < 0 ) {
-       print("Exiting because CheckHostAlive($hostIP) failed\n")
+       print(STDERR "Exiting because CheckHostAlive($hostIP) failed\n")
                            if ( $opts{v} );
        exit(1);
     }
     if ( $Conf{NmbLookupCmd} eq "" ) {
-       print("Exiting because \$Conf{NmbLookupCmd} is empty\n")
+       print(STDERR "Exiting because \$Conf{NmbLookupCmd} is empty\n")
                            if ( $opts{v} );
        exit(1);
     }
     ($client, $user) = $bpc->NetBiosInfoGet($hostIP);
     if ( $client !~ /^([\w\.\s-]+)$/ ) {
-       print("Exiting because NetBiosInfoGet($hostIP) returned '$client',"
-           . " an invalid host name\n")
-                           if ( $opts{v} );
+       print(STDERR "Exiting because NetBiosInfoGet($hostIP) returned"
+                   . " '$client', an invalid host name\n") if ( $opts{v} );
        exit(1)
     }
     $Hosts = $bpc->HostInfoRead($client);
@@ -148,8 +147,8 @@ if ( $opts{d} ) {
     $Hosts = $bpc->HostInfoRead($client);
 }
 if ( !defined($Hosts->{$client}) ) {
-    print("Exiting because host $client does not exist in the hosts file\n")
-                           if ( $opts{v} );
+    print(STDERR "Exiting because host $client does not exist in the"
+               . " hosts file\n") if ( $opts{v} );
     exit(1)
 }
 
@@ -200,6 +199,13 @@ if ( $opts{e} ) {
     exit(0);
 }
 
+#
+# For archive hosts we don't bother any further
+#
+if ($Conf{XferMethod} eq "archive" ) {
+    exit(0);
+}
+
 if ( !$opts{d} ) {
     #
     # In the non-DHCP case, make sure the host can be looked up
@@ -215,7 +221,7 @@ if ( !$opts{d} ) {
         # Ok, NS doesn't know about it.  Maybe it is a NetBios name
         # instead.
         #
-       print("Name server doesn't know about $host; trying NetBios\n")
+       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");
@@ -253,7 +259,7 @@ $bpc->ServerDisconnect();
 if ( $opts{d} ) {
     if ( $StatusHost{activeJob} ) {
         # oops, something is already running for this host
-       print("Exiting because backup is already running for $client\n")
+       print(STDERR "Exiting because backup is already running for $client\n")
                        if ( $opts{v} );
         exit(0);
     }
@@ -264,6 +270,7 @@ my($needLink, @Backups, $type, $lastBkupNum, $lastFullBkupNum);
 my $lastFull = 0;
 my $lastIncr = 0;
 my $partialIdx = -1;
+my $partialNum;
 
 if ( $Conf{FullPeriod} == -1 && !$opts{f} && !$opts{i}
         || $Conf{FullPeriod} == -2 ) {
@@ -274,11 +281,32 @@ if ( !$opts{i} && !$opts{f} && $Conf{BlackoutGoodCnt} >= 0
              && $StatusHost{aliveCnt} >= $Conf{BlackoutGoodCnt} ) {
     my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
     my($currHours) = $hour + $min / 60 + $sec / 3600;
-    if ( $Conf{BlackoutHourBegin} <= $currHours
-              && $currHours <= $Conf{BlackoutHourEnd}
-              && grep($_ == $wday, @{$Conf{BlackoutWeekDays}}) ) {
+    my $blackout;
+    #
+    # Allow blackout to span midnight (specified by BlackoutHourBegin
+    # being greater than BlackoutHourEnd)
+    #
+    if ( $Conf{BlackoutHourBegin} > $Conf{BlackoutHourEnd} ) {
+        $blackout = $Conf{BlackoutHourBegin} <= $currHours
+                               || $currHours <= $Conf{BlackoutHourEnd};
+       if ( $currHours <= $Conf{BlackoutHourEnd} ) {
+           #
+           # This is after midnight, so decrement the weekday for the
+           # weekday check (eg: Monday 11pm-1am means Monday 2300 to
+           # Tuesday 0100, not Monday 2300-2400 plus Monday 0000-0100).
+           #
+           $wday--;
+           $wday += 7 if ( $wday < 0 );
+       }
+    } else {
+        $blackout = $Conf{BlackoutHourBegin} <= $currHours
+                               && $currHours <= $Conf{BlackoutHourEnd};
+    }
+    if ( $blackout && grep($_ == $wday, @{$Conf{BlackoutWeekDays}}) ) {
 #        print(LOG $bpc->timeStamp, "skipping because of blackout"
 #                    . " (alive $StatusHost{aliveCnt} times)\n");
+       print(STDERR "Skipping $client because of blackout\n")
+                       if ( $opts{v} );
         NothingToDo($needLink);
     }
 }
@@ -313,6 +341,7 @@ for ( my $i = 0 ; $i < @Backups ; $i++ ) {
                 if ( $lastIncr < $Backups[$i]{startTime} );
     } elsif ( $Backups[$i]{type} eq "partial" ) {
         $partialIdx = $i;
+        $partialNum = $Backups[$i]{num};
     }
 }
 
@@ -378,7 +407,7 @@ if ( !defined($XferLOG) ) {
     print("dump failed: unable to open/create $Dir/XferLOG$fileExt\n");
     exit(1);
 }
-$XferLOG->writeTeeStdout(1) if ( $opts{v} );
+$XferLOG->writeTeeStderr(1) if ( $opts{v} );
 unlink("$Dir/NewFileList");
 my $startTime = time();
 
@@ -493,6 +522,7 @@ for my $shareName ( @$ShareNames ) {
            open(STDERR, ">&STDOUT");
            close(STDIN);
            open(STDIN, "<&RH");
+           alarm(0);
            exec("$BinDir/BackupPC_tarExtract", $client, $shareName,
                         $Conf{CompressLevel});
            print(LOG $bpc->timeStamp,
@@ -531,6 +561,7 @@ for my $shareName ( @$ShareNames ) {
        compress    => $Conf{CompressLevel},
        XferMethod  => $Conf{XferMethod},
        pidHandler  => \&pidHandler,
+        partialNum  => $partialNum,
     });
 
     if ( !defined($logMsg = $xfer->start()) ) {
@@ -682,10 +713,10 @@ for my $shareName ( @$ShareNames ) {
 }
 
 #
-# If any share had zero files then consider the dump bad
+# If this is a full, and any share had zero files then consider the dump bad
 #
-if ( $stat{hostError} eq ""
-       && length($noFilesErr) && $Conf{BackupZeroFilesIsFatal} ) {
+if ( $type eq "full" && $stat{hostError} eq ""
+           && length($noFilesErr) && $Conf{BackupZeroFilesIsFatal} ) {
     $stat{hostError} = $noFilesErr;
     $stat{xferOK} = 0;
 }