X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=bin%2FBackupPC_ASA_SearchUpdate;h=279b8b0b1fb17cec684928d12a495a9836227bc3;hp=ede665fd1cfb3f1b7f2b7ad01dfb9ca72721b6a8;hb=d1bfa4d92bec24954f2e7877f6531644bb84e8f3;hpb=dfc71d1e230596fcb539889fce2a475c45e0acd0 diff --git a/bin/BackupPC_ASA_SearchUpdate b/bin/BackupPC_ASA_SearchUpdate index ede665f..279b8b0 100755 --- a/bin/BackupPC_ASA_SearchUpdate +++ b/bin/BackupPC_ASA_SearchUpdate @@ -7,7 +7,7 @@ use DBI; use BackupPC::Lib; use BackupPC::View; use Data::Dumper; -use Getopt::Std; +use Getopt::Long::Descriptive; use Time::HiRes qw/time/; use File::Pid; use POSIX qw/strftime/; @@ -57,43 +57,40 @@ my $index_node_url = $Conf{HyperEstraierIndex}; my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 }); -my %opt; +my ($opt,$usage) = describe_options( +"%c %o", +[ 'create|c', "create database on first use" ], +[ 'delete|d', "delete database before import" ], +[ 'max|m=i', "import just max increments for one host" ], +[ 'host|h=s@', "import just host(s)" ], +[], +[ 'verbose|v:i', 'set verbosity (debug) level' ], +[ 'index|i', 'update full text index' ], +[ 'junk|j', "update full text, don't check existing files" ], +[ 'fast|f', "don't do anything with full text index" ], +[ 'quiet|q', "be quiet for hosts without changes" ], +[ 'help', "show help" ], +); + +print($usage->text), exit if $opt->help; + +warn "hosts: ",dump( $opt->host ); -if ( !getopts("cdm:v:ijfqh:", \%opt ) ) { - print STDERR <junk && print STDERR "Skipping check for existing files -- this should be used only with initital import\n"; print curr_time," updating fulltext:"; @@ -186,6 +183,7 @@ sub hest_update { } print "$added"; + status "| $added"; $offset += EST_CHUNK; @@ -204,17 +202,17 @@ sub hest_update { ## update index ## -if ( ( $opt{i} || $opt{j} ) && !$opt{c} ) { +if ( ( $opt->index || $opt->junk ) && !$opt->create ) { # update all print "force update of Hyper Estraier index "; - print "by -i flag" if ($opt{i}); - print "by -j flag" if ($opt{j}); + print "by -i flag" if ($opt->index); + print "by -j flag" if ($opt->junk); print "\n"; hest_update(); } ## create tables ## -if ($opt{c}) { +if ($opt->create) { sub do_index { my $index = shift || return; my ($table,$col,$unique) = split(/:/, $index); @@ -359,8 +357,6 @@ if ($opt{c}) { $dbh->do( qq{ CREATE SEQUENCE $seq } ); } -=cut - print " creating triggers "; $dbh->do( <<__END_OF_TRIGGER__ ); @@ -422,8 +418,6 @@ create trigger do_backup_backup_parts_check __END_OF_TRIGGER__ -=cut - print "...\n"; $dbh->commit; @@ -431,7 +425,7 @@ __END_OF_TRIGGER__ } ## delete data before inseting ## -if ($opt{d}) { +if ($opt->delete) { print "deleting "; foreach my $table (qw(files dvds backups shares hosts)) { print "$table "; @@ -456,7 +450,7 @@ INSERT INTO hosts (name, IP) VALUES (?,?) }); $sth->{hosts_by_name} = $dbh->prepare(qq{ -SELECT ID FROM hosts WHERE name=? +SELECT id FROM hosts WHERE name=? }); $sth->{backups_count} = $dbh->prepare(qq{ @@ -484,18 +478,11 @@ INSERT INTO files my @hosts = keys %{$hosts}; my $host_nr = 0; -my $host_regex; -if ( exists $opt{h} ) { - $host_regex = $opt{h}; - $host_regex =~ s/\s+/|/g; - $host_regex = '^' . $host_regex . '$'; -} - foreach my $host_key (@hosts) { my $hostname = $hosts->{$host_key}->{'host'} || die "can't find host for $host_key"; - next if $host_regex && $hostname =~ m/$host_regex/; + next if $opt->host && ! grep { m/^$hostname$/ } @{ $opt->host }; $sth->{hosts_by_name}->execute($hostname); @@ -519,7 +506,7 @@ foreach my $host_key (@hosts) { ($#hosts + 1), $incs ); - print $host_header unless ($opt{q}); + print $host_header unless $opt->quiet; my $inc_nr = 0; $beenThere = {}; @@ -527,7 +514,7 @@ foreach my $host_key (@hosts) { foreach my $backup (@backups) { $inc_nr++; - last if (defined $opt{m} && $inc_nr > $opt{m}); + last if defined $opt->max && $inc_nr > $opt->max; my $backupNum = $backup->{'num'}; my @backupShares = (); @@ -540,9 +527,10 @@ foreach my $host_key (@hosts) { strftime($t_fmt,localtime($backup->{startTime})), fmt_time($backup->{endTime} - $backup->{startTime}) ); - print $share_header unless ($opt{q}); + print $share_header unless $opt->quiet; + status "$hostname $backupNum $share_header"; - my $files = BackupPC::View->new($bpc, $hostname, \@backups, { only_first => 1 }); + my $files = BackupPC::View->new($bpc, $hostname, \@backups, { only_increment => 1 }); foreach my $share ($files->shareList($backupNum)) { @@ -556,7 +544,7 @@ foreach my $host_key (@hosts) { next if ($count > 0); # dump host and share header for -q - if ($opt{q}) { + if ( $opt->quiet ) { if ($host_header) { print $host_header; $host_header = undef; @@ -595,16 +583,21 @@ foreach my $host_key (@hosts) { } my $dur = (time() - $t) || 1; - printf(" %d/%d files %d/%d dirs %0.2f MB [%.2f/s dur: %s]\n", + my $status = sprintf("%d/%d files %d/%d dirs %0.2f MB [%.2f/s dur: %s]", $nf, $f, $nd, $d, ($size / 1024 / 1024), ( ($f+$d) / $dur ), fmt_time($dur) ); + print " $status\n"; + status "$hostname $backupNum $status"; if ($nf + $nd > 0) { - eval { hest_update($hostID, $shareID, $backupNum) }; - warn "ERROR: $@" if $@; + status "$hostname $backupNum full-text | indexing"; + #eval { hest_update($hostID, $shareID, $backupNum) }; + #warn "ERROR: $@" if $@; + hest_update($hostID, $shareID, $backupNum); + # eval breaks our re-try logic } }