X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=bin%2FBackupPC_ASA_ArchiveStart;h=f91a60f6078a035cf7edae468f771c67e783a832;hp=69d124c2b1f29ac97f3d713f2a4af82982e83635;hb=06017d5181d9c62f8cbd1c6d58d831f54d7d4ad1;hpb=74baa820fab5e1a03551526f0e9e671d9f74de03 diff --git a/bin/BackupPC_ASA_ArchiveStart b/bin/BackupPC_ASA_ArchiveStart index 69d124c..f91a60f 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(); @@ -89,39 +94,73 @@ if ( !defined($Hosts->{$ArchiveHost}) ) { } $bpc->ConfigRead($ArchiveHost); -if ( ! @HostFilter ) { - @HostFilter = keys %$Hosts; -} +my(@HostList, @BackupList); -warn "archiving hosts ",dump(@HostFilter); -my(@HostList, @BackupList); +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); - } - my @backups = $bpc->BackupInfoRead($host); - if ( !@backups ) { - warn "$0: host $host doesn't have any backups... skipping\n"; - 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 ($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); + } + } } +if ( ! @HostFilter ) { + foreach my $host ( keys %$host_nums ) { + foreach my $num ( @{ $host_nums->{$host} } ) { + warn "+ $host $num\n"; + push(@HostList, $host); + push(@BackupList, $num); + } + } +} + +warn "# HostList=",dump(@HostList),"\n"; +warn "# BackupList=",dump(@BackupList),"\n"; + $dbh->disconnect; my $ReqFileName;