--- trunk/bin/BackupPC_updatedb 2006/01/31 16:22:21 324 +++ trunk/bin/BackupPC_updatedb 2006/01/31 16:29:30 325 @@ -126,8 +126,8 @@ my $offset = 0; my $added = 0; - print " opening index $index_node_url"; if ($index_node_url) { + print " opening index $index_node_url"; $hest_node ||= Search::Estraier::Node->new( url => $index_node_url, user => 'admin', @@ -135,8 +135,6 @@ 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; @@ -199,7 +197,7 @@ while (my $row = $sth->fetchrow_hashref()) { my $uri = $row->{hname} . ':' . $row->{sname} . '#' . $row->{backupnum} . ' ' . $row->{filepath}; - unless ($skip_check) { + unless ($skip_check && $hest_node) { my $id = $hest_node->uri_to_id($uri); next if ($id && $id == -1); } @@ -304,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) ); @@ -384,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";