X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=lib%2FBackupPC%2FSearchLib.pm;h=cea2c85255a8d74241abfb6f9f9630fee693cae8;hb=feb2b4f953e2174663a3de57c07b5fff6e29718d;hp=e9d3065cb86204cc742428d09b453e48056537bf;hpb=c98af2af72138c59febd2bfcfc48cdef4cb74408;p=BackupPC.git diff --git a/lib/BackupPC/SearchLib.pm b/lib/BackupPC/SearchLib.pm index e9d3065..cea2c85 100644 --- a/lib/BackupPC/SearchLib.pm +++ b/lib/BackupPC/SearchLib.pm @@ -17,7 +17,7 @@ my $pager_pages = 10; my $dsn = $Conf{SearchDSN}; my $db_user = $Conf{SearchUser} || ''; -my $hest_index_path = $Conf{HyperEstraierIndex}; +my $hest_node_url = $Conf{HyperEstraierIndex}; my $dbh; @@ -150,8 +150,8 @@ my $sort_def = { }, burn => { default => 'date_a', sql => { - share_d => 'share DESC', - share_a => 'share ASC', + share_d => 'host DESC, share DESC', + share_a => 'host ASC, share ASC', num_d => 'backupnum DESC', num_a => 'backupnum ASC', date_d => 'date DESC', @@ -251,16 +251,11 @@ sub getHyperEstraier_url($) { return unless $use_hest; - use HyperEstraier; - my ($index_path, $index_node_url); + use Search::Estraier 0.04; + die "direct access to Hyper Estraier datatase is no longer supported. Please use estmaster\n" + unless ($use_hest =~ m#^http://#); - if ($use_hest =~ m#^http://#) { - $index_node_url = $use_hest; - } else { - $index_path = $TopDir . '/' . $index_path; - $index_path =~ s#//#/#g; - } - return ($index_path, $index_node_url); + return $use_hest; } sub getFilesHyperEstraier($) { @@ -269,26 +264,19 @@ sub getFilesHyperEstraier($) { my $offset = $param->{'offset'} || 0; $offset *= $on_page; - die "no index_path?" unless ($hest_index_path); - - use HyperEstraier; - - my ($index_path, $index_node_url) = getHyperEstraier_url($hest_index_path); + die "no Hyper Estraier node URL?" unless ($hest_node_url); # open the database my $db; - if ($index_path) { - $db = HyperEstraier::Database->new(); - $db->open($index_path, $HyperEstraier::ESTDBREADER); - } elsif ($index_node_url) { - $db ||= HyperEstraier::Node->new($index_node_url); + if ($hest_node_url) { + $db ||= Search::Estraier::Node->new($hest_node_url); $db->set_auth('admin', 'admin'); } else { die "BUG: unimplemented"; } # create a search condition object - my $cond = HyperEstraier::Condition->new(); + my $cond = Search::Estraier::Condition->new(); my $q = $param->{'search_filename'}; my $shareid = $param->{'search_share'}; @@ -312,33 +300,31 @@ sub getFilesHyperEstraier($) { $cond->add_attr("shareid NUMEQ $shareid") if ($shareid); -# $cond->set_max( $offset + $on_page ); - $cond->set_options( $HyperEstraier::Condition::SURE ); + $cond->set_max( $offset + $on_page ); + $cond->set_options( 'SURE' ); $cond->set_order( getSort('search', 'est', $param->{'sort'} ) ); # get the result of search my @res; my ($result, $hits); - if ($index_path) { - $result = $db->search($cond, 0); - $hits = $result->size; - } elsif ($index_node_url) { + if ($hest_node_url) { $result = $db->search($cond, 0); - $hits = $result->doc_num; + if ($result) { + $hits = $result->hits; + } else { + $hits = 0; + } } else { die "BUG: unimplemented"; } # for each document in result for my $i ($offset .. ($offset + $on_page - 1)) { - last if ($i >= $hits); + last if ($i >= $result->doc_num); my $doc; - if ($index_path) { - my $id = $result->get($i); - $doc = $db->get_doc($id, 0); - } elsif ($index_node_url) { + if ($hest_node_url) { $doc = $result->get_doc($i); } else { die "BUG: unimplemented"; @@ -377,16 +363,18 @@ sub get_tgz_size_by_name($) { my $size = -1; - if (-f $tgz) { - $size = (stat($tgz))[7]; + if (-f "${tgz}.tar.gz") { + $size = (stat("${tgz}.tar.gz"))[7]; } elsif (-d $tgz) { opendir(my $dir, $tgz) || die "can't opendir $tgz: $!"; - my @parts = grep { !/^\./ && -f "$tgz/$_" } readdir($dir); + my @parts = grep { !/^\./ && !/md5/ && -f "$tgz/$_" } readdir($dir); $size = 0; foreach my $part (@parts) { $size += (stat("$tgz/$part"))[7] || die "can't stat $tgz/$part: $!"; } closedir $dir; + } else { + return -1; } return $size; @@ -418,6 +406,36 @@ sub getGzipSize($$) ); } +sub getVolumes($) { + my $id = shift; + + my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize"; + + my $sth = $dbh->prepare(qq{ + select + size + from backup_parts + where backup_id = ? + order by part_nr asc + }); + + $sth->execute($id); + + my $cumulative_size = 0; + my $volumes = 1; + + while(my ($size) = $sth->fetchrow_array) { + if ($cumulative_size + $size > $max_archive_size) { + $volumes++; + $cumulative_size = $size; + } else { + $cumulative_size += $size; + } + } + + return ($volumes,$cumulative_size); +} + sub getBackupsNotBurned($) { my $param = shift; @@ -444,7 +462,7 @@ print STDERR "## sort=". ($param->{'sort'} || 'no sort param') . " burn sql orde INNER JOIN shares ON backups.shareID=shares.ID INNER JOIN hosts ON backups.hostID = hosts.ID LEFT OUTER JOIN archive_backup ON archive_backup.backup_id = backups.id - WHERE backups.inc_size > 0 AND backups.inc_deleted is false AND archive_backup.backup_id IS NULL + WHERE backups.inc_size > 0 AND backups.size > 0 AND backups.inc_deleted is false AND archive_backup.backup_id IS NULL AND backups.parts > 0 GROUP BY backups.hostID, hosts.name, @@ -466,20 +484,30 @@ print STDERR "## sort=". ($param->{'sort'} || 'no sort param') . " burn sql orde while ( my $row = $sth->fetchrow_hashref() ) { $row->{'age'} = sprintf("%0.1f", ( $row->{'age'} / 86400 ) ); #$row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) ); - $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024); - # do some cluster calculation (approximate) and convert to kB - $row->{'inc_size'} = int(($row->{'inc_size'} + 1023 ) / ( 2 * 1024 ) * 2); + my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize"; + if ($row->{size} > $max_archive_size) { + ($row->{volumes}, $row->{inc_size_calc}) = getVolumes($row->{id}); + } + + $row->{size} = sprintf("%0.2f", $row->{size} / 1024 / 1024); + + # do some cluster calculation (approximate) + $row->{inc_size} = int(( ($row->{inc_size} + 1023 ) / 2 ) * 2); + $row->{inc_size_calc} ||= $row->{inc_size}; push @ret, $row; } - return @ret; + return @ret; } sub displayBackupsGrid($) { my $param = shift; + my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize"; + my $max_archive_file_size = $Conf{MaxArchiveFileSize} || die "no MaxFileInSize"; + my $retHTML .= q{