--- trunk/bin/BackupPC_updatedb 2006/01/28 16:45:46 303 +++ trunk/bin/BackupPC_updatedb 2006/01/31 16:29:30 325 @@ -15,7 +15,7 @@ use Cwd qw/abs_path/; use constant BPC_FTYPE_DIR => 5; -use constant EST_CHUNK => 100000; +use constant EST_CHUNK => 4096; # daylight saving time change offset for 1h my $dst_offset = 60 * 60; @@ -58,7 +58,7 @@ my %opt; -if ( !getopts("cdm:v:ijf", \%opt ) ) { +if ( !getopts("cdm:v:ijfq", \%opt ) ) { print STDERR <sync(); - $hest_db->close(); - } - exit(0); -} - -$SIG{'INT'} = \&signal; -$SIG{'QUIT'} = \&signal; - sub hest_update { my ($host_id, $share_id, $num) = @_; @@ -139,13 +126,15 @@ my $offset = 0; my $added = 0; - print " opening index $index_node_url"; if ($index_node_url) { - $hest_node ||= Search::Estraier::Node->new($index_node_url); - $hest_node->set_auth('admin', 'admin'); + print " opening index $index_node_url"; + $hest_node ||= Search::Estraier::Node->new( + url => $index_node_url, + user => 'admin', + passwd => 'admin', + croak_on_error => 1, + ); print " via node URL"; - } else { - die "don't know how to use Hyper Estraier Index $index_node_url"; } my $results = 0; @@ -193,9 +182,9 @@ if ($results == 0) { print " - no new files\n"; - last; + return; } else { - print " - $results files: "; + print "..."; } sub fmt_date { @@ -207,12 +196,10 @@ while (my $row = $sth->fetchrow_hashref()) { - my $fid = $row->{'fid'} || die "no fid?"; - my $uri = 'file:///' . $fid; - - unless ($skip_check) { - my $id = ($hest_db || $hest_node)->uri_to_id($uri); - next unless ($id == -1); + my $uri = $row->{hname} . ':' . $row->{sname} . '#' . $row->{backupnum} . ' ' . $row->{filepath}; + unless ($skip_check && $hest_node) { + my $id = $hest_node->uri_to_id($uri); + next if ($id && $id == -1); } # create a document object @@ -222,6 +209,7 @@ $doc->add_attr('@uri', $uri); foreach my $c (@{ $sth->{NAME} }) { + print STDERR "attr $c = $row->{$c}\n" if ($debug > 2); $doc->add_attr($c, $row->{$c}) if (defined($row->{$c})); } @@ -244,7 +232,7 @@ $added++; } - print " $added"; + print "$added"; $offset += EST_CHUNK; @@ -314,7 +302,7 @@ size bigint not null, inc_size bigint not null default -1, inc_deleted boolean default false, - parts integer not null default 1, + parts integer not null default 0, PRIMARY KEY(id) ); @@ -394,6 +382,33 @@ $dbh->do( qq{ CREATE SEQUENCE $seq } ); } + print " creating triggers "; + $dbh->do( qq{ + create or replace function backup_parts_check() returns trigger as ' + declare + b_parts integer; + b_counted integer; + b_id integer; + begin + if (TG_OP=''UPDATE'') then + b_id := old.id; + b_parts := old.parts; + elsif (TG_OP = ''INSERT'') then + b_id := new.id; + b_parts := new.parts; + end if; + b_counted := (select count(*) from backup_parts where backup_id = b_id); + if ( b_parts != b_counted ) then + raise exception ''Update of backup % aborted, requested % parts and there are really % parts'', b_id, b_parts, b_counted; + end if; + return null; + end; + ' language plpgsql; + + create trigger do_backup_parts_check + after insert or update or delete on backups + for each row execute procedure backup_parts_check(); + }); print "...\n"; @@ -471,14 +486,18 @@ } $host_nr++; - print "host ", $hosts->{$host_key}->{'host'}, " [", - $host_nr, "/", ($#hosts + 1), "]: "; - # get backups for a host my @backups = $bpc->BackupInfoRead($hostname); my $incs = scalar @backups; - print "$incs increments\n"; + my $host_header = sprintf("host %s [%d/%d]: %d increments\n", + $hosts->{$host_key}->{'host'}, + $host_nr, + ($#hosts + 1), + $incs + ); + print $host_header unless ($opt{q}); + my $inc_nr = 0; $beenThere = {}; @@ -490,7 +509,7 @@ my $backupNum = $backup->{'num'}; my @backupShares = (); - printf("%-10s %2d/%-2d #%-2d %s %5s/%5s files (date: %s dur: %s)\n", + my $share_header = sprintf("%-10s %2d/%-2d #%-2d %s %5s/%5s files (date: %s dur: %s)\n", $hosts->{$host_key}->{'host'}, $inc_nr, $incs, $backupNum, $backup->{type} || '?', @@ -498,6 +517,7 @@ strftime($t_fmt,localtime($backup->{startTime})), fmt_time($backup->{endTime} - $backup->{startTime}) ); + print $share_header unless ($opt{q}); my $files = BackupPC::View->new($bpc, $hostname, \@backups, 1); foreach my $share ($files->shareList($backupNum)) { @@ -511,6 +531,15 @@ # skip if allready in database! next if ($count > 0); + # dump host and share header for -q + if ($opt{q}) { + if ($host_header) { + print $host_header; + $host_header = undef; + } + print $share_header; + } + # dump some log print curr_time," ", $share;