/[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 18 by dpavlin, Mon Jul 11 14:31:51 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 236  sub getShareID() { Line 238  sub getShareID() {
238                  VALUES (?,?,?,?)                  VALUES (?,?,?,?)
239          });          });
240    
241          $sth->{insert_share}->execute($hostID,$share, $hostname . $share,undef);          my $drop_down = $hostname . '/' . $share;
242            $drop_down =~ s#//+#/#g;
243    
244            $sth->{insert_share}->execute($hostID,$share, $drop_down ,undef);
245          return $dbh->func('last_insert_rowid');                  return $dbh->func('last_insert_rowid');        
246  }  }
247    
# Line 268  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            print STDERR "recurse($hostname,$backupNum,$share,$dir,$shareID)\n" if ($debug >= 1);
277    
278          my ($nr_files, $new_files, $nr_dirs, $new_dirs) = (0,0,0,0);          my ($nr_files, $new_files, $nr_dirs, $new_dirs) = (0,0,0,0);
279    
280          my $files = BackupPC::View->new($bpc, $hostname, $backups);                      { # scope
281          my $filesInBackup = $files->dirAttrib($backupNum, $share, $dir);                  my @stack;
282    
283          # first, add all the entries in current directory                  my $files = BackupPC::View->new($bpc, $hostname, $backups);            
284          foreach my $path_key (keys %{$filesInBackup}) {                  my $filesInBackup = $files->dirAttrib($backupNum, $share, $dir);
                 my @data = (  
                         $shareID,  
                         $backupNum,  
                         $path_key,  
                         $filesInBackup->{$path_key}->{'relPath'},  
                         $filesInBackup->{$path_key}->{'fullPath'},  
 #                       $filesInBackup->{$path_key}->{'sharePathM'},  
                         $filesInBackup->{$path_key}->{'mtime'},  
                         $filesInBackup->{$path_key}->{'type'},  
                         $filesInBackup->{$path_key}->{'size'}  
                 );  
   
                 my $key = join(" ", (  
                         $shareID,  
                         $dir,  
                         $path_key,  
                         $filesInBackup->{$path_key}->{'mtime'},  
                         $filesInBackup->{$path_key}->{'size'}  
                 ));  
285    
286                    # first, add all the entries in current directory
287                    foreach my $path_key (keys %{$filesInBackup}) {
288                            my @data = (
289                                    $shareID,
290                                    $backupNum,
291                                    $path_key,
292                                    $filesInBackup->{$path_key}->{'relPath'},
293                                    $filesInBackup->{$path_key}->{'fullPath'},
294            #                       $filesInBackup->{$path_key}->{'sharePathM'},
295                                    $filesInBackup->{$path_key}->{'mtime'},
296                                    $filesInBackup->{$path_key}->{'type'},
297                                    $filesInBackup->{$path_key}->{'size'}
298                            );
299    
300                            my $key = join(" ", (
301                                    $shareID,
302                                    $dir,
303                                    $path_key,
304                                    $filesInBackup->{$path_key}->{'mtime'},
305                                    $filesInBackup->{$path_key}->{'size'}
306                            ));
307    
308    
309                            if (! $beenThere->{$key} && ! found_in_db(@data)) {
310                                    print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2);
311                                    $sth->{'insert_files'}->execute(@data);
312                                    if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
313                                            $new_dirs++;
314                                            print STDERR " dir\n" if ($debug >= 2);
315                                    } else {
316                                            $new_files++;
317                                            print STDERR " file\n" if ($debug >= 2);
318                                    }
319                            }
320                            $beenThere->{$key}++;
321    
                 if (! $beenThere->{$key} && ! found_in_db(@data)) {  
                         $sth->{'insert_files'}->execute(@data);  
 #                       print STDERR "$key\n";  
322                          if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {                          if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
323                                  $new_dirs++;                                  $nr_dirs++;
324    
325                                    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});
330    #
331    #                               $nr_files += $f;
332    #                               $new_files += $nf;
333    #                               $nr_dirs += $d;
334    #                               $new_dirs += $nd;
335    
336                          } else {                          } else {
337                                  $new_files++;                                  $nr_files++;
338                          }                          }
339                  }                  }
                 $beenThere->{$key}++;  
   
                 if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {  
                         $nr_dirs++;  
340    
341                          my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $backups, $backupNum, $share, $path_key, $shareID);                  print STDERR "## STACK ",join(", ", @stack),"\n" if ($debug >= 2);
342    
343                    while ( my $dir = shift @stack ) {
344                            my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $backups, $backupNum, $share, $dir, $shareID);
345                            print STDERR "# $dir f: $f nf: $nf d: $d nd: $nd\n" if ($debug >= 1);
346                          $nr_files += $f;                          $nr_files += $f;
347                          $new_files += $nf;                          $new_files += $nf;
348                          $nr_dirs += $d;                          $nr_dirs += $d;
349                          $new_dirs += $nd;                          $new_dirs += $nd;
   
                 } else {  
                         $nr_files++;  
350                  }                  }
351          }          }
352    

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

  ViewVC Help
Powered by ViewVC 1.1.26