/[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 15 by dpavlin, Mon Jul 11 00:07:25 2005 UTC revision 27 by dpavlin, Fri Jul 29 17:31:14 2005 UTC
# Line 81  if ($opt{c}) { Line 81  if ($opt{c}) {
81                  create table files (                  create table files (
82                          ID      INTEGER         NOT NULL PRIMARY KEY,                            ID      INTEGER         NOT NULL PRIMARY KEY,  
83                          shareID INTEGER         NOT NULL references shares(id),                          shareID INTEGER         NOT NULL references shares(id),
84                          backupNum  INTEGER      NOT NULL references backups(id),                          backupNum  INTEGER      NOT NULL references backups(num),
85                          name       VARCHAR(255) NOT NULL,                          name       VARCHAR(255) NOT NULL,
86                          path       VARCHAR(255) NOT NULL,                          path       VARCHAR(255) NOT NULL,
87                          fullpath   VARCHAR(255) NOT NULL,                          fullpath   VARCHAR(255) NOT NULL,
# Line 236  sub getShareID() { Line 236  sub getShareID() {
236                  VALUES (?,?,?,?)                  VALUES (?,?,?,?)
237          });          });
238    
239          $sth->{insert_share}->execute($hostID,$share, $hostname . $share,undef);          my $drop_down = $hostname . '/' . $share;
240            $drop_down =~ s#//+#/#g;
241    
242            $sth->{insert_share}->execute($hostID,$share, $drop_down ,undef);
243          return $dbh->func('last_insert_rowid');                  return $dbh->func('last_insert_rowid');        
244  }  }
245    
# Line 270  sub recurseDir($$$$$$$$) { Line 273  sub recurseDir($$$$$$$$) {
273    
274          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);
275    
276          my $files = BackupPC::View->new($bpc, $hostname, $backups);                      my @stack;
         my $filesInBackup = $files->dirAttrib($backupNum, $share, $dir);  
277    
278          # first, add all the entries in current directory          { # scope
         foreach my $path_key (keys %{$filesInBackup}) {  
                 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'}  
                 );  
279    
280                  my $key = join(" ", (                  my $files = BackupPC::View->new($bpc, $hostname, $backups);            
281                          $shareID,                  my $filesInBackup = $files->dirAttrib($backupNum, $share, $dir);
                         $dir,  
                         $path_key,  
                         $filesInBackup->{$path_key}->{'mtime'},  
                         $filesInBackup->{$path_key}->{'size'}  
                 ));  
282    
283    print STDERR "$hostname: $share | $dir | $backupNum\n";
284    
285                    # first, add all the entries in current directory
286                    foreach my $path_key (keys %{$filesInBackup}) {
287                            my @data = (
288                                    $shareID,
289                                    $backupNum,
290                                    $path_key,
291                                    $filesInBackup->{$path_key}->{'relPath'},
292                                    $filesInBackup->{$path_key}->{'fullPath'},
293            #                       $filesInBackup->{$path_key}->{'sharePathM'},
294                                    $filesInBackup->{$path_key}->{'mtime'},
295                                    $filesInBackup->{$path_key}->{'type'},
296                                    $filesInBackup->{$path_key}->{'size'}
297                            );
298    
299                            my $key = join(" ", (
300                                    $shareID,
301                                    $dir,
302                                    $path_key,
303                                    $filesInBackup->{$path_key}->{'mtime'},
304                                    $filesInBackup->{$path_key}->{'size'}
305                            ));
306    
307    
308                            if (! $beenThere->{$key} && ! found_in_db(@data)) {
309                                    $sth->{'insert_files'}->execute(@data);
310                                    print STDERR "$key\n";
311                                    if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
312                                            $new_dirs++;
313                                    } else {
314                                            $new_files++;
315                                    }
316                            }
317                            $beenThere->{$key}++;
318    
                 if (! $beenThere->{$key} && ! found_in_db(@data)) {  
                         $sth->{'insert_files'}->execute(@data);  
 #                       print STDERR "$key\n";  
319                          if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {                          if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
320                                  $new_dirs++;                                  $nr_dirs++;
321    
322                                    push @stack, [ $bpc, $hostname, $backups, $backupNum, $share, $path_key, $shareID ] unless ($beenThere->{$key});
323    #                               my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $backups, $backupNum, $share, $path_key, $shareID) unless ($beenThere->{$key});
324    #
325    #                               $nr_files += $f;
326    #                               $new_files += $nf;
327    #                               $nr_dirs += $d;
328    #                               $new_dirs += $nd;
329    
330                          } else {                          } else {
331                                  $new_files++;                                  $nr_files++;
332                          }                          }
333                  }                  }
                 $beenThere->{$key}++;  
   
                 if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {  
                         $nr_dirs++;  
   
                         my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $backups, $backupNum, $share, $path_key, $shareID);  
334    
335                          $nr_files += $f;          }
                         $new_files += $nf;  
                         $nr_dirs += $d;  
                         $new_dirs += $nd;  
336    
337                  } else {          foreach my $r (@stack) {
338                          $nr_files++;                  my ($f,$nf,$d,$nd) = recurseDir(@{$r});
339                  }                  $nr_files += $f;
340                    $new_files += $nf;
341                    $nr_dirs += $d;
342                    $new_dirs += $nd;
343          }          }
344    
345          return ($nr_files, $new_files, $nr_dirs, $new_dirs);          return ($nr_files, $new_files, $nr_dirs, $new_dirs);

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

  ViewVC Help
Powered by ViewVC 1.1.26