* Commit for 2.1.0.
[BackupPC.git] / bin / BackupPC
index 585eec1..50d5500 100755 (executable)
@@ -47,7 +47,7 @@
 #
 #========================================================================
 #
-# Version 2.1.0beta1, released 9 Apr 2004.
+# Version 2.1.0, released 20 Jun 2004.
 #
 # See http://backuppc.sourceforge.net.
 #
@@ -596,7 +596,7 @@ sub Main_TryToRun_Bg_or_User_Queue
             if ( $du > $Conf{DfMaxUsagePct} ) {
                 my $nSkip = @BgQueue + @deferBgQueue;
                 print(LOG $bpc->timeStamp,
-                           "Disk too full ($du%%); skipping $nSkip hosts\n");
+                           "Disk too full ($du%); skipping $nSkip hosts\n");
                $Info{DUDailySkipHostCnt} += $nSkip;
                 @BgQueue = ();
                 @deferBgQueue = ();
@@ -782,6 +782,8 @@ sub Main_Check_Timeout
         }
         print(LOG $bpc->timeStamp, "Aging LOG files, LOG -> LOG.0 -> "
                    . "LOG.1 -> ... -> LOG.$lastLog\n");
+       close(STDERR);          # dup of LOG
+       close(STDOUT);          # dup of LOG
         close(LOG);
         for ( my $i = $lastLog - 1 ; $i >= 0 ; $i-- ) {
             my $j = $i + 1;
@@ -1531,6 +1533,18 @@ sub StatusWrite
     }
 }
 
+#
+# Compare function for host sort.  Hosts with errors go first,
+# sorted with the oldest errors first.  The remaining hosts
+# are sorted so that those with the oldest backups go first.
+#
+sub HostSortCompare
+{
+    return -1 if ( $Status{$a}{error} ne "" && $Status{$b}{error} eq "" );
+    return  1 if ( $Status{$a}{error} eq "" && $Status{$b}{error} ne "" );
+    return $Status{$a}{endTime} <=> $Status{$b}{endTime};
+}
+
 #
 # Queue all the hosts for backup.  This means queuing all the fixed
 # ip hosts and all the dhcp address ranges.  We also additionally
@@ -1538,7 +1552,7 @@ sub StatusWrite
 #
 sub QueueAllPCs
 {
-    foreach my $host ( sort(keys(%$Hosts)) ) {
+    foreach my $host ( sort(HostSortCompare keys(%$Hosts)) ) {
         delete($Status{$host}{backoffTime})
                 if ( defined($Status{$host}{backoffTime})
                   && $Status{$host}{backoffTime} < time );