/[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 143 by iklaric, Fri Oct 7 09:36:10 2005 UTC revision 197 by dpavlin, Thu Oct 13 18:33:00 2005 UTC
# Line 8  use DBI; Line 8  use DBI;
8  use DateTime;  use DateTime;
9  use vars qw(%In $MyURL);  use vars qw(%In $MyURL);
10  use Time::HiRes qw/time/;  use Time::HiRes qw/time/;
11    use XML::Writer;
12    use IO::File;
13    
14  my $on_page = 100;  my $on_page = 100;
15  my $pager_pages = 10;  my $pager_pages = 10;
# Line 68  sub dates_from_form($) { Line 70  sub dates_from_form($) {
70                  $mm =~ s/\D//g;                  $mm =~ s/\D//g;
71                  $dd =~ s/\D//g;                  $dd =~ s/\D//g;
72    
73                    my $h = my $m = my $s = 0;
74                    if ($suffix eq 'to') {
75                            $h = 23;
76                            $m = 59;
77                            $s = 59;
78                    }
79    
80                  my $dt = new DateTime(                  my $dt = new DateTime(
81                          year => $yyyy,                          year => $yyyy,
82                          month => $mm,                          month => $mm,
83                          day => $dd                          day => $dd,
84                            hour => $h,
85                            minute => $m,
86                            second => $s,
87                  );                  );
88                  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";
89                  return $dt->epoch || 'NULL';                  return $dt->epoch || 'NULL';
# Line 100  sub getWhere($) { Line 112  sub getWhere($) {
112          push @conditions, qq{ files.date >= $files_from } if ($files_from);          push @conditions, qq{ files.date >= $files_from } if ($files_from);
113          push @conditions, qq{ files.date <= $files_to } if ($files_to);          push @conditions, qq{ files.date <= $files_to } if ($files_to);
114    
115          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);
116    
117          push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'});          push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'});
118          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 300  sub getGzipName($$$)
300          $ret =~ s/\\h/$host/ge;          $ret =~ s/\\h/$host/ge;
301          $ret =~ s/\\s/$share/ge;          $ret =~ s/\\s/$share/ge;
302          $ret =~ s/\\n/$backupnum/ge;          $ret =~ s/\\n/$backupnum/ge;
303            
304            $ret =~ s/__+/_/g;
305    
306          return $ret;          return $ret;
307                    
308  }  }
309    
310    sub get_tgz_size_by_name($) {
311            my $name = shift;
312    
313            my $tgz = $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.$name;
314    
315            my $size = -1;
316    
317            if (-f $tgz) {
318                    $size = (stat($tgz))[7];
319            } elsif (-d $tgz) {
320                    opendir(my $dir, $tgz) || die "can't opendir $tgz: $!";
321                    my @parts = grep { !/^\./ && -f "$tgz/$_" } readdir($dir);
322                    $size = 0;
323                    foreach my $part (@parts) {
324                            $size += (stat("$tgz/$part"))[7] || die "can't stat $tgz/$part: $!";
325                    }
326                    closedir $dir;
327            }
328    
329            return $size;
330    }
331    
332  sub getGzipSize($$)  sub getGzipSize($$)
333  {  {
334          my ($hostID, $backupNum) = @_;          my ($hostID, $backupNum) = @_;
         my $ret;  
335          my $sql;          my $sql;
336          my $dbh = get_dbh();          my $dbh = get_dbh();
337                    
# Line 308  sub getGzipSize($$) Line 343  sub getGzipSize($$)
343                                  WHERE shares.id=backups.shareid AND                                  WHERE shares.id=backups.shareid AND
344                                            hosts.id =backups.hostid AND                                            hosts.id =backups.hostid AND
345                                            hosts.id=? AND                                            hosts.id=? AND
346                                            backups.num=?;                                            backups.num=?
347                          };                          };
348          my $sth = $dbh->prepare($sql);          my $sth = $dbh->prepare($sql);
349          $sth->execute($hostID, $backupNUM);          $sth->execute($hostID, $backupNum);
350          my $row = $res->fetchrow_hashref();  
351                    my $row = $sth->fetchrow_hashref();
352          my (undef,undef,undef,undef,undef,undef,undef,$ret,undef,undef,undef,undef,undef) =  
353                          stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.          return get_tgz_size_by_name(
354                                  getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'}));                  getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'})
355                    );
         return $ret;      
