X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=bin%2FBackupPC_ASA_ArchiveStart;h=f91a60f6078a035cf7edae468f771c67e783a832;hp=c527fa46557fe3279242776fb33db42197ef40e3;hb=06017d5181d9c62f8cbd1c6d58d831f54d7d4ad1;hpb=180855aa8468f84a03c34b278214440b07778789 diff --git a/bin/BackupPC_ASA_ArchiveStart b/bin/BackupPC_ASA_ArchiveStart index c527fa4..f91a60f 100755 --- a/bin/BackupPC_ASA_ArchiveStart +++ b/bin/BackupPC_ASA_ArchiveStart @@ -15,6 +15,7 @@ # # AUTHOR # Craig Barratt +# Dobrica Pavlinusic # # COPYRIGHT # Copyright (C) 2007-2009 Craig Barratt @@ -47,21 +48,44 @@ use lib "/usr/local/BackupPC/lib"; use Getopt::Std; 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; # no options currently -if ( !getopts("", \%opts) || @ARGV < 3 ) { +if ( !getopts("", \%opts) || @ARGV < 2 ) { print STDERR <Conf(); + +my $dbh = DBI->connect($Conf{SearchDSN}, $Conf{SearchUser}, "", { RaiseError => 1, AutoCommit => 0 }); + +my $sth = $dbh->prepare(qq{ + select + backups.id as backup_id, + hosts.name as host, + backups.num as num, + inc_size, + size, + inc_deleted + from backups + join hosts on hosts.id = hostid + where hosts.name = ? +}); + my $Hosts = $bpc->HostInfoRead(); -my $ArchiveHost = $ARGV[0]; -my $UserName = $ARGV[1]; +my $ArchiveHost = shift @ARGV; +my $UserName = shift @ARGV; +my @HostFilter = @ARGV; my $TopDir = $bpc->{Conf}{TopDir}; if ( !defined($Hosts->{$ArchiveHost}) ) { @@ -71,22 +95,74 @@ if ( !defined($Hosts->{$ArchiveHost}) ) { $bpc->ConfigRead($ArchiveHost); my(@HostList, @BackupList); -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); + } + } } +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; for ( my $i = 0 ; ; $i++ ) { $ReqFileName="archiveReq.$$.$i"; @@ -101,7 +177,7 @@ my %ArchiveReq = ( compext => $bpc->{Conf}{ArchiveComp} eq 'none' ? '' : ($bpc->{Conf}{ArchiveComp} eq 'gzip' ? '.gz' : '.bz2'), parfile => $bpc->{Conf}{ArchivePar}, - splitsize => '0000000', + splitsize => $bpc->{Conf}{ArchiveSplit} . '000000', # mb -> bytes host => $ArchiveHost, HostList => \@HostList, BackupList => \@BackupList,