/[BackupPC]/trunk/bin/BackupPC_updatedb
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/bin/BackupPC_updatedb

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

revision 65 by dpavlin, Sun Aug 21 23:25:47 2005 UTC revision 66 by dpavlin, Mon Aug 22 00:09:59 2005 UTC
# Line 96  if ($opt{c}) { Line 96  if ($opt{c}) {
96                          date    integer         NOT NULL,                          date    integer         NOT NULL,
97                          type    CHAR(4)         not null,                          type    CHAR(4)         not null,
98                          shareID integer         not null references shares(id),                          shareID integer         not null references shares(id),
99                            size    integer         not null,
100                          PRIMARY KEY(hostID, num, shareID)                          PRIMARY KEY(hostID, num, shareID)
101                  );                              );            
102          });          });
# Line 188  WHERE hostID=? AND num=? AND shareid=? Line 189  WHERE hostID=? AND num=? AND shareid=?
189  });  });
190    
191  $sth->{insert_backups} = $dbh->prepare(qq{  $sth->{insert_backups} = $dbh->prepare(qq{
192  INSERT INTO backups (hostID, num, date, type, shareid)  INSERT INTO backups (hostID, num, date, type, shareid, size)
193  VALUES (?,?,?,?,?)  VALUES (?,?,?,?,?,?)
194  });  });
195    
196  $sth->{insert_files} = $dbh->prepare(qq{  $sth->{insert_files} = $dbh->prepare(qq{
# Line 262  foreach my $host_key (keys %{$hosts}) { Line 263  foreach my $host_key (keys %{$hosts}) {
263                          # dump some log                          # dump some log
264                          print strftime($t_fmt,localtime())," ", $share;                          print strftime($t_fmt,localtime())," ", $share;
265    
266                          my ($f, $nf, $d, $nd) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);                          my ($f, $nf, $d, $nd, $size) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);
267    
268                          $sth->{insert_backups}->execute(                          $sth->{insert_backups}->execute(
269                                  $hostID,                                  $hostID,
270                                  $backupNum,                                  $backupNum,
271                                  $backup->{'endTime'},                                  $backup->{'endTime'},
272                                  $backup->{'type'},                                  $backup->{'type'},
273                                  $shareID                                  $shareID,
274                                    $size,
275                          );                          );
276    
277                          print " commit";                          print " commit";
278                          $dbh->commit();                          $dbh->commit();
279    
280                          my $dur = (time() - $t) || 1;                          my $dur = (time() - $t) || 1;
281                          printf(" %d/%d files %d/%d dirs [%.2f/s dur: %s]\n",                          printf(" %d/%d files %d/%d dirs %0.2f MB [%.2f/s dur: %s]\n",
282                                  $nf, $f, $nd, $d,                                  $nf, $f, $nd, $d,
283                                    ($size / 1024 / 1024),
284                                  ( ($f+$d) / $dur ),                                  ( ($f+$d) / $dur ),
285                                  fmt_time($dur)                                  fmt_time($dur)
286                          );                          );
# Line 359  sub recurseDir($$$$$$$$) { Line 362  sub recurseDir($$$$$$$$) {
362    
363          print STDERR "\nrecurse($hostname,$backupNum,$share,$dir,$shareID)\n" if ($debug >= 1);          print STDERR "\nrecurse($hostname,$backupNum,$share,$dir,$shareID)\n" if ($debug >= 1);
364    
365          my ($nr_files, $new_files, $nr_dirs, $new_dirs) = (0,0,0,0);          my ($nr_files, $new_files, $nr_dirs, $new_dirs, $size) = (0,0,0,0,0);
366    
367          { # scope          { # scope
368                  my @stack;                  my @stack;
# Line 369  sub recurseDir($$$$$$$$) { Line 372  sub recurseDir($$$$$$$$) {
372    
373                  # first, add all the entries in current directory                  # first, add all the entries in current directory
374                  foreach my $path_key (keys %{$filesInBackup}) {                  foreach my $path_key (keys %{$filesInBackup}) {
375                            print STDERR "# file ",Dumper($filesInBackup->{$path_key}),"\n" if ($debug >= 3);
376                          my @data = (                          my @data = (
377                                  $shareID,                                  $shareID,
378                                  $backupNum,                                  $backupNum,
# Line 398  sub recurseDir($$$$$$$$) { Line 402  sub recurseDir($$$$$$$$) {
402                                          $new_files++;                                          $new_files++;
403                                          print STDERR " file\n" if ($debug >= 2);                                          print STDERR " file\n" if ($debug >= 2);
404                                  }                                  }
405                                    $size += $filesInBackup->{$path_key}->{'size'} || 0;
406                          }                          }
407    
408                          if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {                          if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
# Line 422  sub recurseDir($$$$$$$$) { Line 427  sub recurseDir($$$$$$$$) {
427                  print STDERR "## STACK ",join(", ", @stack),"\n" if ($debug >= 2);                  print STDERR "## STACK ",join(", ", @stack),"\n" if ($debug >= 2);
428    
429                  while ( my $dir = shift @stack ) {                  while ( my $dir = shift @stack ) {
430                          my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $files, $backupNum, $share, $dir, $shareID);                          my ($f,$nf,$d,$nd, $s) = recurseDir($bpc, $hostname, $files, $backupNum, $share, $dir, $shareID);
431                          print STDERR "# $dir f: $f nf: $nf d: $d nd: $nd\n" if ($debug >= 1);                          print STDERR "# $dir f: $f nf: $nf d: $d nd: $nd\n" if ($debug >= 1);
432                          $nr_files += $f;                          $nr_files += $f;
433                          $new_files += $nf;                          $new_files += $nf;
434                          $nr_dirs += $d;                          $nr_dirs += $d;
435                          $new_dirs += $nd;                          $new_dirs += $nd;
436                            $size += $s;
437                  }                  }
438          }          }
439    
440          return ($nr_files, $new_files, $nr_dirs, $new_dirs);          return ($nr_files, $new_files, $nr_dirs, $new_dirs, $size);
441  }  }
442    

Legend:
Removed from v.65  
changed lines
  Added in v.66

  ViewVC Help
Powered by ViewVC 1.1.26