--- trunk/lib/BackupPC/SearchLib.pm 2005/09/11 13:05:06 117 +++ trunk/lib/BackupPC/SearchLib.pm 2005/10/10 14:04:49 166 @@ -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; @@ -198,11 +194,11 @@ 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($index_path); + my ($index_path, $index_node_url) = getHyperEstraier_url($hest_index_path); # open the database my $db; @@ -292,30 +288,74 @@ $ret =~ s/\\h/$host/ge; $ret =~ s/\\s/$share/ge; $ret =~ s/\\n/$backupnum/ge; - + + $ret =~ s/__+/_/g; + return $ret; } +sub getGzipSize($$) +{ + my ($hostID, $backupNum) = @_; + my $ret; + my $sql; + my $dbh = get_dbh(); + + $sql = q{ + SELECT hosts.name as host, + shares.name as share, + backups.num as backupnum + FROM hosts, backups, shares + WHERE shares.id=backups.shareid AND + hosts.id =backups.hostid AND + hosts.id=? AND + backups.num=? + }; + my $sth = $dbh->prepare($sql); + $sth->execute($hostID, $backupNum); + + my $row = $sth->fetchrow_hashref(); + + my (undef,undef,undef,undef,undef,undef,undef,$ret,undef,undef,undef,undef,undef) = + stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'. + getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'})); + + 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.num AS backupnum, + backups.type AS type, + backups.date AS date, + backups.size AS size, + backups.id AS id, + backups.inc_size AS inc_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 + WHERE backups.size > 0 AND backups.inc_size > 0 AND backups.inc_deleted is false AND archive_backup.backup_id IS NULL + GROUP BY + backups.hostID, + hosts.name, + shares.name, + backups.num, + backups.shareid, + backups.id, + backups.type, + backups.date, + backups.size, + backups.inc_size + ORDER BY backups.date }; my $sth = $dbh->prepare( $sql ); my @ret; @@ -324,62 +364,334 @@ 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; + + # do some cluster calculation (approximate) and convert to kB + $row->{'inc_size'} = int(($row->{'inc_size'} + 1023 ) / ( 2 * 1024 ) * 2); push @ret, $row; } return @ret; } -sub displayBackupsGrid() - { - my $retHTML = ""; - - $retHTML .= < +sub displayBackupsGrid() { + + my $retHTML .= q{ +
+ }; + + $retHTML .= <<'EOF3'; + + +/* progress bar */ + +var _pbar_width = null; +var _pbar_warn = 10; // change color in last 10% + +function pbar_reset() { + element_id("mask").style.left = "0px"; + _pbar_width = element_id("mContainer").offsetWidth - 2; + element_id("mask").style.width = _pbar_width + "px"; + element_id("mask").style.display = "block"; + element_id("progressIndicator").style.zIndex = 10; + element_id("progressIndicator").innerHTML = "0"; +} + +function dec2hex(d) { + var hch = '0123456789ABCDEF'; + var a = d % 16; + var q = (d - a) / 16; + return hch.charAt(q) + hch.charAt(a); +} + +function pbar_set(amount, max) { + debug('pbar_set('+amount+', '+max+')'); + + if (_pbar_width == null) { + var _mc = element_id("mContainer"); + if (_pbar_width == null) _pbar_width = parseInt(_mc.offsetWidth ? (_mc.offsetWidth - 2) : 0) || null; + if (_pbar_width == null) _pbar_width = parseInt(_mc.clientWidth ? (_mc.clientWidth + 2) : 0) || null; + if (_pbar_width == null) _pbar_width = 0; + } + + var pcnt = Math.floor(amount * 100 / max); + var p90 = 100 - _pbar_warn; + var pcol = pcnt - p90; + if (Math.round(pcnt) <= 100) { + if (pcol < 0) pcol = 0; + var e = element_id("submitBurner"); + debug('enable_button'); + e.disabled = false; + var a = e.getAttributeNode('disabled') || null; + if (a) e.removeAttributeNode(a); + } else { + debug('disable button'); + pcol = _pbar_warn; + var e = element_id("submitBurner"); + if (!e.disabled) e.disabled = true; + } + var col_g = Math.floor((_pbar_warn - pcol) * 255 / _pbar_warn); + var col = '#FF' + dec2hex(col_g) + '00'; + + //debug('pcol: '+pcol+' g:'+col_g+' _pbar_warn:'+ _pbar_warn + ' color: '+col); + element_id("gradient").style.backgroundColor = col; + + element_id("progressIndicator").innerHTML = pcnt + '%'; + //element_id("progressIndicator").innerHTML = amount; + + element_id("mask").style.clip = 'rect(' + Array( + '0px', + element_id("mask").offsetWidth + 'px', + element_id("mask").offsetHeight + 'px', + Math.round(_pbar_width * amount / max) + 'px' + ).join(' ') + ')'; +} + +if (!self.body) self.body = new Object(); +self.onload = self.document.onload = self.body.onload = function() { + //pbar_reset(); + sumiraj(); +}; + +// --> + +
+ +Size: kB + +
+
 
+
 
+
0%
+
+
+ +Note: + + + + +
+ EOF3 $retHTML .= q{ - - - - - - - - - - - - - - - - + + +
- - ShareBackup noTypedateage/dayssize/MBgzip size
- -
+ + + + + + + + + + + }; my @color = (' bgcolor="#e0e0e0"', ''); @@ -394,24 +706,30 @@ $host = $backup->{'host'}; } my $ftype = ""; - - $retHTML .= ""; - $retHTML .= ''; - + + my $checkbox_key = $backup->{'hostid'}. '_' .$backup->{'backupnum'} . '_' . $backup->{'id'}; + $retHTML .= + ' + ' . '' . '' . '' . '' . '' . '' . - '' . - "\n"; - + '' . + "\n"; } $retHTML .= "
+ + ShareBackup noTypedateage/dayssize/MBgzip size/kB
'; + + if (($backup->{'inc_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'} .'
' . $backup->{'inc_size'} . + '
";