X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=bin%2FBackupPC_ASA_ArchiveStart;h=69d124c2b1f29ac97f3d713f2a4af82982e83635;hp=bd294e4350c222ce6f235ff3cf4417224b32263e;hb=74baa820fab5e1a03551526f0e9e671d9f74de03;hpb=485515f3a375c43115b1b04ab06b4048b6a64aaf diff --git a/bin/BackupPC_ASA_ArchiveStart b/bin/BackupPC_ASA_ArchiveStart index bd294e4..69d124c 100755 --- a/bin/BackupPC_ASA_ArchiveStart +++ b/bin/BackupPC_ASA_ArchiveStart @@ -49,22 +49,38 @@ use Getopt::Std; use BackupPC::Lib; use DBI; +use Data::Dump qw(dump); 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 + from backups + join hosts on hosts.id = hostid + where hosts.name = ? and inc_size < 0 and size > 0 and not inc_deleted +}); + 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}) ) { @@ -73,23 +89,41 @@ if ( !defined($Hosts->{$ArchiveHost}) ) { } $bpc->ConfigRead($ArchiveHost); +if ( ! @HostFilter ) { + @HostFilter = keys %$Hosts; +} + +warn "archiving hosts ",dump(@HostFilter); + my(@HostList, @BackupList); -for ( my $i = 2 ; $i < @ARGV ; $i++ ) { - my ($host,$num) = split(/:/,$ARGV[$i],2); +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 ) { - print(STDERR "$0: host $host doesn't have any backups... quitting\n"); - exit(1); + 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}); } - push(@HostList, $host); - $num ||= $backups[$#backups]{num}; - push(@BackupList, $num); } +$dbh->disconnect; + my $ReqFileName; for ( my $i = 0 ; ; $i++ ) { $ReqFileName="archiveReq.$$.$i"; @@ -104,7 +138,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,