added common BackupPC::Search::host_backup_nums
[BackupPC.git] / lib / BackupPC / Search.pm
index ee982ff..a6f01ff 100644 (file)
@@ -354,6 +354,43 @@ sub getGzipSize($$)
        );
 }
 
        );
 }
 
+sub host_backup_nums {
+       my $host = shift;
+       my $sth = get_dbh->prepare(qq{
+               select
+                       hosts.name as host, -- FIXME for debug
+                       backups.num as num,
+                       inc_size,
+                       size,
+                       inc_deleted
+               from backups
+               join hosts on hosts.id = hostid
+               where hosts.name = ?
+       });
+       $sth->execute($host);
+       # and inc_size < 0 and size > 0 and not inc_deleted
+
+       my $all_backup_numbers;
+
+       while( my $row = $sth->fetchrow_hashref ) {
+warn "# row ",dump $row;
+               $all_backup_numbers->{ $row->{num} } =
+               $row->{inc_deleted}  ? 0 :
+               $row->{size}    == 0 ? 0 :
+               $row->{inc_size} > 0 ? 0 :
+               $row->{size}     > 0 ? 1 :
+               0;
+       }
+
+warn "# host $host all_backup_numbers = ",dump($all_backup_numbers);
+       my @backup_nums = 
+               sort { $a <=> $b }
+               grep { $all_backup_numbers->{$_} }
+               keys %$all_backup_numbers;
+
+       return @backup_nums;
+}
+
 
 sub getBackupsNotBurned($) {
 
 
 sub getBackupsNotBurned($) {