-for ( my $i = 2 ; $i < @ARGV ; $i++ ) {
- my ($host,$num) = split(/:/,$ARGV[$i],2);
- if ( !defined($Hosts->{$host}) ) {
- print(STDERR "$0: host $host doesn't exist... quitting\n");
- exit(1);
- }
- my @backups = $bpc->BackupInfoRead($host);
- if ( !@backups ) {
- print(STDERR "$0: host $host doesn't have any backups... quitting\n");
- exit(1);
- }
- push(@HostList, $host);
- $num ||= $backups[$#backups]{num};
- push(@BackupList, $num);
+
+
+my $host_nums;
+
+foreach my $host ( keys %$Hosts ) {
+ my @backups = $bpc->BackupInfoRead($host);
+ if ( !@backups ) {
+ warn "$0: host $host doesn't have any backups... skipping\n";
+ next;
+ }
+
+ my $all_backup_numbers;
+ $all_backup_numbers->{ $_->{num} }++ foreach @backups;
+
+ $sth->execute( $host );
+ while ( my $row = $sth->fetchrow_hashref ) {
+ warn "# row ",dump($row) if $debug;
+ $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 all_backup_numbers = ",dump($all_backup_numbers),"\n";
+
+ $host_nums->{$host} = [
+ sort
+ grep { $all_backup_numbers->{$_} }
+ keys %$all_backup_numbers
+ ];
+}
+
+foreach ( @HostFilter ) {
+ my ($host,$num) = split(/:/,$_,2);
+ if ( !defined($Hosts->{$host}) ) {
+ print(STDERR "$0: host $host doesn't exist... quitting\n");
+ exit(1);
+ }
+ if ( defined $num ) {
+ warn "+ $host $num\n";
+ push(@HostList, $host);
+ push(@BackupList, $num);
+ } else {
+ foreach my $num ( @{ $host_nums->{$host} } ) {
+ warn "+ $host $num\n";
+ push(@HostList, $host);
+ push(@BackupList, $num);
+ }
+ }