/[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 27 by dpavlin, Fri Jul 29 17:31:14 2005 UTC revision 30 by dpavlin, Sun Jul 31 15:59:19 2005 UTC
# Line 9  use Data::Dumper; Line 9  use Data::Dumper;
9  use Getopt::Std;  use Getopt::Std;
10  use constant BPC_FTYPE_DIR => 5;  use constant BPC_FTYPE_DIR => 5;
11    
12    my $debug = 0;
13  $|=1;  $|=1;
14    
15  my $hosts;  my $hosts;
# Line 192  foreach my $host_key (keys %{$hosts}) { Line 193  foreach my $host_key (keys %{$hosts}) {
193                  my ($broj) = $sth->{backups_broj}->fetchrow_array();                  my ($broj) = $sth->{backups_broj}->fetchrow_array();
194                  next if ($broj > 0);                  next if ($broj > 0);
195    
                 $sth->{insert_backups}->execute(  
                         $hostID,  
                         $backupNum,  
                         $backup->{'endTime'},  
                         $backup->{'type'}  
                 );  
                 $dbh->commit();  
   
196                  my $files = BackupPC::View->new($bpc, $hostname, \@backups);                  my $files = BackupPC::View->new($bpc, $hostname, \@backups);
197                  foreach my $share ($files->shareList($backupNum)) {                  foreach my $share ($files->shareList($backupNum)) {
198    
# Line 210  foreach my $host_key (keys %{$hosts}) { Line 203  foreach my $host_key (keys %{$hosts}) {
203                          print " $nf/$f files $nd/$d dirs\n";                          print " $nf/$f files $nd/$d dirs\n";
204                          $dbh->commit();                          $dbh->commit();
205                  }                  }
206    
207                    $sth->{insert_backups}->execute(
208                            $hostID,
209                            $backupNum,
210                            $backup->{'endTime'},
211                            $backup->{'type'}
212                    );
213                    $dbh->commit();
214    
215          }          }
216  }  }
217  undef $sth;  undef $sth;
# Line 271  sub recurseDir($$$$$$$$) { Line 273  sub recurseDir($$$$$$$$) {
273    
274          my ($bpc, $hostname, $backups, $backupNum, $share, $dir, $shareID) = @_;          my ($bpc, $hostname, $backups, $backupNum, $share, $dir, $shareID) = @_;
275    
276          my ($nr_files, $new_files, $nr_dirs, $new_dirs) = (0,0,0,0);          print STDERR "recurse($hostname,$backupNum,$share,$dir,$shareID)\n" if ($debug >= 1);
277    
278          my @stack;          my ($nr_files, $new_files, $nr_dirs, $new_dirs) = (0,0,0,0);
279    
280          { # scope          { # scope
281                    my @stack;
282    
283                  my $files = BackupPC::View->new($bpc, $hostname, $backups);                              my $files = BackupPC::View->new($bpc, $hostname, $backups);            
284                  my $filesInBackup = $files->dirAttrib($backupNum, $share, $dir);                  my $filesInBackup = $files->dirAttrib($backupNum, $share, $dir);
285    
 print STDERR "$hostname: $share | $dir | $backupNum\n";  
   
286                  # first, add all the entries in current directory                  # first, add all the entries in current directory
287                  foreach my $path_key (keys %{$filesInBackup}) {                  foreach my $path_key (keys %{$filesInBackup}) {
288                          my @data = (                          my @data = (
# Line 306  print STDERR "$hostname: $share | $dir | Line 307  print STDERR "$hostname: $share | $dir |
307    
308    
309                          if (! $beenThere->{$key} && ! found_in_db(@data)) {                          if (! $beenThere->{$key} && ! found_in_db(@data)) {
310                                    print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2);
311                                  $sth->{'insert_files'}->execute(@data);                                  $sth->{'insert_files'}->execute(@data);
                                 print STDERR "$key\n";  
312                                  if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {                                  if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
313                                          $new_dirs++;                                          $new_dirs++;
314                                            print STDERR " dir\n" if ($debug >= 2);
315                                  } else {                                  } else {
316                                          $new_files++;                                          $new_files++;
317                                            print STDERR " file\n" if ($debug >= 2);
318                                  }                                  }
319                          }                          }
320                          $beenThere->{$key}++;                          $beenThere->{$key}++;
# Line 319  print STDERR "$hostname: $share | $dir | Line 322  print STDERR "$hostname: $share | $dir |
322                          if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {                          if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
323                                  $nr_dirs++;                                  $nr_dirs++;
324    
325                                  push @stack, [ $bpc, $hostname, $backups, $backupNum, $share, $path_key, $shareID ] unless ($beenThere->{$key});                                  my $full_path = $dir . '/' . $path_key;
326                                    push @stack, $full_path;
327                                    print STDERR "### store to stack: $full_path\n" if ($debug >= 3);
328    
329  #                               my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $backups, $backupNum, $share, $path_key, $shareID) unless ($beenThere->{$key});  #                               my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $backups, $backupNum, $share, $path_key, $shareID) unless ($beenThere->{$key});
330  #  #
331  #                               $nr_files += $f;  #                               $nr_files += $f;
# Line 332  print STDERR "$hostname: $share | $dir | Line 338  print STDERR "$hostname: $share | $dir |
338                          }                          }
339                  }                  }
340    
341          }                  print STDERR "## STACK ",join(", ", @stack),"\n" if ($debug >= 2);
342    
343          foreach my $r (@stack) {                  while ( my $dir = shift @stack ) {
344                  my ($f,$nf,$d,$nd) = recurseDir(@{$r});                          my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $backups, $backupNum, $share, $dir, $shareID);
345                  $nr_files += $f;                          print STDERR "# $dir f: $f nf: $nf d: $d nd: $nd\n" if ($debug >= 1);
346                  $new_files += $nf;                          $nr_files += $f;
347                  $nr_dirs += $d;                          $new_files += $nf;
348                  $new_dirs += $nd;                          $nr_dirs += $d;
349                            $new_dirs += $nd;
350                    }
351          }          }
352    
353          return ($nr_files, $new_files, $nr_dirs, $new_dirs);          return ($nr_files, $new_files, $nr_dirs, $new_dirs);

Legend:
Removed from v.27  
changed lines
  Added in v.30

  ViewVC Help
Powered by ViewVC 1.1.26