11 |
use Time::HiRes qw/time/; |
use Time::HiRes qw/time/; |
12 |
use File::Pid; |
use File::Pid; |
13 |
use POSIX qw/strftime/; |
use POSIX qw/strftime/; |
14 |
|
use BackupPC::SearchLib; |
15 |
|
|
16 |
use constant BPC_FTYPE_DIR => 5; |
use constant BPC_FTYPE_DIR => 5; |
17 |
use constant EST_CHUNK => 100000; |
use constant EST_CHUNK => 100000; |
42 |
|
|
43 |
my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n"; |
my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n"; |
44 |
my $user = $Conf{SearchUser} || ''; |
my $user = $Conf{SearchUser} || ''; |
|
my $index_path = $Conf{HyperEstraierIndex}; |
|
|
$index_path = $TopDir . '/' . $index_path; |
|
|
$index_path =~ s#//#/#g; |
|
|
if ($index_path) { |
|
|
use HyperEstraier; |
|
|
} |
|
45 |
|
|
46 |
|
my $use_hest = $Conf{HyperEstraierIndex}; |
47 |
|
my ($index_path, $index_node_url) = BackupPC::SearchLib::getHyperEstraier_url($use_hest); |
48 |
|
|
49 |
my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 }); |
my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 }); |
50 |
|
|
85 |
} |
} |
86 |
|
|
87 |
my $hest_db; |
my $hest_db; |
88 |
|
my $hest_node; |
89 |
|
|
90 |
sub signal { |
sub signal { |
91 |
my($sig) = @_; |
my($sig) = @_; |
104 |
|
|
105 |
my ($host_id, $share_id, $num) = @_; |
my ($host_id, $share_id, $num) = @_; |
106 |
|
|
107 |
|
unless ($use_hest) { |
108 |
|
print STDERR "HyperEstraier support not enabled in configuration\n"; |
109 |
|
return; |
110 |
|
} |
111 |
|
|
112 |
print curr_time," updating HyperEstraier:"; |
print curr_time," updating HyperEstraier:"; |
113 |
|
|
114 |
my $t = time(); |
my $t = time(); |
116 |
my $offset = 0; |
my $offset = 0; |
117 |
my $added = 0; |
my $added = 0; |
118 |
|
|
119 |
print " opening index $index_path"; |
print " opening index"; |
120 |
$hest_db = HyperEstraier::Database->new(); |
if ($index_path) { |
121 |
$hest_db->open($index_path, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT); |
$hest_db = HyperEstraier::Database->new(); |
122 |
|
$hest_db->open($TopDir . $index_path, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT); |
123 |
print " increment is " . EST_CHUNK . " files"; |
print "$index_path directly"; |
124 |
|
} elsif ($index_node_url) { |
125 |
|
$hest_node ||= HyperEstraier::Node->new($index_node_url); |
126 |
|
$hest_node->set_auth('admin', 'admin'); |
127 |
|
print "$index_node_url via node URL"; |
128 |
|
} else { |
129 |
|
die "don't know how to use HyperEstraier Index $use_hest"; |
130 |
|
} |
131 |
|
print " increment is " . EST_CHUNK . " files:"; |
132 |
|
|
133 |
my $results = 0; |
my $results = 0; |
134 |
|
|
135 |
do { |
do { |
136 |
|
|
137 |
my $where = ''; |
my $where = ''; |
138 |
|
my @data; |
139 |
if ($host_id && $share_id && $num) { |
if ($host_id && $share_id && $num) { |
140 |
$where = qq{ |
$where = qq{ |
141 |
WHERE |
WHERE |
143 |
shares.id = ? AND |
shares.id = ? AND |
144 |
files.backupnum = ? |
files.backupnum = ? |
145 |
}; |
}; |
146 |
|
@data = ( $host_id, $share_id, $num ); |
147 |
} |
} |
148 |
|
|
149 |
my $limit = sprintf('LIMIT '.EST_CHUNK.' OFFSET %d', $offset); |
my $limit = sprintf('LIMIT '.EST_CHUNK.' OFFSET %d', $offset); |
170 |
$limit |
$limit |
171 |
}); |
}); |
172 |
|
|
173 |
$sth->execute(@_); |
$sth->execute(@data); |
174 |
$results = $sth->rows; |
$results = $sth->rows; |
175 |
|
|
176 |
if ($results == 0) { |
if ($results == 0) { |
177 |
print " - no more files\n"; |
print " - no new files\n"; |
178 |
last; |
last; |
179 |
} |
} |
180 |
|
|
190 |
my $fid = $row->{'fid'} || die "no fid?"; |
my $fid = $row->{'fid'} || die "no fid?"; |
191 |
my $uri = 'file:///' . $fid; |
my $uri = 'file:///' . $fid; |
192 |
|
|
193 |
my $id = $hest_db->uri_to_id($uri); |
my $id = ($hest_db || $hest_node)->uri_to_id($uri); |
194 |
next unless ($id == -1); |
next unless ($id == -1); |
195 |
|
|
196 |
# create a document object |
# create a document object |
214 |
print STDERR $doc->dump_draft,"\n" if ($debug > 1); |
print STDERR $doc->dump_draft,"\n" if ($debug > 1); |
215 |
|
|
216 |
# register the document object to the database |
# register the document object to the database |
217 |
$hest_db->put_doc($doc, $HyperEstraier::Database::PDCLEAN); |
if ($hest_db) { |
218 |
|
$hest_db->put_doc($doc, $HyperEstraier::Database::PDCLEAN); |
219 |
|
} elsif ($hest_node) { |
220 |
|
$hest_node->put_doc($doc); |
221 |
|
} else { |
222 |
|
die "not supported"; |
223 |
|
} |
224 |
$added++; |
$added++; |
225 |
} |
} |
226 |
|
|
227 |
print " $added"; |
print " $added"; |
228 |
$hest_db->sync(); |
$hest_db->sync() if ($index_path); |
229 |
|
|
230 |
$offset += EST_CHUNK; |
$offset += EST_CHUNK; |
231 |
|
|
232 |
} while ($results == EST_CHUNK); |
} while ($results == EST_CHUNK); |
233 |
|
|
234 |
print ", close"; |
if ($index_path) { |
235 |
$hest_db->close(); |
print ", close"; |
236 |
|
$hest_db->close(); |
237 |
|
} |
238 |
|
|
239 |
my $dur = (time() - $t) || 1; |
my $dur = (time() - $t) || 1; |
240 |
printf(" [%.2f/s dur: %s]\n", |
printf(" [%.2f/s dur: %s]\n", |
471 |
fmt_time($dur) |
fmt_time($dur) |
472 |
); |
); |
473 |
|
|
474 |
hest_update($hostID, $shareID, $backupNum); |
hest_update($hostID, $shareID, $backupNum) if ($nf + $nd > 0); |
475 |
} |
} |
476 |
|
|
477 |
} |
} |