- fixed configure.pl and makeDist.
[BackupPC.git] / bin / BackupPC_nightly
index b3a4802..a53e592 100755 (executable)
@@ -20,6 +20,9 @@
 #
 #     -m   Do monthly aging of per-PC log files and sending of email.
 #          Otherise, BackupPC_nightly just does pool pruning.
+#          Since several BackupPC_nightly processes might run
+#          concurrently, just the first one is given the -m flag
+#          by BackupPC.
 #
 #   The poolRangeStart and poolRangeEnd arguments are integers from 0 to 255.
 #   These specify which parts of the pool to process.  There are 256 2nd-level
@@ -52,7 +55,7 @@
 #
 #========================================================================
 #
-# Version 2.1.0beta1, released 9 Apr 2004.
+# Version 3.0.0alpha, released 23 Jan 2006.
 #
 # See http://backuppc.sourceforge.net.
 #
@@ -127,6 +130,7 @@ my $fileCntRep;    # total number of file names containing "_", ie: files
 my $fileRepMax;    # worse case number of files that have repeated checksums
                    # (ie: max(nnn+1) for all names xxxxxxxxxxxxxxxx_nnn)
 my $fileLinkMax;   # maximum number of hardlinks on a pool file
+my $fileLinkTotal; # total number of hardlinks on entire pool
 my $fileCntRename; # number of renamed files (to keep file numbering
                    # contiguous)
 my %FixList;       # list of paths that need to be renamed to avoid
@@ -148,7 +152,8 @@ for my $pool ( qw(pool cpool) ) {
         $fileLinkMax   = 0;
         $fileCntRename = 0;
         %FixList       = ();
-        find({wanted => \&GetPoolStats}, "$TopDir/$pool/$dir");
+        find({wanted => \&GetPoolStats}, "$TopDir/$pool/$dir")
+                                           if ( -d "$TopDir/$pool/$dir" );
         my $kb   = $blkCnt / 2;
         my $kbRm = $blkCntRm / 2;
         my $kb2  = $blkCnt2 / 2;
@@ -193,7 +198,7 @@ for my $pool ( qw(pool cpool) ) {
         }
         print("BackupPC_stats $i = $pool,$fileCnt,$dirCnt,$kb,$kb2,$kbRm,"
                               . "$fileCntRm,$fileCntRep,$fileRepMax,"
-                              . "$fileCntRename,$fileLinkMax\n");
+                              . "$fileCntRename,$fileLinkMax,$fileLinkTotal\n");
     }
 }
 
@@ -206,11 +211,12 @@ for my $pool ( qw(pool cpool) ) {
 printf("BackupPC_nightly lock_off\n");
 
 ###########################################################################
-# Send email 
+# Send email and generation of backupInfo files for each backup
 ###########################################################################
 if ( $opts{m} ) {
     print("log BackupPC_nightly now running BackupPC_sendEmail\n");
-    system("$BinDir/BackupPC_sendEmail")
+    system("$BinDir/BackupPC_sendEmail");
+    doBackupInfoUpdate();
 }
 
 #
@@ -249,6 +255,31 @@ sub doPerPCLogFileAging
     }
 }
 
+#
+# Update the backupInfo files based on the backups file.
+# We do this just once a week (on Sun) since it is only
+# needed for old backups with BackupPC <= 2.1.2.
+#
+sub doBackupInfoUpdate
+{
+    my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
+    return if ( $wday != 0 );
+
+    foreach my $host ( sort(keys(%{$bpc->HostInfoRead()})) ) {
+        my @Backups = $bpc->BackupInfoRead($host);
+
+        for ( my $i = 0 ; $i < @Backups ; $i++ ) {
+            #
+            # BackupPC::Storage->backupInfoWrite won't overwrite
+            # an existing file
+            #
+            BackupPC::Storage->backupInfoWrite("$TopDir/pc/$host",
+                                               $Backups[$i]{num},
+                                               $Backups[$i]);
+        }
+    }
+}
+
 sub GetPoolStats
 {
     my($nlinks, $nblocks) = (lstat($_))[3, 12];
@@ -282,5 +313,6 @@ sub GetPoolStats
         $blkCnt  += $nblocks;
         $blkCnt2 += $nblocks if ( $nlinks == 2 );
         $fileLinkMax = $nlinks if ( $fileLinkMax < $nlinks );
+        $fileLinkTotal += $nlinks - 1;
     }
 }