15 |
use Cwd qw/abs_path/; |
use Cwd qw/abs_path/; |
16 |
|
|
17 |
use constant BPC_FTYPE_DIR => 5; |
use constant BPC_FTYPE_DIR => 5; |
18 |
use constant EST_CHUNK => 100000; |
use constant EST_CHUNK => 4096; |
19 |
|
|
20 |
# daylight saving time change offset for 1h |
# daylight saving time change offset for 1h |
21 |
my $dst_offset = 60 * 60; |
my $dst_offset = 60 * 60; |
58 |
|
|
59 |
my %opt; |
my %opt; |
60 |
|
|
61 |
if ( !getopts("cdm:v:ijf", \%opt ) ) { |
if ( !getopts("cdm:v:ijfq", \%opt ) ) { |
62 |
print STDERR <<EOF; |
print STDERR <<EOF; |
63 |
usage: $0 [-c|-d] [-m num] [-v|-v level] [-i|-j|-f] |
usage: $0 [-c|-d] [-m num] [-v|-v level] [-i|-j|-f] |
64 |
|
|
70 |
-i update Hyper Estraier full text index |
-i update Hyper Estraier full text index |
71 |
-j update full text, don't check existing files |
-j update full text, don't check existing files |
72 |
-f don't do anything with full text index |
-f don't do anything with full text index |
73 |
|
-q be quiet for hosts without changes |
74 |
|
|
75 |
Option -j is variation on -i. It will allow faster initial creation |
Option -j is variation on -i. It will allow faster initial creation |
76 |
of full-text index from existing database. |
of full-text index from existing database. |
105 |
return strftime($t_fmt,localtime()); |
return strftime($t_fmt,localtime()); |
106 |
} |
} |
107 |
|
|
|
my $hest_db; |
|
108 |
my $hest_node; |
my $hest_node; |
109 |
|
|
|
sub signal { |
|
|
my($sig) = @_; |
|
|
if ($hest_db) { |
|
|
print "\nCaught a SIG$sig--syncing database and shutting down\n"; |
|
|
$hest_db->sync(); |
|
|
$hest_db->close(); |
|
|
} |
|
|
exit(0); |
|
|
} |
|
|
|
|
|
$SIG{'INT'} = \&signal; |
|
|
$SIG{'QUIT'} = \&signal; |
|
|
|
|
110 |
sub hest_update { |
sub hest_update { |
111 |
|
|
112 |
my ($host_id, $share_id, $num) = @_; |
my ($host_id, $share_id, $num) = @_; |
128 |
|
|
129 |
print " opening index $index_node_url"; |
print " opening index $index_node_url"; |
130 |
if ($index_node_url) { |
if ($index_node_url) { |
131 |
$hest_node ||= Search::Estraier::Node->new($index_node_url); |
$hest_node ||= Search::Estraier::Node->new( |
132 |
$hest_node->set_auth('admin', 'admin'); |
url => $index_node_url, |
133 |
|
user => 'admin', |
134 |
|
passwd => 'admin', |
135 |
|
croak_on_error => 1, |
136 |
|
); |
137 |
print " via node URL"; |
print " via node URL"; |
138 |
} else { |
} else { |
139 |
die "don't know how to use Hyper Estraier Index $index_node_url"; |
die "don't know how to use Hyper Estraier Index $index_node_url"; |
184 |
|
|
185 |
if ($results == 0) { |
if ($results == 0) { |
186 |
print " - no new files\n"; |
print " - no new files\n"; |
187 |
last; |
return; |
188 |
} else { |
} else { |
189 |
print " - $results files: "; |
print " - $results files: "; |
190 |
} |
} |
198 |
|
|
199 |
while (my $row = $sth->fetchrow_hashref()) { |
while (my $row = $sth->fetchrow_hashref()) { |
200 |
|
|
201 |
my $fid = $row->{'fid'} || die "no fid?"; |
my $uri = $row->{hname} . ':' . $row->{sname} . '#' . $row->{backupnum} . ' ' . $row->{filepath}; |
|
my $uri = 'file:///' . $fid; |
|
|
|
|
202 |
unless ($skip_check) { |
unless ($skip_check) { |
203 |
my $id = ($hest_db || $hest_node)->uri_to_id($uri); |
my $id = $hest_node->uri_to_id($uri); |
204 |
next unless ($id == -1); |
next if ($id && $id == -1); |
205 |
} |
} |
206 |
|
|
207 |
# create a document object |
# create a document object |
211 |
$doc->add_attr('@uri', $uri); |
$doc->add_attr('@uri', $uri); |
212 |
|
|
213 |
foreach my $c (@{ $sth->{NAME} }) { |
foreach my $c (@{ $sth->{NAME} }) { |
214 |
|
print STDERR "attr $c = $row->{$c}\n" if ($debug > 2); |
215 |
$doc->add_attr($c, $row->{$c}) if (defined($row->{$c})); |
$doc->add_attr($c, $row->{$c}) if (defined($row->{$c})); |
216 |
} |
} |
217 |
|
|
461 |
} |
} |
462 |
|
|
463 |
$host_nr++; |
$host_nr++; |
|
print "host ", $hosts->{$host_key}->{'host'}, " [", |
|
|
$host_nr, "/", ($#hosts + 1), "]: "; |
|
|
|
|
464 |
# get backups for a host |
# get backups for a host |
465 |
my @backups = $bpc->BackupInfoRead($hostname); |
my @backups = $bpc->BackupInfoRead($hostname); |
466 |
my $incs = scalar @backups; |
my $incs = scalar @backups; |
|
print "$incs increments\n"; |
|
467 |
|
|
468 |
|
my $host_header = sprintf("host %s [%d/%d]: %d increments\n", |
469 |
|
$hosts->{$host_key}->{'host'}, |
470 |
|
$host_nr, |
471 |
|
($#hosts + 1), |
472 |
|
$incs |
473 |
|
); |
474 |
|
print $host_header unless ($opt{q}); |
475 |
|
|
476 |
my $inc_nr = 0; |
my $inc_nr = 0; |
477 |
$beenThere = {}; |
$beenThere = {}; |
478 |
|
|
484 |
my $backupNum = $backup->{'num'}; |
my $backupNum = $backup->{'num'}; |
485 |
my @backupShares = (); |
my @backupShares = (); |
486 |
|
|
487 |
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", |
488 |
$hosts->{$host_key}->{'host'}, |
$hosts->{$host_key}->{'host'}, |
489 |
$inc_nr, $incs, $backupNum, |
$inc_nr, $incs, $backupNum, |
490 |
$backup->{type} || '?', |
$backup->{type} || '?', |
492 |
strftime($t_fmt,localtime($backup->{startTime})), |
strftime($t_fmt,localtime($backup->{startTime})), |
493 |
fmt_time($backup->{endTime} - $backup->{startTime}) |
fmt_time($backup->{endTime} - $backup->{startTime}) |
494 |
); |
); |
495 |
|
print $share_header unless ($opt{q}); |
496 |
|
|
497 |
my $files = BackupPC::View->new($bpc, $hostname, \@backups, 1); |
my $files = BackupPC::View->new($bpc, $hostname, \@backups, 1); |
498 |
foreach my $share ($files->shareList($backupNum)) { |
foreach my $share ($files->shareList($backupNum)) { |
506 |
# skip if allready in database! |
# skip if allready in database! |
507 |
next if ($count > 0); |
next if ($count > 0); |
508 |
|
|
509 |
|
# dump host and share header for -q |
510 |
|
if ($opt{q}) { |
511 |
|
if ($host_header) { |
512 |
|
print $host_header; |
513 |
|
$host_header = undef; |
514 |
|
} |
515 |
|
print $share_header; |
516 |
|
} |
517 |
|
|
518 |
# dump some log |
# dump some log |
519 |
print curr_time," ", $share; |
print curr_time," ", $share; |
520 |
|
|