--- trunk/bin/BackupPC_updatedb 2005/08/26 23:50:05 80 +++ trunk/bin/BackupPC_updatedb 2005/08/28 08:40:06 81 @@ -45,19 +45,112 @@ my %opt; -if ( !getopts("cdm:v:", \%opt ) ) { +if ( !getopts("cdm:v:i", \%opt ) ) { print STDERR <new(); + $db->open($index_dir, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT); + + my $sth = $dbh->prepare(qq{ + SELECT + files.id AS fid, + hosts.name AS hname, + shares.name AS sname, + shares.share AS sharename, + files.backupNum AS backupNum, + files.name AS filename, + files.path AS filepath, + files.date AS date, + files.type AS filetype, + files.size AS size, + files.shareid AS shareid + FROM files + INNER JOIN shares ON files.shareID=shares.ID + INNER JOIN hosts ON hosts.ID = shares.hostID + INNER JOIN backups ON backups.num = files.backupNum and backups.hostID = hosts.ID AND backups.shareID = shares.ID + }); + + $sth->execute(); + + my $dot = int($sth->rows / 15); + + print $sth->rows, " files ($dot/#) "; + + sub fmt_date { + my $t = shift || return; + my $iso = BackupPC::Lib::timeStamp($t); + $iso =~ s/\s/T/; + return $iso; + } + + my $i = 0; + my $max = int($sth->rows / $dot); + + while (my $row = $sth->fetchrow_hashref()) { + + # create a document object + my $doc = HyperEstraier::Document->new; + + # add attributes to the document object + $doc->add_attr('@uri', 'file:///' . $row->{'fid'}); + + foreach my $c (qw/fid hname sname sharename backupNum filename filepath shareid/) { + $doc->add_attr($c, $row->{$c}) if ($row->{$c}); + } + + $doc->add_attr('date', fmt_date($row->{'date'})); + + # add the body text to the document object + my $path = $row->{'filepath'}; + $doc->add_text($path); + $path =~ s/(.)/$1 /g; + $doc->add_hidden_text($path); + + print STDERR $doc->dump_draft,"\n" if ($debug > 1); + + # register the document object to the database + $db->put_doc($doc, $HyperEstraier::Database::PDCLEAN); + + $i++; + if ($i % $dot == 0) { + print "$max "; + $max--; + } + + } + + print "sync"; + $db->sync(); + print " close\n"; + $db->close(); + + exit; +} + ###################################create tables############################3 if ($opt{c}) { @@ -160,11 +253,6 @@ $dbh->commit; } -if ($opt{v}) { - print "Debug level at $opt{v}\n"; - $debug = $opt{v}; -} - #################################INSERT VALUES############################# # get hosts