356  }  }
357    
358  sub getBackupsNotBurned() {  sub getBackupsNotBurned() {
# Line 330  sub getBackupsNotBurned() { Line 364  sub getBackupsNotBurned() {
364                          backups.hostID AS hostID,                          backups.hostID AS hostID,
365                          hosts.name AS host,                          hosts.name AS host,
366                          shares.name AS share,                          shares.name AS share,
367                          backups.id AS backupnum,                          backups.num AS backupnum,
368                          backups.type AS type,                          backups.type AS type,
369                          backups.date AS date,                          backups.date AS date,
370                          backups.size AS size                          backups.size AS size,
371                            backups.id AS id,
372                            backups.inc_size AS inc_size,
373                            backups.parts AS parts
374                  FROM backups                  FROM backups
375                  INNER JOIN shares       ON backups.shareID=shares.ID                  INNER JOIN shares       ON backups.shareID=shares.ID
376                  INNER JOIN hosts        ON backups.hostID = hosts.ID                  INNER JOIN hosts        ON backups.hostID = hosts.ID
377                  LEFT OUTER JOIN archive_backup ON archive_backup.backup_id = backups.id                  LEFT OUTER JOIN archive_backup ON archive_backup.backup_id = backups.id
378                  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
379                  GROUP BY                  GROUP BY
380                          backups.hostID,                          backups.hostID,
381                          hosts.name,                          hosts.name,
# Line 348  sub getBackupsNotBurned() { Line 385  sub getBackupsNotBurned() {
385                          backups.id,                          backups.id,
386                          backups.type,                          backups.type,
387                          backups.date,                          backups.date,
388                          backups.size                          backups.size,
389                            backups.inc_size,
390                            backups.parts
391                  ORDER BY backups.date                  ORDER BY backups.date
392          };          };
393          my $sth = $dbh->prepare( $sql );          my $sth = $dbh->prepare( $sql );
# Line 358  sub getBackupsNotBurned() { Line 397  sub getBackupsNotBurned() {
397          while ( my $row = $sth->fetchrow_hashref() ) {          while ( my $row = $sth->fetchrow_hashref() ) {
398                  $row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );                  $row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );
399                  $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);                  $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);
400                  my (undef,undef,undef,undef,undef,undef,undef,$fs_size,undef,undef,undef,undef,undef) =  
401                          stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.                  # do some cluster calculation (approximate) and convert to kB
402                                  getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'}));                  $row->{'inc_size'} = int(($row->{'inc_size'} + 1023 ) / ( 2 * 1024 ) * 2);
                 $row->{'fs_size'} = $fs_size;  
