create all archives which are missing for given host
[BackupPC.git] / bin / BackupPC_ASA_ArchiveStart
index bd294e4..669a0c1 100755 (executable)
@@ -62,6 +62,20 @@ EOF
     exit(1);
 }
 
+my %Conf = $bpc->Conf();
+
+my $dbh = DBI->connect($Conf{SearchDSN}, $Conf{SearchUser}, "", { RaiseError => 1, AutoCommit => 0 });
+
+my $sth = $dbh->prepare(qq{
+       select
+               backups.id as backup_id,
+               hosts.name as host,
+               backups.num as num
+       from backups
+       join hosts on hosts.id = hostid
+       where hosts.name = ? and inc_size < 0 and size > 0 and not inc_deleted
+});
+
 my $Hosts       = $bpc->HostInfoRead();
 my $ArchiveHost = $ARGV[0];
 my $UserName    = $ARGV[1];
@@ -85,9 +99,18 @@ for ( my $i = 2 ; $i < @ARGV ; $i++ ) {
         print(STDERR "$0: host $host doesn't have any backups... quitting\n");
         exit(1);
     }
-    push(@HostList, $host);
-    $num ||= $backups[$#backups]{num};
-    push(@BackupList, $num);
+
+    $sth->execute( $host );
+    if ( $sth->rows == 0 ) {
+       warn "no backups to archive on $host\n";
+       next;
+    }
+
+    while ( my $row = $sth->fetchrow_hashref ) {
+       warn "+ ", $row->{host}, " ", $row->{num}, "\n";
+       push(@HostList, $host);
+       push(@BackupList, $row->{num});
+    }
 }
 
 my $ReqFileName;