use DBI;
use Data::Dump qw(dump);
+my $debug = $ENV{DEBUG} || 0;
+
die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
my %opts;
select
backups.id as backup_id,
hosts.name as host,
- backups.num as num
+ backups.num as num,
+ inc_size,
+ size,
+ inc_deleted
from backups
join hosts on hosts.id = hostid
- where hosts.name = ? and inc_size < 0 and size > 0 and not inc_deleted
+ where hosts.name = ?
});
my $Hosts = $bpc->HostInfoRead();
next;
}
- $sth->execute( $host );
- if ( $sth->rows == 0 ) {
- warn "no backups to archive on $host\n";
- push @HostList, $host;
- push @BackupList, 0; # fake, but will make full-text update
- }
-
- while ( my $row = $sth->fetchrow_hashref ) {
- warn "+ ", $row->{host}, " ", $row->{num}, "\n";
- push(@HostList, $host);
- push(@BackupList, $row->{num});
- }
+ 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) if $debug;
+
+ my @backup_nums =
+ sort
+ grep { $all_backup_numbers->{$_} }
+ keys %$all_backup_numbers;
+
+ foreach my $num ( @backup_nums ) {
+ warn "+ $host $num\n";
+ push(@HostList, $host);
+ push(@BackupList, $num);
+ }
}
$dbh->disconnect;