--- trunk/bin/BackupPC_updatedb 2005/08/28 10:45:51 85 +++ trunk/bin/BackupPC_updatedb 2005/08/28 12:35:59 86 @@ -65,24 +65,44 @@ $debug = $opt{v}; } +#---- subs ---- + +sub fmt_time { + my $t = shift || return; + my $out = ""; + my ($ss,$mm,$hh) = gmtime($t); + $out .= "${hh}h" if ($hh); + $out .= sprintf("%02d:%02d", $mm,$ss); + return $out; +} + +sub curr_time { + return strftime($t_fmt,localtime()); +} + +#---- /subs ---- + ## update index ## if ($opt{i}) { - print "updating HyperEstraier files "; + print curr_time," updating HyperEstraier: files"; + + my $t = time(); 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, + -- 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 + files.shareid AS shareid, + backups.date AS backup_date FROM files INNER JOIN shares ON files.shareID=shares.ID INNER JOIN hosts ON hosts.ID = shares.hostID @@ -90,10 +110,11 @@ }); $sth->execute(); + my $results = $sth->rows; - my $dot = int($sth->rows / 15); + my $dot = int($results / 15); - print $sth->rows, " files ($dot/#) "; + print " $results ($dot/#)"; sub fmt_date { my $t = shift || return; @@ -103,12 +124,12 @@ } my $i = 0; - my $max = int($sth->rows / $dot); + my $max = int($results / $dot); $index_path = $TopDir . '/' . $index_path; $index_path =~ s#//#/#g; - print "index $index_path..."; + print " index $index_path..."; use HyperEstraier; my $db = HyperEstraier::Database->new(); $db->open($index_path, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT); @@ -122,11 +143,11 @@ # 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/) { + foreach my $c (@{ $sth->{NAME} }) { $doc->add_attr($c, $row->{$c}) if ($row->{$c}); } - $doc->add_attr('date', fmt_date($row->{'date'})); + #$doc->add_attr('@cdate', fmt_date($row->{'date'})); # add the body text to the document object my $path = $row->{'filepath'}; @@ -149,9 +170,15 @@ print "sync"; $db->sync(); - print " close\n"; + print " close"; $db->close(); + my $dur = (time() - $t) || 1; + printf(" [%.2f/s dur: %s]\n", + ( $results / $dur ), + fmt_time($dur) + ); + exit; } @@ -291,15 +318,6 @@ VALUES (?,?,?,?,?,?,?) }); -sub fmt_time { - my $t = shift || return; - my $out = ""; - my ($ss,$mm,$hh) = gmtime($t); - $out .= "${hh}h" if ($hh); - $out .= sprintf("%02d:%02d", $mm,$ss); - return $out; -} - foreach my $host_key (keys %{$hosts}) { my $hostname = $hosts->{$host_key}->{'host'} || die "can't find host for $host_key"; @@ -355,7 +373,7 @@ next if ($count > 0); # dump some log - print strftime($t_fmt,localtime())," ", $share; + print curr_time," ", $share; my ($f, $nf, $d, $nd, $size) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);