Various changes, including changes in 2.1.1 and 2.1.2 releases.
[BackupPC.git] / bin / BackupPC_dump
index d2ed361..8151cbd 100755 (executable)
@@ -70,7 +70,7 @@
 #
 #========================================================================
 #
-# Version 2.1.0beta2, released 23 May 2004.
+# Version 2.1.0, released 20 Jun 2004.
 #
 # See http://backuppc.sourceforge.net.
 #
@@ -348,7 +348,7 @@ if ( !$opts{i} && !$opts{f} && $Conf{BlackoutGoodCnt} >= 0
 }
 
 if ( !$opts{i} && !$opts{f} && $StatusHost{backoffTime} > time ) {
-    printf(LOG "%sskipping because of user requested delay (%.1f hours left)",
+    printf(LOG "%sskipping because of user requested delay (%.1f hours left)\n",
                 $bpc->timeStamp, ($StatusHost{backoffTime} - time) / 3600);
     NothingToDo($needLink);
 }
@@ -434,7 +434,11 @@ $bpc->RmTreeDefer("$TopDir/trash", "$Dir/new") if ( -d "$Dir/new" );
 #
 # Setup file extension for compression and open XferLOG output file
 #
-$Conf{CompressLevel} = 0 if ( !BackupPC::FileZIO->compOk );
+if ( $Conf{CompressLevel} && !BackupPC::FileZIO->compOk ) {
+    print(LOG $bpc->timeStamp, "dump failed: can't find Compress::Zlib\n");
+    print("dump failed: can't find Compress::Zlib\n");
+    exit(1);
+}
 my $fileExt = $Conf{CompressLevel} > 0 ? ".z" : "";
 my $XferLOG = BackupPC::FileZIO->open("$Dir/XferLOG$fileExt", 1,
                                      $Conf{CompressLevel});
@@ -518,6 +522,8 @@ for my $shareName ( @$ShareNames ) {
         next;
     }
 
+    UserCommandRun("DumpPreShareCmd", $shareName);
+
     if ( $Conf{XferMethod} eq "tar" ) {
         #
         # Use tar (eg: tar/ssh) as the transport program.
@@ -531,6 +537,7 @@ for my $shareName ( @$ShareNames ) {
             my $errStr = BackupPC::Xfer::Rsync::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);
         }
@@ -650,6 +657,7 @@ for my $shareName ( @$ShareNames ) {
            sleep(1);
            kill($bpc->sigName2num("KILL"), @xferPid);
        }
+       UserCommandRun("DumpPostShareCmd", $shareName) if ( $NeedPostCmd );
        UserCommandRun("DumpPostUserCmd") if ( $NeedPostCmd );
         exit(1);
     }
@@ -763,6 +771,9 @@ for my $shareName ( @$ShareNames ) {
             next;
         }
     }
+
+    UserCommandRun("DumpPostShareCmd", $shareName) if ( $NeedPostCmd );
+
     $stat{xferOK} = 0 if ( $stat{hostError} || $stat{hostAbort} );
     if ( !$stat{xferOK} ) {
         #
@@ -1102,8 +1113,26 @@ sub BackupExpire
         # Delete any old full backups, according to $Conf{FullKeepCntMin}
        # and $Conf{FullAgeMax}.
         #
+       # First make sure that $Conf{FullAgeMax} is at least bigger
+       # than $Conf{FullPeriod} * $Conf{FullKeepCnt}, including
+       # the exponential array case.
+        #
+       my $fullKeepCnt = $Conf{FullKeepCnt};
+       $fullKeepCnt = [$fullKeepCnt] if ( ref($fullKeepCnt) ne "ARRAY" );
+       my $fullAgeMax;
+       my $fullPeriod = int(0.5 + $Conf{FullPeriod});
+        $fullPeriod = 7 if ( $fullPeriod <= 0 );
+       for ( my $i = 0 ; $i < @$fullKeepCnt ; $i++ ) {
+           $fullAgeMax += $fullKeepCnt->[$i] * $fullPeriod;
+           $fullPeriod *= 2;
+       }
+       $fullAgeMax += $fullPeriod;     # add some buffer
+
         if ( $cntFull > $Conf{FullKeepCntMin}
                && $oldestFull > $Conf{FullAgeMax}
+               && $oldestFull > $fullAgeMax
+              && $Conf{FullKeepCntMin} > 0
+              && $Conf{FullAgeMax} > 0
                && (@Backups <= $firstFull + 1
                         || !$Backups[$firstFull + 1]{noFill}) ) {
             #
@@ -1179,8 +1208,8 @@ sub BackupFullExpire
             #
             # Delete the full backup
             #
-            #printf("Deleting backup $i ($prevFull)\n");
-            push(@delete, $i);
+            #print("Deleting backup $i ($prevFull)\n");
+            unshift(@delete, $i);
         } else {
             $fullCnt++;
             while ( $fullKeepIdx < @$fullKeepCnt
@@ -1321,6 +1350,11 @@ sub BackupRemove
     my($client, $Backups, $idx) = @_;
     my($Dir) = "$TopDir/pc/$client";
 
+    if ( $Backups->[$idx]{num} eq "" ) {
+        print("BackupRemove: ignoring empty backup number for idx $idx\n");
+        return;
+    }
+
     $bpc->RmTreeDefer("$TopDir/trash",
                       "$Dir/$Backups->[$idx]{num}");
     unlink("$Dir/SmbLOG.$Backups->[$idx]{num}")
@@ -1367,9 +1401,9 @@ sub pidHandler
 #
 sub UserCommandRun
 {
-    my($type) = @_;
+    my($cmdType, $sharename) = @_;
 
-    return if ( !defined($Conf{$type}) );
+    return if ( !defined($Conf{$cmdType}) );
     my $vars = {
         xfer       => $xfer,
         client     => $client,
@@ -1387,9 +1421,15 @@ sub UserCommandRun
         xferOK     => $stat{xferOK} || 0,
        hostError  => $stat{hostError},
        type       => $type,
+       cmdType    => $cmdType,
     };
-    my $cmd = $bpc->cmdVarSubstitute($Conf{$type}, $vars);
-    $XferLOG->write(\"Executing $type: @$cmd\n");
+
+    if ($cmdType eq 'DumpPreShareCmd' || $cmdType eq 'DumpPostShareCmd') {
+       $vars->{share} = $sharename;
+    }
+
+    my $cmd = $bpc->cmdVarSubstitute($Conf{$cmdType}, $vars);
+    $XferLOG->write(\"Executing $cmdType: @$cmd\n");
     #
     # Run the user's command, dumping the stdout/stderr into the
     # Xfer log file.  Also supply the optional $vars and %Conf in