/[BackupPC]/trunk/lib/BackupPC/SearchLib.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/BackupPC/SearchLib.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 140 by ravilov, Fri Oct 7 07:59:28 2005 UTC revision 186 by dpavlin, Wed Oct 12 12:53:27 2005 UTC
# Line 68  sub dates_from_form($) { Line 68  sub dates_from_form($) {
68                  $mm =~ s/\D//g;                  $mm =~ s/\D//g;
69                  $dd =~ s/\D//g;                  $dd =~ s/\D//g;
70    
71                    my $h = my $m = my $s = 0;
72                    if ($suffix eq 'to') {
73                            $h = 23;
74                            $m = 59;
75                            $s = 59;
76                    }
77    
78                  my $dt = new DateTime(                  my $dt = new DateTime(
79                          year => $yyyy,                          year => $yyyy,
80                          month => $mm,                          month => $mm,
81                          day => $dd                          day => $dd,
82                            hour => $h,
83                            minute => $m,
84                            second => $s,
85                  );                  );
86                  print STDERR "mk_epoch_date($name,$suffix) [$yyyy-$mm-$dd] = " . $dt->ymd . " " . $dt->hms . "\n";                  print STDERR "mk_epoch_date($name,$suffix) [$yyyy-$mm-$dd] = " . $dt->ymd . " " . $dt->hms . "\n";
87                  return $dt->epoch || 'NULL';                  return $dt->epoch || 'NULL';
# Line 100  sub getWhere($) { Line 110  sub getWhere($) {
110          push @conditions, qq{ files.date >= $files_from } if ($files_from);          push @conditions, qq{ files.date >= $files_from } if ($files_from);
111          push @conditions, qq{ files.date <= $files_to } if ($files_to);          push @conditions, qq{ files.date <= $files_to } if ($files_to);
112    
113          print STDERR "backup: $backup_from - $backup_to files: $files_from - $files_to cond:" . join(" | ",@conditions);          print STDERR "backup: $backup_from - $backup_to files: $files_from - $files_to cond:" . join(" and ",@conditions);
114    
115          push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'});          push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'});
116          push (@conditions, " upper(files.path) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'});          push (@conditions, " upper(files.path) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'});
# Line 288  sub getGzipName($$$) Line 298  sub getGzipName($$$)
298          $ret =~ s/\\h/$host/ge;          $ret =~ s/\\h/$host/ge;
299          $ret =~ s/\\s/$share/ge;          $ret =~ s/\\s/$share/ge;
300          $ret =~ s/\\n/$backupnum/ge;          $ret =~ s/\\n/$backupnum/ge;
301            
302            $ret =~ s/__+/_/g;
303    
304          return $ret;          return $ret;
305                    
306  }  }
307    
308    sub getGzipSize($$)
309    {
310            my ($hostID, $backupNum) = @_;
311            my $ret;
312            my $sql;
313            my $dbh = get_dbh();
314            
315            $sql = q{
316                                    SELECT hosts.name  as host,
317                                               shares.name as share,
318                                               backups.num as backupnum
319                                    FROM hosts, backups, shares
320                                    WHERE shares.id=backups.shareid AND
321                                              hosts.id =backups.hostid AND
322                                              hosts.id=? AND
323                                              backups.num=?
324                            };
325            my $sth = $dbh->prepare($sql);
326            $sth->execute($hostID, $backupNum);
327    
328            my $row = $sth->fetchrow_hashref();
329            
330            my (undef,undef,undef,undef,undef,undef,undef,$ret,undef,undef,undef,undef,undef) =
331                            stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.
332                                    getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'}));
333            
334            return $ret;    
335    }
336    
337  sub getBackupsNotBurned() {  sub getBackupsNotBurned() {
338    
339          my $dbh = get_dbh();          my $dbh = get_dbh();
# Line 302  sub getBackupsNotBurned() { Line 343  sub getBackupsNotBurned() {
343                          backups.hostID AS hostID,                          backups.hostID AS hostID,
344                          hosts.name AS host,                          hosts.name AS host,
345                          shares.name AS share,                          shares.name AS share,
346                          backups.id AS backupnum,                          backups.num AS backupnum,
347                          backups.type AS type,                          backups.type AS type,
348                          backups.date AS date,                          backups.date AS date,
349                          backups.size AS size                          backups.size AS size,
350                            backups.id AS id,
351                            backups.inc_size AS inc_size
352                  FROM backups                  FROM backups
353                  INNER JOIN shares       ON backups.shareID=shares.ID                  INNER JOIN shares       ON backups.shareID=shares.ID
354                  INNER JOIN hosts        ON backups.hostID = hosts.ID                  INNER JOIN hosts        ON backups.hostID = hosts.ID
355                  LEFT OUTER JOIN archive_backup ON archive_backup.backup_id = backups.id                  LEFT OUTER JOIN archive_backup ON archive_backup.backup_id = backups.id
356                  WHERE backups.size > 0 AND archive_backup.backup_id IS NULL                  WHERE backups.inc_size > 0 AND backups.inc_deleted is false AND archive_backup.backup_id IS NULL
357                  GROUP BY                  GROUP BY
358                          backups.hostID,                          backups.hostID,
359                          hosts.name,                          hosts.name,
# Line 320  sub getBackupsNotBurned() { Line 363  sub getBackupsNotBurned() {
363                          backups.id,                          backups.id,
364                          backups.type,                          backups.type,
365                          backups.date,                          backups.date,
366                          backups.size                          backups.size,
367                            backups.inc_size
368                  ORDER BY backups.date                  ORDER BY backups.date
369          };          };
370          my $sth = $dbh->prepare( $sql );          my $sth = $dbh->prepare( $sql );
# Line 330  sub getBackupsNotBurned() { Line 374  sub getBackupsNotBurned() {
374          while ( my $row = $sth->fetchrow_hashref() ) {          while ( my $row = $sth->fetchrow_hashref() ) {
375                  $row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );                  $row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );
376                  $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);                  $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);
377                  my (undef,undef,undef,undef,undef,undef,undef,$fs_size,undef,undef,undef,undef,undef) =  
378                          stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.                  # do some cluster calculation (approximate) and convert to kB
379                                  getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'}));                  $row->{'inc_size'} = int(($row->{'inc_size'} + 1023 ) / ( 2 * 1024 ) * 2);
                 $row->{'fs_size'} = $fs_size;  
