/[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 29 by dpavlin, Sun Jul 31 12:40:51 2005 UTC revision 34 by dpavlin, Sun Jul 31 20:53:40 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 23  my $dbh = DBI->connect($dsn, "", "", { R Line 24  my $dbh = DBI->connect($dsn, "", "", { R
24    
25  my %opt;  my %opt;
26    
27  if ( !getopts("cdm:", \%opt ) ) {  if ( !getopts("cdm:v", \%opt ) ) {
28          print STDERR <<EOF;          print STDERR <<EOF;
29  usage: $0 [-c|-d] [-m num]  usage: $0 [-c|-d] [-m num]
30    
# Line 122  if ($opt{d}) { Line 123  if ($opt{d}) {
123          print " done...\n";          print " done...\n";
124  }  }
125    
126    if ($opt{v}) {
127            print "Debug level at $opt{v}\n";
128            $debug = $opt{v};
129    }
130    
131  #################################INSERT VALUES#############################  #################################INSERT VALUES#############################
132    
133  # get hosts  # get hosts
# Line 192  foreach my $host_key (keys %{$hosts}) { Line 198  foreach my $host_key (keys %{$hosts}) {
198                  my ($broj) = $sth->{backups_broj}->fetchrow_array();                  my ($broj) = $sth->{backups_broj}->fetchrow_array();
199                  next if ($broj > 0);                  next if ($broj > 0);
200    
201                  my $files = BackupPC::View->new($bpc, $hostname, \@backups);                  my $files = BackupPC::View->new($bpc, $hostname, \@backups, 1);
202                  foreach my $share ($files->shareList($backupNum)) {                  foreach my $share ($files->shareList($backupNum)) {
203    
204                          print "\t$share";                          print "\t$share";
# Line 272  sub recurseDir($$$$$$$$) { Line 278  sub recurseDir($$$$$$$$) {
278    
279          my ($bpc, $hostname, $backups, $backupNum, $share, $dir, $shareID) = @_;          my ($bpc, $hostname, $backups, $backupNum, $share, $dir, $shareID) = @_;
280    
281  #print STDERR "recurse($hostname,$backupNum,$share,$dir,$shareID)\n";          print STDERR "recurse($hostname,$backupNum,$share,$dir,$shareID)\n" if ($debug >= 1);
282    
283          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);
284    
285          { # scope          { # scope
286                  my @stack;                  my @stack;
287    
288                  my $files = BackupPC::View->new($bpc, $hostname, $backups);                              my $files = BackupPC::View->new($bpc, $hostname, $backups, 1);
289                  my $filesInBackup = $files->dirAttrib($backupNum, $share, $dir);                  my $filesInBackup = $files->dirAttrib($backupNum, $share, $dir);
290    
291                  # first, add all the entries in current directory                  # first, add all the entries in current directory
# Line 306  sub recurseDir($$$$$$$$) { Line 312  sub recurseDir($$$$$$$$) {
312    
313    
314                          if (! $beenThere->{$key} && ! found_in_db(@data)) {                          if (! $beenThere->{$key} && ! found_in_db(@data)) {
315  ##print STDERR "# key: $key [", $beenThere->{$key},"]";                                  print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2);
316                                  $sth->{'insert_files'}->execute(@data);                                  $sth->{'insert_files'}->execute(@data);
317                                  if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {                                  if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
318                                          $new_dirs++;                                          $new_dirs++;
319  ##print STDERR " dir\n";                                          print STDERR " dir\n" if ($debug >= 2);
320                                  } else {                                  } else {
321                                          $new_files++;                                          $new_files++;
322  ##print STDERR " file\n";                                          print STDERR " file\n" if ($debug >= 2);
323                                  }                                  }
324                          }                          }
325                          $beenThere->{$key}++;                          $beenThere->{$key}++;
# Line 323  sub recurseDir($$$$$$$$) { Line 329  sub recurseDir($$$$$$$$) {
329    
330                                  my $full_path = $dir . '/' . $path_key;                                  my $full_path = $dir . '/' . $path_key;
331                                  push @stack, $full_path;                                  push @stack, $full_path;
332  ##print STDERR "### store to stack: $full_path\n";                                  print STDERR "### store to stack: $full_path\n" if ($debug >= 3);
333    
334  #                               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});
335  #  #
# Line 337  sub recurseDir($$$$$$$$) { Line 343  sub recurseDir($$$$$$$$) {
343                          }                          }
344                  }                  }
345    
346  ##print STDERR "# STACK ",join(", ", @stack),"\n";                  print STDERR "## STACK ",join(", ", @stack),"\n" if ($debug >= 2);
347    
348                  while ( my $dir = shift @stack ) {                  while ( my $dir = shift @stack ) {
349                          my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $backups, $backupNum, $share, $dir, $shareID);                          my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $backups, $backupNum, $share, $dir, $shareID);
350  #       print STDERR "## $dir f: $f nf: $nf d: $d nd: $nd\n";                          print STDERR "# $dir f: $f nf: $nf d: $d nd: $nd\n" if ($debug >= 1);
351                          $nr_files += $f;                          $nr_files += $f;
352                          $new_files += $nf;                          $new_files += $nf;
353                          $nr_dirs += $d;                          $nr_dirs += $d;

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

  ViewVC Help
Powered by ViewVC 1.1.26