/[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 29 by dpavlin, Sun Jul 31 12:40:51 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 192  foreach my $host_key (keys %{$hosts}) { Line 192  foreach my $host_key (keys %{$hosts}) {
192                  my ($broj) = $sth->{backups_broj}->fetchrow_array();                  my ($broj) = $sth->{backups_broj}->fetchrow_array();
193                  next if ($broj > 0);                  next if ($broj > 0);
194    
                 $sth->{insert_backups}->execute(  
                         $hostID,  
                         $backupNum,  
                         $backup->{'endTime'},  
                         $backup->{'type'}  
                 );  
                 $dbh->commit();  
   
195                  my $files = BackupPC::View->new($bpc, $hostname, \@backups);                  my $files = BackupPC::View->new($bpc, $hostname, \@backups);
196                  foreach my $share ($files->shareList($backupNum)) {                  foreach my $share ($files->shareList($backupNum)) {
197    
# Line 210  foreach my $host_key (keys %{$hosts}) { Line 202  foreach my $host_key (keys %{$hosts}) {
202                          print " $nf/$f files $nd/$d dirs\n";                          print " $nf/$f files $nd/$d dirs\n";
203                          $dbh->commit();                          $dbh->commit();
204                  }                  }
205    
206                    $sth->{insert_backups}->execute(
207                            $hostID,
208                            $backupNum,
209                            $backup->{'endTime'},
210                            $backup->{'type'}
211                    );
212                    $dbh->commit();
213    
214          }          }
215  }  }
216  undef $sth;  undef $sth;
# Line 236  sub getShareID() { Line 237  sub getShareID() {
237                  VALUES (?,?,?,?)                  VALUES (?,?,?,?)
238          });          });
239    
240          $sth->{insert_share}->execute($hostID,$share, $hostname . $share,undef);          my $drop_down = $hostname . '/' . $share;
241            $drop_down =~ s#//+#/#g;
242    
243            $sth->{insert_share}->execute($hostID,$share, $drop_down ,undef);
244          return $dbh->func('last_insert_rowid');                  return $dbh->func('last_insert_rowid');        
245  }  }
246    
# Line 268  sub recurseDir($$$$$$$$) { Line 272  sub recurseDir($$$$$$$$) {
272    
273          my ($bpc, $hostname, $backups, $backupNum, $share, $dir, $shareID) = @_;          my ($bpc, $hostname, $backups, $backupNum, $share, $dir, $shareID) = @_;
274    
275    #print STDERR "recurse($hostname,$backupNum,$share,$dir,$shareID)\n";
276    
277          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);
278    
279          my $files = BackupPC::View->new($bpc, $hostname, $backups);                      { # scope
280          my $filesInBackup = $files->dirAttrib($backupNum, $share, $dir);                  my @stack;
281    
282          # first, add all the entries in current directory                  my $files = BackupPC::View->new($bpc, $hostname, $backups);            
283          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'}  
                 ));  
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    ##print STDERR "# key: $key [", $beenThere->{$key},"]";
310                                    $sth->{'insert_files'}->execute(@data);
311                                    if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
312                                            $new_dirs++;
313    ##print STDERR " dir\n";
314                                    } else {
315                                            $new_files++;
316    ##print STDERR " file\n";
317                                    }
318                            }
319                            $beenThere->{$key}++;
320    
                 if (! $beenThere->{$key} && ! found_in_db(@data)) {  
                         $sth->{'insert_files'}->execute(@data);  
 #                       print STDERR "$key\n";  
321                          if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {                          if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
322                                  $new_dirs++;                                  $nr_dirs++;
323    
324                                    my $full_path = $dir . '/' . $path_key;
325                                    push @stack, $full_path;
326    ##print STDERR "### store to stack: $full_path\n";
327    
328    #                               my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $backups, $backupNum, $share, $path_key, $shareID) unless ($beenThere->{$key});
329    #
330    #                               $nr_files += $f;
331    #                               $new_files += $nf;
332    #                               $nr_dirs += $d;
333    #                               $new_dirs += $nd;
334    
335                          } else {                          } else {
336                                  $new_files++;                                  $nr_files++;
337                          }                          }
338                  }                  }
                 $beenThere->{$key}++;  
   
                 if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {  
                         $nr_dirs++;  
339    
340                          my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $backups, $backupNum, $share, $path_key, $shareID);  ##print STDERR "# STACK ",join(", ", @stack),"\n";
341    
342                    while ( my $dir = shift @stack ) {
343                            my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $backups, $backupNum, $share, $dir, $shareID);
344    #       print STDERR "## $dir f: $f nf: $nf d: $d nd: $nd\n";
345                          $nr_files += $f;                          $nr_files += $f;
346                          $new_files += $nf;                          $new_files += $nf;
347                          $nr_dirs += $d;                          $nr_dirs += $d;
348                          $new_dirs += $nd;                          $new_dirs += $nd;
   
                 } else {  
                         $nr_files++;  
349                  }                  }
350          }          }
351    

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

  ViewVC Help
Powered by ViewVC 1.1.26