X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=bin%2FBackupPC_ASA_ArchiveStart;h=c446363df2e9d5ca69fe76d91c87e19f850a79fd;hp=c527fa46557fe3279242776fb33db42197ef40e3;hb=7cc35df2d8753d1eddd17d3f377fffd6ef316c1d;hpb=180855aa8468f84a03c34b278214440b07778789 diff --git a/bin/BackupPC_ASA_ArchiveStart b/bin/BackupPC_ASA_ArchiveStart index c527fa4..c446363 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,39 @@ use lib "/usr/local/BackupPC/lib"; 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}) ) { @@ -70,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"; @@ -101,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}, host => $ArchiveHost, HostList => \@HostList, BackupList => \@BackupList,