--- trunk/lib/BackupPC/SearchLib.pm 2005/08/30 22:43:01 102 +++ trunk/lib/BackupPC/SearchLib.pm 2005/09/22 14:25:51 129 @@ -15,11 +15,7 @@ my $dsn = $Conf{SearchDSN}; my $db_user = $Conf{SearchUser} || ''; -my $index_path = $Conf{HyperEstraierIndex}; -if ($index_path) { - $index_path = $TopDir . '/' . $index_path; - $index_path =~ s#//#/#g; -} +my $hest_index_path = $Conf{HyperEstraierIndex}; my $dbh; @@ -175,19 +171,46 @@ return ($results, \@ret); } +sub getHyperEstraier_url($) { + my ($use_hest) = @_; + + return unless $use_hest; + + use HyperEstraier; + my ($index_path, $index_node_url); + + 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); +} + sub getFilesHyperEstraier($) { my ($param) = @_; my $offset = $param->{'offset'} || 0; $offset *= $on_page; - die "no index_path?" unless ($index_path); + die "no index_path?" unless ($hest_index_path); use HyperEstraier; + my ($index_path, $index_node_url) = getHyperEstraier_url($hest_index_path); + # open the database - my $db = HyperEstraier::Database->new(); - $db->open($index_path, $HyperEstraier::ESTDBREADER); + 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); + $db->set_auth('admin', 'admin'); + } else { + die "BUG: unimplemented"; + } # create a search condition object my $cond = HyperEstraier::Condition->new(); @@ -219,17 +242,32 @@ $cond->set_order( 'date NUMA' ); # get the result of search - my $result = $db->search($cond, 0); - my @res; - my $hits = $result->size; + my ($result, $hits); + + if ($index_path) { + $result = $db->search($cond, 0); + $hits = $result->size; + } elsif ($index_node_url) { + $result = $db->search($cond, 0); + $hits = $result->doc_num; + } else { + die "BUG: unimplemented"; + } # for each document in result for my $i ($offset .. ($offset + $on_page - 1)) { last if ($i >= $hits); - my $id = $result->get($i); - my $doc = $db->get_doc($id, 0); + my $doc; + if ($index_path) { + my $id = $result->get($i); + $doc = $db->get_doc($id, 0); + } elsif ($index_node_url) { + $doc = $result->get_doc($i); + } else { + die "BUG: unimplemented"; + } my $row; foreach my $c (qw/fid hname sname backupnum fiilename filepath date type size/) { @@ -241,25 +279,49 @@ return ($hits, \@res); } +sub getGzipName($$$) +{ + my ($host, $share, $backupnum) = @_; + my $ret = $Conf{GzipSchema}; + + $share =~ s/\//_/g; + $ret =~ s/\\h/$host/ge; + $ret =~ s/\\s/$share/ge; + $ret =~ s/\\n/$backupnum/ge; + + return $ret; + +} + sub getBackupsNotBurned() { my $dbh = get_dbh(); - my $sql = q{ - SELECT - backups.hostID AS hostid, - min(hosts.name) AS host, - min(shares.name) AS share, - backups.num AS backupnum, - min(backups.type) AS type, - min(backups.date) AS date, - min(backups.size) AS size - FROM files - INNER JOIN shares ON files.shareID=shares.ID - INNER JOIN hosts ON hosts.ID = shares.hostID - INNER JOIN backups ON backups.num = files.backupnum and backups.hostID = hosts.ID AND backups.shareID = shares.ID - GROUP BY - backups.hostID, backups.num, backups.shareid - ORDER BY min(backups.date) + + my $sql = q{ + SELECT + backups.hostID AS hostID, + hosts.name AS host, + shares.name AS share, + backups.id AS backupnum, + backups.type AS type, + backups.date AS date, + backups.size AS size + FROM backups + 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 AND archive_backup.backup_id IS NULL + WHERE backups.size > 0 + GROUP BY + backups.hostID, + hosts.name, + shares.name, + backups.num, + backups.shareid, + backups.id, + backups.type, + backups.date, + backups.size + ORDER BY backups.date }; my $sth = $dbh->prepare( $sql ); my @ret; @@ -268,57 +330,317 @@ while ( my $row = $sth->fetchrow_hashref() ) { $row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) ); $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024); + my (undef,undef,undef,undef,undef,undef,undef,$fs_size,undef,undef,undef,undef,undef) = + stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'. + getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'})); + $row->{'fs_size'} = $fs_size; push @ret, $row; } return @ret; } -sub displayBackupsGrid() - { - my $retHTML = ""; - - $retHTML .= < + }; + + $retHTML .= <<'EOF3'; + + +
+ +Size: + + +
+
+
+
 
+
+ +
+Note: +
+ +
+ + +
+
+no debug output yet +
EOF3 $retHTML .= q{ -
- - - - - - - - - - - - - - + + +
- - ShareBackup noTypedateage/dayssize/MB
- -
+ + + + + + + + + + + }; my @color = (' bgcolor="#e0e0e0"', ''); @@ -333,23 +655,31 @@ $host = $backup->{'host'}; } my $ftype = ""; - - $retHTML .= ""; - $retHTML .= ''; - + + $retHTML .= + ' + ' . '' . '' . '' . '' . '' . '' . - "\n"; - + '' . + "\n"; } $retHTML .= "
+ + ShareBackup noTypedateage/dayssize/MBgzip size
'; + # FIXME + $backup->{'fs_size'} = int($backup->{'size'} * 1024); + if (($backup->{'fs_size'} || 0) > 0) { + $retHTML .= ' + '; + } $retHTML .= + '' . $backup->{'host'} . ':' . $backup->{'share'} . '' . $backup->{'backupnum'} . '' . $backup->{'type'} . '' . epoch_to_iso( $backup->{'date'} ) . '' . $backup->{'age'} . '' . $backup->{'size'} . '
' . $backup->{'fs_size'} . + '
";