From: Dobrica Pavlinusic Date: Sat, 29 Jan 2011 13:02:51 +0000 (+0100) Subject: use same logic as CGI/Archive.pm X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=commitdiff_plain;h=3d58bf6f3395b7586acc0f44aa3c60232663914f use same logic as CGI/Archive.pm This will select increments which are not yet indexed, because archive will update database and full-text search for them. --- diff --git a/bin/BackupPC_ASA_ArchiveStart b/bin/BackupPC_ASA_ArchiveStart index 69d124c..f9372fd 100755 --- a/bin/BackupPC_ASA_ArchiveStart +++ b/bin/BackupPC_ASA_ArchiveStart @@ -51,6 +51,8 @@ use BackupPC::Lib; 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; @@ -71,10 +73,13 @@ my $sth = $dbh->prepare(qq{ 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(); @@ -108,18 +113,32 @@ foreach ( @HostFilter ) { 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;