/[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 70 by dpavlin, Wed Aug 24 17:12:22 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 222  foreach my $host_key (keys %{$hosts}) { Line 223  foreach my $host_key (keys %{$hosts}) {
223                  $hostID = $dbh->last_insert_id(undef,undef,'hosts',undef);                  $hostID = $dbh->last_insert_id(undef,undef,'hosts',undef);
224          }          }
225    
226          print("host ".$hosts->{$host_key}->{'host'}.": ");          print "host ".$hosts->{$host_key}->{'host'}.": ";
227    
228          # get backups for a host          # get backups for a host
229          my @backups = $bpc->BackupInfoRead($hostname);          my @backups = $bpc->BackupInfoRead($hostname);
230          print scalar @backups, " increments\n";          my $incs = scalar @backups;
231            print  "$incs increments\n";
232    
233          my $inc_nr = 0;          my $inc_nr = 0;
234            $beenThere = {};
235    
236          foreach my $backup (@backups) {          foreach my $backup (@backups) {
237    
# Line 238  foreach my $host_key (keys %{$hosts}) { Line 241  foreach my $host_key (keys %{$hosts}) {
241                  my $backupNum = $backup->{'num'};                  my $backupNum = $backup->{'num'};
242                  my @backupShares = ();                  my @backupShares = ();
243    
244                  print $hosts->{$host_key}->{'host'},                  printf("%-10s %2d/%-2d #%-2d %s %5s/%5s files (date: %s dur: %s)\n",
245                          "\t#$backupNum\t", $backup->{type} || '?', " ",                          $hosts->{$host_key}->{'host'},
246                          $backup->{nFilesNew} || '?', "/", $backup->{nFiles} || '?',                          $inc_nr, $incs, $backupNum,
247                          " files (date: ",                          $backup->{type} || '?',
248                            $backup->{nFilesNew} || '?', $backup->{nFiles} || '?',
249                          strftime($t_fmt,localtime($backup->{startTime})),                          strftime($t_fmt,localtime($backup->{startTime})),
250                          " dur: ",                          fmt_time($backup->{endTime} - $backup->{startTime})
251                          fmt_time($backup->{endTime} - $backup->{startTime}),                  );
                         ")\n";  
252    
253                  my $files = BackupPC::View->new($bpc, $hostname, \@backups, 1);                  my $files = BackupPC::View->new($bpc, $hostname, \@backups, 1);
254                  foreach my $share ($files->shareList($backupNum)) {                  foreach my $share ($files->shareList($backupNum)) {
# Line 262  foreach my $host_key (keys %{$hosts}) { Line 265  foreach my $host_key (keys %{$hosts}) {
265                          # dump some log                          # dump some log
266                          print strftime($t_fmt,localtime())," ", $share;                          print strftime($t_fmt,localtime())," ", $share;
267    
268                          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);
269    
270                          $sth->{insert_backups}->execute(                          $sth->{insert_backups}->execute(
271                                  $hostID,                                  $hostID,
272                                  $backupNum,                                  $backupNum,
273                                  $backup->{'endTime'},                                  $backup->{'endTime'},
274                                  $backup->{'type'},                                  $backup->{'type'},
275                                  $shareID                                  $shareID,
276                                    $size,
277                          );                          );
278    
279                          print " commit";                          print " commit";
280                          $dbh->commit();                          $dbh->commit();
281    
282                          my $dur = (time() - $t) || 1;                          my $dur = (time() - $t) || 1;
283                          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",
284                                  $nf, $f, $nd, $d,                                  $nf, $f, $nd, $d,
285                                    ($size / 1024 / 1024),
286                                  ( ($f+$d) / $dur ),                                  ( ($f+$d) / $dur ),
287                                  fmt_time($dur)                                  fmt_time($dur)
288                          );                          );
# Line 333  sub found_in_db { Line 338  sub found_in_db {
338                  SELECT 1 FROM files                  SELECT 1 FROM files
339                  WHERE shareID = ? and                  WHERE shareID = ? and
340                          path = ? and                          path = ? and
                         name = ? and  
341                          date = ? and                          date = ? and
342                          size = ?                          size = ?
343          });          });
344    
345          my @param = ($shareID,$path,$name,$date,$size);          my @param = ($shareID,$path,$date,$size);
346          $sth->{file_in_db}->execute(@param);          $sth->{file_in_db}->execute(@param);
347          my $rows = $sth->{file_in_db}->rows;          my $rows = $sth->{file_in_db}->rows;
348          print STDERR "## found_in_db ",( $rows ? '+' : '-' ), join(" ",@param), "\n" if ($debug >= 3);          print STDERR "## found_in_db ",( $rows ? '+' : '-' ), join(" ",@param), "\n" if ($debug >= 3);
# Line 359  sub recurseDir($$$$$$$$) { Line 363  sub recurseDir($$$$$$$$) {
363    
364          print STDERR "\nrecurse($hostname,$backupNum,$share,$dir,$shareID)\n" if ($debug >= 1);          print STDERR "\nrecurse($hostname,$backupNum,$share,$dir,$shareID)\n" if ($debug >= 1);
365    
366          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);
367    
368          { # scope          { # scope
369                  my @stack;                  my @stack;
# Line 369  sub recurseDir($$$$$$$$) { Line 373  sub recurseDir($$$$$$$$) {
373    
374                  # first, add all the entries in current directory                  # first, add all the entries in current directory
375                  foreach my $path_key (keys %{$filesInBackup}) {                  foreach my $path_key (keys %{$filesInBackup}) {
376                            print STDERR "# file ",Dumper($filesInBackup->{$path_key}),"\n" if ($debug >= 3);
377                          my @data = (                          my @data = (
378                                  $shareID,                                  $shareID,
379                                  $backupNum,                                  $backupNum,
# Line 387  sub recurseDir($$$$$$$$) { Line 392  sub recurseDir($$$$$$$$) {
392                                  $filesInBackup->{$path_key}->{'size'}                                  $filesInBackup->{$path_key}->{'size'}
393                          ));                          ));
394    
395                            my $found;
396                          if (! defined($beenThere->{$key}) && ! found_in_db($key, @data)) {                          if (! defined($beenThere->{$key}) && ! ($found = found_in_db($key, @data)) ) {
397                                  print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2);                                  print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2);
398    
399                                  if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {                                  if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
400                                          $new_dirs++;                                          $new_dirs++ unless ($found);
401                                          print STDERR " dir\n" if ($debug >= 2);                                          print STDERR " dir\n" if ($debug >= 2);
402                                  } else {                                  } else {
403                                          $new_files++;                                          $new_files++ unless ($found);
404                                          print STDERR " file\n" if ($debug >= 2);                                          print STDERR " file\n" if ($debug >= 2);
405                                  }                                  }
406                                    $size += $filesInBackup->{$path_key}->{'size'} || 0;
407                          }                          }
408    
409                          if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {                          if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
# Line 422  sub recurseDir($$$$$$$$) { Line 428  sub recurseDir($$$$$$$$) {
428                  print STDERR "## STACK ",join(", ", @stack),"\n" if ($debug >= 2);                  print STDERR "## STACK ",join(", ", @stack),"\n" if ($debug >= 2);
429    
430                  while ( my $dir = shift @stack ) {                  while ( my $dir = shift @stack ) {
431                          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);
432                          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);
433                          $nr_files += $f;                          $nr_files += $f;
434                          $new_files += $nf;                          $new_files += $nf;
435                          $nr_dirs += $d;                          $nr_dirs += $d;
436                          $new_dirs += $nd;                          $new_dirs += $nd;
437                            $size += $s;
438                  }                  }
439          }          }
440    
441          return ($nr_files, $new_files, $nr_dirs, $new_dirs);          return ($nr_files, $new_files, $nr_dirs, $new_dirs, $size);
442  }  }
443    

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

  ViewVC Help
Powered by ViewVC 1.1.26