403                  push @ret, $row;                  push @ret, $row;
404          }          }
405                
# Line 475  DIV#fixedBox #submitBurner { Line 513  DIV#fixedBox #submitBurner {
513          z-index: 3;          z-index: 3;
514          background-color: transparent;          background-color: transparent;
515  }  }
516    
517    #parts {
518            padding: 0.4em;
519            display: none;
520            width: 100%;
521            font-size: 80%;
522            color: #ff0000;
523            text-align: center;
524    }
525  -->  -->
526  </style>  </style>
527  <script type="text/javascript">  <script type="text/javascript">
528  <!--  <!--
529    
530  var debug_div = null;  var debug_div = null;
531  var media_size = 4400 * 1024;  EOF3
532    
533            # take maximum archive size from configuration
534            $retHTML .= 'var media_size = '. $Conf{MaxArchiveSize} .';';
535    
536            $retHTML .= <<'EOF3';
537    
538  function debug(msg) {  function debug(msg) {
539  //      return; // Disable debugging          return; // Disable debugging
540    
541          if (! debug_div) debug_div = document.getElementById('debug');          if (! debug_div) debug_div = document.getElementById('debug');
542    
# Line 540  function checkAll(location) { Line 592  function checkAll(location) {
592          update_sum(suma);          update_sum(suma);
593  }  }
594    
595  function update_sum(suma) {  function update_sum(suma, suma_disp) {
596          element_id('forma').elements['totalsize'].value = suma;          if (! suma_disp) suma_disp = suma;
597            element_id('forma').elements['totalsize'].value = suma_disp;
598          pbar_set(suma, media_size);          pbar_set(suma, media_size);
599          debug('total size: ' + suma);          debug('total size: ' + suma);
600  }  }
# Line 556  function sumiraj(e) { Line 609  function sumiraj(e) {
609                  } else {                  } else {
610                          suma -= size;                          suma -= size;
611                  }                  }
612    
613                    var parts = parseInt( element_id("prt" + e.name.substr(3)).value);
614                    if (suma > media_size && suma == size && parts > 1) {
615                            element_id("parts").innerHTML = "This will take "+parts+" mediums!";
616                            element_id("parts").style.display = 'block';
617                            update_sum(media_size, suma);
618                            suma = media_size;
619                            return suma;
620                    } else {
621                            element_id("parts").style.display = 'none';
622                    }
623    
624                    if (suma < 0) suma = 0;
625          } else {          } else {
626                  suma = 0;                  suma = 0;
627                  for (var i = 0; i < len; i++) {                  for (var i = 0; i < len; i++) {
# Line 653  Size: <input type="text" name="totalsize Line 719  Size: <input type="text" name="totalsize
719  </div>  </div>
720  <br/>  <br/>
721    
722    <div id="parts">&nbsp;</div>
723    
724  Note:  Note:
725  <textarea name="note" cols="10" rows="5" id="note"></textarea>  <textarea name="note" cols="10" rows="5" id="note"></textarea>
726    
# Line 679  EOF3 Line 747  EOF3
747                          <td align="center">date</td>                          <td align="center">date</td>
748                          <td align="center">age/days</td>                          <td align="center">age/days</td>
749                          <td align="center">size/MB</td>                          <td align="center">size/MB</td>
750                          <td align="center">gzip size</td>                          <td align="center">gzip size/kB</td>
751                          </tr>                          </tr>
752    
753          };          };
# Line 697  EOF3 Line 765  EOF3
765                  }                  }
766                  my $ftype = "";                  my $ftype = "";
767    
768                    my $checkbox_key = $backup->{'hostid'}. '_' .$backup->{'backupnum'} . '_' . $backup->{'id'};
769    
770                  $retHTML .=                  $retHTML .=
771                          '<tr' . $color[$i %2 ] . '>                          '<tr' . $color[$i %2 ] . '>
772                          <td class="fview">';                          <td class="fview">';
773                  # FIXME  
774                  $backup->{'fs_size'} = int($backup->{'size'} * 1024);                  if (($backup->{'inc_size'} || 0) > 0) {
                 if (($backup->{'fs_size'} || 0) > 0) {  
775                          $retHTML .= '                          $retHTML .= '
776                          <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);">';  
777                  }                  }
778    
779                  $retHTML .=                  $retHTML .=
780                          '</td>' .                          '</td>' .
781                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .
# Line 717  EOF3 Line 784  EOF3
784                          '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .                          '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .
785                          '<td align="center">' . $backup->{'age'} . '</td>' .                          '<td align="center">' . $backup->{'age'} . '</td>' .
786                          '<td align="right">' . $backup->{'size'} . '</td>' .                          '<td align="right">' . $backup->{'size'} . '</td>' .
787                          '<td align="right">' . $backup->{'fs_size'} .                          '<td align="right">' . $backup->{'inc_size'} .
788                          '<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>' .
789                            '<input type="hidden" id="prt'.$checkbox_key .'" value="'. $backup->{'parts'} .'"></td>' .
790    
791                          "</tr>\n";                          "</tr>\n";
792          }          }

Legend:
Removed from v.143  
changed lines
  Added in v.197

  ViewVC Help
Powered by ViewVC 1.1.26