380                  push @ret, $row;                  push @ret, $row;
381          }          }
382                
# Line 453  DIV#fixedBox #submitBurner { Line 496  DIV#fixedBox #submitBurner {
496  <!--  <!--
497    
498  var debug_div = null;  var debug_div = null;
499  var media_size = 4400 * 1024;  EOF3
500    
501            # take maximum archive size from configuration
502            $retHTML .= 'var media_size = '. $Conf{MaxArchiveSize} .';';
503    
504            $retHTML .= <<'EOF3';
505    
506  function debug(msg) {  function debug(msg) {
507  //      return; // Disable debugging  //      return; // Disable debugging
# Line 483  function element_id(name,element) { Line 531  function element_id(name,element) {
531  }  }
532    
533  function checkAll(location) {  function checkAll(location) {
534          var len = element_id('forma').elements.length;          var f = element_id('forma') || null;
535            if (!f) return false;
536    
537            var len = f.elements.length;
538          var check_all = element_id('allFiles');          var check_all = element_id('allFiles');
539          var suma = 0;          var suma = check_all.checked ? (parseInt(f.elements['totalsize'].value) || 0) : 0;
540    
541          for (var i = 0; i < len; i++) {          for (var i = 0; i < len; i++) {
542                    var e = f.elements[i];
543                  var e = element_id('forma').elements[i];                  if (e.name != 'all' && e.name.substr(0, 3) == 'fcb') {
                 if (e.name != 'all' && e.name.substr(0,3) == 'fcb') {  
544                          if (check_all.checked) {                          if (check_all.checked) {
545                                    if (e.checked) continue;
546                                  var el = element_id("fss" + e.name.substr(3));                                  var el = element_id("fss" + e.name.substr(3));
547                                  var size = parseInt(el.value) || 0;                                  var size = parseInt(el.value) || 0;
548                                  debug('suma: '+suma+' size: '+size);                                  debug('suma: '+suma+' size: '+size);
# Line 510  function checkAll(location) { Line 561  function checkAll(location) {
561  }  }
562    
563  function update_sum(suma) {  function update_sum(suma) {
564          element_id('forma').totalsize.value = suma;          element_id('forma').elements['totalsize'].value = suma;
565          pbar_set(suma, media_size);          pbar_set(suma, media_size);
566          debug('total size: '+suma);          debug('total size: ' + suma);
567  }  }
568    
569  function sumiraj(e) {  function sumiraj(e) {
570          var suma = parseInt(element_id('forma').totalsize.value) || 0;          var suma = parseInt(element_id('forma').elements['totalsize'].value) || 0;
571          var len = element_id('forma').elements.length;          var len = element_id('forma').elements.length;
572          if (e) {          if (e) {
573                  var size = parseInt( element_id("fss" + e.name.substr(3)).value);                  var size = parseInt( element_id("fss" + e.name.substr(3)).value);
# Line 648  EOF3 Line 699  EOF3
699                          <td align="center">date</td>                          <td align="center">date</td>
700                          <td align="center">age/days</td>                          <td align="center">age/days</td>
701                          <td align="center">size/MB</td>                          <td align="center">size/MB</td>
702                          <td align="center">gzip size</td>                          <td align="center">gzip size/kB</td>
703                          </tr>                          </tr>
704    
705          };          };
# Line 666  EOF3 Line 717  EOF3
717                  }                  }
718                  my $ftype = "";                  my $ftype = "";
719    
720                    my $checkbox_key = $backup->{'hostid'}. '_' .$backup->{'backupnum'} . '_' . $backup->{'id'};
721    
722                  $retHTML .=                  $retHTML .=
723                          '<tr' . $color[$i %2 ] . '>                          '<tr' . $color[$i %2 ] . '>
724                          <td class="fview">';                          <td class="fview">';
725                  # FIXME  
726                  $backup->{'fs_size'} = int($backup->{'size'} * 1024);                  if (($backup->{'inc_size'} || 0) > 0) {
                 if (($backup->{'fs_size'} || 0) > 0) {  
727                          $retHTML .= '                          $retHTML .= '
728                          <input type="checkbox" name="fcb' .                          <input type="checkbox" name="fcb' . $checkbox_key . '" value="' . $checkbox_key . '" onClick="sumiraj(this);">';
                         $backup->{'hostid'}.'_'.$backup->{'backupnum'} .  
                         '" value="' . $backup->{'hostid'}.'_'.$backup->{'backupnum'} .  
                         '" onClick="sumiraj(this);">';  
729                  }                  }
730    
731                  $retHTML .=                  $retHTML .=
732                          '</td>' .                          '</td>' .
733                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .
# Line 686  EOF3 Line 736  EOF3
736                          '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .                          '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .
737                          '<td align="center">' . $backup->{'age'} . '</td>' .                          '<td align="center">' . $backup->{'age'} . '</td>' .
738                          '<td align="right">' . $backup->{'size'} . '</td>' .                          '<td align="right">' . $backup->{'size'} . '</td>' .
739                          '<td align="right">' . $backup->{'fs_size'} .                          '<td align="right">' . $backup->{'inc_size'} .
740                          '<input type="hidden" iD="fss'.$backup->{'hostid'}.'_'.$backup->{'backupnum'} . '" value="'. $backup->{'fs_size'} .'"></td>' .                          '<input type="hidden" iD="fss'.$checkbox_key .'" value="'. $backup->{'inc_size'} .'"></td>' .
741    
742                          "</tr>\n";                          "</tr>\n";
743          }          }

Legend:
Removed from v.140  
changed lines
  Added in v.186

  ViewVC Help
Powered by ViewVC 1.1.26