15 |
my $dsn = $Conf{SearchDSN}; |
my $dsn = $Conf{SearchDSN}; |
16 |
my $db_user = $Conf{SearchUser} || ''; |
my $db_user = $Conf{SearchUser} || ''; |
17 |
|
|
18 |
my $index_path = $Conf{HyperEstraierIndex}; |
my $hest_index_path = $Conf{HyperEstraierIndex}; |
|
if ($index_path) { |
|
|
$index_path = $TopDir . '/' . $index_path; |
|
|
$index_path =~ s#//#/#g; |
|
|
} |
|
19 |
|
|
20 |
my $dbh; |
my $dbh; |
21 |
|
|
171 |
return ($results, \@ret); |
return ($results, \@ret); |
172 |
} |
} |
173 |
|
|
174 |
|
sub getHyperEstraier_url($) { |
175 |
|
my ($use_hest) = @_; |
176 |
|
|
177 |
|
return unless $use_hest; |
178 |
|
|
179 |
|
use HyperEstraier; |
180 |
|
my ($index_path, $index_node_url); |
181 |
|
|
182 |
|
if ($use_hest =~ m#^http://#) { |
183 |
|
$index_node_url = $use_hest; |
184 |
|
} else { |
185 |
|
$index_path = $TopDir . '/' . $index_path; |
186 |
|
$index_path =~ s#//#/#g; |
187 |
|
} |
188 |
|
return ($index_path, $index_node_url); |
189 |
|
} |
190 |
|
|
191 |
sub getFilesHyperEstraier($) { |
sub getFilesHyperEstraier($) { |
192 |
my ($param) = @_; |
my ($param) = @_; |
193 |
|
|
194 |
my $offset = $param->{'offset'} || 0; |
my $offset = $param->{'offset'} || 0; |
195 |
$offset *= $on_page; |
$offset *= $on_page; |
196 |
|
|
197 |
die "no index_path?" unless ($index_path); |
die "no index_path?" unless ($hest_index_path); |
198 |
|
|
199 |
use HyperEstraier; |
use HyperEstraier; |
200 |
|
|
201 |
|
my ($index_path, $index_node_url) = getHyperEstraier_url($hest_index_path); |
202 |
|
|
203 |
# open the database |
# open the database |
204 |
my $db = HyperEstraier::Database->new(); |
my $db; |
205 |
$db->open($index_path, $HyperEstraier::ESTDBREADER); |
if ($index_path) { |
206 |
|
$db = HyperEstraier::Database->new(); |
207 |
|
$db->open($index_path, $HyperEstraier::ESTDBREADER); |
208 |
|
} elsif ($index_node_url) { |
209 |
|
$db ||= HyperEstraier::Node->new($index_node_url); |
210 |
|
$db->set_auth('admin', 'admin'); |
211 |
|
} else { |
212 |
|
die "BUG: unimplemented"; |
213 |
|
} |
214 |
|
|
215 |
# create a search condition object |
# create a search condition object |
216 |
my $cond = HyperEstraier::Condition->new(); |
my $cond = HyperEstraier::Condition->new(); |
218 |
my $q = $param->{'search_filename'}; |
my $q = $param->{'search_filename'}; |
219 |
my $shareid = $param->{'search_share'}; |
my $shareid = $param->{'search_share'}; |
220 |
|
|
221 |
if ($q) { |
if (length($q) > 0) { |
222 |
$q =~ s/(.)/$1 /g; |
# exact match |
223 |
|
$cond->add_attr("filepath ISTRINC $q"); |
224 |
|
|
225 |
|
$q =~ s/(.)/$1 /g; |
226 |
# set the search phrase to the search condition object |
# set the search phrase to the search condition object |
227 |
$cond->set_phrase($q); |
$cond->set_phrase($q); |
228 |
} |
} |
242 |
$cond->set_order( 'date NUMA' ); |
$cond->set_order( 'date NUMA' ); |
243 |
|
|
244 |
# get the result of search |
# get the result of search |
|
my $result = $db->search($cond, 0); |
|
|
|
|
245 |
my @res; |
my @res; |
246 |
my $hits = $result->size; |
my ($result, $hits); |
247 |
|
|
248 |
|
if ($index_path) { |
249 |
|
$result = $db->search($cond, 0); |
250 |
|
$hits = $result->size; |
251 |
|
} elsif ($index_node_url) { |
252 |
|
$result = $db->search($cond, 0); |
253 |
|
$hits = $result->doc_num; |
254 |
|
} else { |
255 |
|
die "BUG: unimplemented"; |
256 |
|
} |
257 |
|
|
258 |
# for each document in result |
# for each document in result |
259 |
for my $i ($offset .. ($offset + $on_page - 1)) { |
for my $i ($offset .. ($offset + $on_page - 1)) { |
260 |
last if ($i >= $hits); |
last if ($i >= $hits); |
261 |
|
|
262 |
my $id = $result->get($i); |
my $doc; |
263 |
my $doc = $db->get_doc($id, 0); |
if ($index_path) { |
264 |
|
my $id = $result->get($i); |
265 |
|
$doc = $db->get_doc($id, 0); |
266 |
|
} elsif ($index_node_url) { |
267 |
|
$doc = $result->get_doc($i); |
268 |
|
} else { |
269 |
|
die "BUG: unimplemented"; |
270 |
|
} |
271 |
|
|
272 |
my $row; |
my $row; |
273 |
foreach my $c (qw/fid hname sname backupnum fiilename filepath date type size/) { |
foreach my $c (qw/fid hname sname backupnum fiilename filepath date type size/) { |
279 |
return ($hits, \@res); |
return ($hits, \@res); |
280 |
} |
} |
281 |
|
|
282 |
|
sub getGzipName($$$) |
283 |
|
{ |
284 |
|
my ($host, $share, $backupnum) = @_; |
285 |
|
my $ret = $Conf{GzipSchema}; |
286 |
|
|
287 |
|
$share =~ s/\//_/g; |
288 |
|
$ret =~ s/\\h/$host/ge; |
289 |
|
$ret =~ s/\\s/$share/ge; |
290 |
|
$ret =~ s/\\n/$backupnum/ge; |
291 |
|
|
292 |
|
return $ret; |
293 |
|
|
294 |
|
} |
295 |
|
|
296 |
sub getBackupsNotBurned() { |
sub getBackupsNotBurned() { |
297 |
|
|
298 |
my $dbh = get_dbh(); |
my $dbh = get_dbh(); |
299 |
my $sql = q{ |
|
300 |
SELECT |
my $sql = q{ |
301 |
backups.hostID AS hostid, |
SELECT |
302 |
min(hosts.name) AS host, |
backups.hostID AS hostID, |
303 |
backups.num AS backupnum, |
hosts.name AS host, |
304 |
min(backups.type) AS type, |
shares.name AS share, |
305 |
min(backups.date) AS date, |
backups.id AS backupnum, |
306 |
min(backups.size) AS size |
backups.type AS type, |
307 |
FROM files |
backups.date AS date, |
308 |
INNER JOIN shares ON files.shareID=shares.ID |
backups.size AS size |
309 |
INNER JOIN hosts ON hosts.ID = shares.hostID |
FROM backups |
310 |
INNER JOIN backups ON backups.num = files.backupnum and backups.hostID = hosts.ID AND backups.shareID = shares.ID |
INNER JOIN shares ON backups.shareID=shares.ID |
311 |
GROUP BY |
INNER JOIN hosts ON backups.hostID = hosts.ID |
312 |
backups.hostID, backups.num |
LEFT OUTER JOIN archive_backup ON archive_backup.backup_id = backups.id AND archive_backup.backup_id IS NULL |
313 |
ORDER BY min(backups.date) |
WHERE backups.size > 0 |
314 |
|
GROUP BY |
315 |
|
backups.hostID, |
316 |
|
hosts.name, |
317 |
|
shares.name, |
318 |
|
backups.num, |
319 |
|
backups.shareid, |
320 |
|
backups.id, |
321 |
|
backups.type, |
322 |
|
backups.date, |
323 |
|
backups.size |
324 |
|
ORDER BY backups.date |
325 |
}; |
}; |
326 |
my $sth = $dbh->prepare( $sql ); |
my $sth = $dbh->prepare( $sql ); |
327 |
my @ret; |
my @ret; |
330 |
while ( my $row = $sth->fetchrow_hashref() ) { |
while ( my $row = $sth->fetchrow_hashref() ) { |
331 |
$row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) ); |
$row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) ); |
332 |
$row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024); |
$row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024); |
333 |
|
my (undef,undef,undef,undef,undef,undef,undef,$fs_size,undef,undef,undef,undef,undef) = |
334 |
|
stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'. |
335 |
|
getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'})); |
336 |
|
$row->{'fs_size'} = $fs_size; |
337 |
push @ret, $row; |
push @ret, $row; |
338 |
} |
} |
339 |
|
|
343 |
sub displayBackupsGrid() |
sub displayBackupsGrid() |
344 |
{ |
{ |
345 |
my $retHTML = ""; |
my $retHTML = ""; |
|
my $addForm = 1; |
|
346 |
|
|
347 |
if ($addForm) { |
$retHTML .= <<EOF3; |
|
|
|
|
$retHTML .= <<EOF3; |
|
348 |
<script language="javascript" type="text/javascript"> |
<script language="javascript" type="text/javascript"> |
349 |
<!-- |
<!-- |
350 |
|
|
362 |
} |
} |
363 |
} |
} |
364 |
} |
} |
365 |
|
|
366 |
|
function sumiraj() |
367 |
|
{ |
368 |
|
var suma = 0; |
369 |
|
for (var i = 0; i < document.forma.elements.length; i++) |
370 |
|
{ |
371 |
|
var e = document.forma.elements[i]; |
372 |
|
if ((e.checked || !e.checked) && e.name != \'all\') |
373 |
|
{ |
374 |
|
if (e.checked) |
375 |
|
{ |
376 |
|
var ret = e.name.match("fcb(.*)"); |
377 |
|
suma += parseInt(eval("document.forma.fss"+ret[1]+".value") || 0); |
378 |
|
|
379 |
|
} |
380 |
|
} |
381 |
|
} |
382 |
|
document.forma.totalsize.value = suma; |
383 |
|
return suma; |
384 |
|
} |
385 |
//--> |
//--> |
386 |
</script> |
</script> |
387 |
EOF3 |
EOF3 |
388 |
$retHTML .= q{<form name="forma" method="GET" action="}."$MyURL"."?action=burn\""; |
$retHTML .= q{ |
389 |
$retHTML.= q{<input type="hidden" value="burn" name="action">}; |
<form name="forma" method="GET" action=}; |
390 |
$retHTML .= q{<input type="hidden" value="results" name="search_results">}; |
$retHTML .= "\"".$MyURL."\""; |
391 |
} |
$retHTML .= q{?action=burn> |
392 |
$retHTML .= qq{ |
<input type="hidden" value="burn" name="action"> |
393 |
<table style="fview" border="1" cellspacing="0" cellpadding="3"> |
<input type="hidden" value="results" name="search_results"> |
394 |
<tr class="tableheader"> |
<table style="fview" border="0" cellspacing="0" cellpadding="2"> |
395 |
}; |
<tr class="tableheader"> |
396 |
|
<td class="tableheader"> |
397 |
|
<input type="checkbox" name="allFiles" onClick="checkAll('allFiles');"> |
398 |
|
</td> |
399 |
|
<td align="center">Share</td> |
400 |
|
<td align="center">Backup no</td> |
401 |
|
<td align="center">Type</td> |
402 |
|
<td align="center">date</td> |
403 |
|
<td align="center">age/days</td> |
404 |
|
<td align="center">size/MB</td> |
405 |
|
<td align="center">gzip size</td> |
406 |
|
</tr> |
407 |
|
|
|
if ($addForm) { |
|
|
$retHTML .= "<td class=\"tableheader\"><input type=\"checkbox\" name=\"allFiles\" onClick=\"checkAll('allFiles');\"></td>"; |
|
|
} |
|
|
$retHTML .= qq{ |
|
|
<td align="center">Host</td> |
|
|
<td align="center">Backup no</td> |
|
|
<td align="center">Type</td> |
|
|
<td align="center">date</td> |
|
|
<td align="center">age/days</td> |
|
|
<td align="center">size/MB</td> |
|
|
</tr> |
|
|
}; |
|
|
|
|
|
my @backups = getBackupsNotBurned(); |
|
|
my $backup; |
|
|
|
|
|
if ($addForm) { |
|
|
$retHTML .= qq{ |
|
408 |
<tr><td colspan=7 style="tableheader"> |
<tr><td colspan=7 style="tableheader"> |
409 |
<input type="submit" value="Burn selected backups on medium" name="submitBurner"> |
<input type="submit" value="Burn selected backups on medium" name="submitBurner"> |
410 |
</td></tr> |
</td></tr> |
411 |
}; |
}; |
|
} |
|
412 |
|
|
413 |
foreach $backup(@backups) { |
my @color = (' bgcolor="#e0e0e0"', ''); |
414 |
|
|
415 |
|
my $i = 0; |
416 |
|
my $host = ''; |
417 |
|
|
418 |
|
foreach my $backup ( getBackupsNotBurned() ) { |
419 |
|
|
420 |
|
if ($host ne $backup->{'host'}) { |
421 |
|
$i++; |
422 |
|
$host = $backup->{'host'}; |
423 |
|
} |
424 |
my $ftype = ""; |
my $ftype = ""; |
425 |
|
|
426 |
$retHTML .= "<tr>"; |
$retHTML .= "<tr" . $color[$i %2 ] . ">"; |
427 |
if ($addForm) { |
$retHTML .= '<td class="fview"><input type="checkbox" name="fcb' . |
428 |
$retHTML .= '<td class="fview"><input type="checkbox" name="fcb' . |
$backup->{'hostid'}.'_'.$backup->{'backupnum'} . |
429 |
$backup->{'hostid'}.'_'.$backup->{'backupnum'} . |
'" value="' . $backup->{'hostid'}.'_'.$backup->{'backupnum'} . |
430 |
'" value="' . $backup->{'hostid'}.'_'.$backup->{'backupnum'} . |
'" onClick="sumiraj();"></td>'; |
|
'"></td>'; |
|
|
} |
|
431 |
|
|
432 |
$retHTML .= '<td class="fviewborder">' . $backup->{'host'} . '</td>' . |
$retHTML .= |
433 |
'<td class="fviewborder">' . $backup->{'backupnum'} . '</td>' . |
'<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' . |
434 |
'<td class="fviewborder">' . $backup->{'type'} . '</td>' . |
'<td align="center">' . $backup->{'backupnum'} . '</td>' . |
435 |
'<td class="fviewborder">' . epoch_to_iso( $backup->{'date'} ) . '</td>' . |
'<td align="center">' . $backup->{'type'} . '</td>' . |
436 |
'<td class="fviewborder">' . $backup->{'age'} . '</td>' . |
'<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' . |
437 |
'<td class="fviewborder">' . $backup->{'size'} . '</td>' . |
'<td align="center">' . $backup->{'age'} . '</td>' . |
438 |
'</tr>'; |
'<td align="right">' . $backup->{'size'} . '</td>' . |
439 |
} |
'<td align="right">' . $backup->{'fs_size'} . |
440 |
|
'<input type="hidden" name="fss'.$backup->{'hostid'}.'_'.$backup->{'backupnum'} . '"'. |
441 |
|
'value="'. $backup->{'fs_size'} .'"'.'</td>' . |
442 |
|
"</tr>\n"; |
443 |
|
|
|
$retHTML .= "</table>"; |
|
444 |
|
|
|
if ($addForm) { |
|
|
$retHTML .= "</form>"; |
|
445 |
} |
} |
446 |
|
|
447 |
|
$retHTML .= "</table>"; |
448 |
|
$retHTML .= "total gzip size:<input type=\"text\" name=\"totalsize\"><br>"; |
449 |
|
$retHTML .= "Note:<input type=\"text\" name=\"note\">"; |
450 |
|
$retHTML .= "</form>"; |
451 |
|
|
452 |
return $retHTML; |
return $retHTML; |
453 |
} |
} |
463 |
my $start_t = time(); |
my $start_t = time(); |
464 |
|
|
465 |
my ($results, $files); |
my ($results, $files); |
466 |
if ($param->{'use_hest'}) { |
if ($param->{'use_hest'} && length($hilite) > 0) { |
467 |
($results, $files) = getFilesHyperEstraier($param); |
($results, $files) = getFilesHyperEstraier($param); |
468 |
} else { |
} else { |
469 |
($results, $files) = getFiles($param); |
($results, $files) = getFiles($param); |
525 |
my $typeStr = BackupPC::Attrib::fileType2Text(undef, $file->{'type'}); |
my $typeStr = BackupPC::Attrib::fileType2Text(undef, $file->{'type'}); |
526 |
$retHTML .= qq{<tr class="fviewborder">}; |
$retHTML .= qq{<tr class="fviewborder">}; |
527 |
|
|
528 |
$retHTML .= qq{<td>$i</td>}; |
$retHTML .= qq{<td class="fviewborder">$i</td>}; |
529 |
|
|
530 |
$retHTML .= |
$retHTML .= |
531 |
qq{<td class="fviewborder" align="right">} . $file->{'hname'} . ':' . $file->{'sname'} . qq{</td>} . |
qq{<td class="fviewborder" align="right">} . $file->{'hname'} . ':' . $file->{'sname'} . qq{</td>} . |