--- trunk/lib/BackupPC/SearchLib.pm 2005/09/20 16:23:04 124 +++ trunk/lib/BackupPC/SearchLib.pm 2005/10/10 14:04:49 166 @@ -288,11 +288,42 @@ $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(); @@ -302,15 +333,17 @@ backups.hostID AS hostID, hosts.name AS host, shares.name AS share, - backups.id AS backupnum, + backups.num AS backupnum, backups.type AS type, backups.date AS date, - backups.size AS size + 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 AND archive_backup.backup_id IS NULL - WHERE backups.size > 0 + 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, @@ -320,7 +353,8 @@ backups.id, backups.type, backups.date, - backups.size + backups.size, + backups.inc_size ORDER BY backups.date }; my $sth = $dbh->prepare( $sql ); @@ -330,71 +364,324 @@ 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{ - @@ -402,12 +689,9 @@ - + - }; my @color = (' bgcolor="#e0e0e0"', ''); @@ -422,31 +706,33 @@ $host = $backup->{'host'}; } my $ftype = ""; - - $retHTML .= ""; - $retHTML .= ''; - + + my $checkbox_key = $backup->{'hostid'}. '_' .$backup->{'backupnum'} . '_' . $backup->{'id'}; + + $retHTML .= + ' + ' . '' . '' . '' . '' . '' . '' . - '\n"; - + '' . + "\n"; } $retHTML .= "
- + Share Backup nodate age/days size/MBgzip sizegzip 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'} . + '
"; - $retHTML .= "total gzip size:
"; - $retHTML .= "Note:"; $retHTML .= "
"; return $retHTML;