/[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 37 by dpavlin, Fri Aug 19 14:57:30 2005 UTC
# Line 7  use BackupPC::Lib; Line 7  use BackupPC::Lib;
7  use BackupPC::View;  use BackupPC::View;
8  use Data::Dumper;  use Data::Dumper;
9  use Getopt::Std;  use Getopt::Std;
10    use Time::HiRes qw/time/;
11    use POSIX qw/strftime/;
12  use constant BPC_FTYPE_DIR => 5;  use constant BPC_FTYPE_DIR => 5;
13    
14    my $debug = 0;
15  $|=1;  $|=1;
16    
17    my $t_fmt = '%Y-%m-%d %H:%M:%S';
18    
19  my $hosts;  my $hosts;
20  my $bpc = BackupPC::Lib->new || die;  my $bpc = BackupPC::Lib->new || die;
21  my %Conf = $bpc->Conf();  my %Conf = $bpc->Conf();
# Line 23  my $dbh = DBI->connect($dsn, "", "", { R Line 28  my $dbh = DBI->connect($dsn, "", "", { R
28    
29  my %opt;  my %opt;
30    
31  if ( !getopts("cdm:", \%opt ) ) {  if ( !getopts("cdm:v", \%opt ) ) {
32          print STDERR <<EOF;          print STDERR <<EOF;
33  usage: $0 [-c|-d] [-m num]  usage: $0 [-c|-d] [-m num]
34    
# Line 122  if ($opt{d}) { Line 127  if ($opt{d}) {
127          print " done...\n";          print " done...\n";
128  }  }
129    
130    if ($opt{v}) {
131            print "Debug level at $opt{v}\n";
132            $debug = $opt{v};
133    }
134    
135  #################################INSERT VALUES#############################  #################################INSERT VALUES#############################
136    
137  # get hosts  # get hosts
# Line 186  foreach my $host_key (keys %{$hosts}) { Line 196  foreach my $host_key (keys %{$hosts}) {
196                  my $backupNum = $backup->{'num'};                  my $backupNum = $backup->{'num'};
197                  my @backupShares = ();                  my @backupShares = ();
198    
199                  print $hosts->{$host_key}->{'host'},"\t#$backupNum\n";                  print $hosts->{$host_key}->{'host'}, "\t#$backupNum\n";
200    
201                  $sth->{backups_broj}->execute($hostID, $backupNum);                  $sth->{backups_broj}->execute($hostID, $backupNum);
202                  my ($broj) = $sth->{backups_broj}->fetchrow_array();                  my ($broj) = $sth->{backups_broj}->fetchrow_array();
203                  next if ($broj > 0);                  next if ($broj > 0);
204    
205                    my $files = BackupPC::View->new($bpc, $hostname, \@backups, 1);
206                    foreach my $share ($files->shareList($backupNum)) {
207    
208                            my $t = time();
209    
210                            print strftime($t_fmt,localtime())," ", $share;
211                            $shareID = getShareID($share, $hostID, $hostname);
212                    
213                            my ($f, $nf, $d, $nd) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);
214                            printf(" %d/%d files %d/%d dirs [%.2f/s]\n",
215                                    $nf, $f, $nd, $d,
216                                    ( ($f+$d) / ((time() - $t) || 1) )
217                            );
218                            $dbh->commit();
219                    }
220    
221                  $sth->{insert_backups}->execute(                  $sth->{insert_backups}->execute(
222                          $hostID,                          $hostID,
223                          $backupNum,                          $backupNum,
# Line 200  foreach my $host_key (keys %{$hosts}) { Line 226  foreach my $host_key (keys %{$hosts}) {
226                  );                  );
227                  $dbh->commit();                  $dbh->commit();
228    
                 my $files = BackupPC::View->new($bpc, $hostname, \@backups);  
                 foreach my $share ($files->shareList($backupNum)) {  
   
                         print "\t$share";  
                         $shareID = getShareID($share, $hostID, $hostname);  
                   
                         my ($f, $nf, $d, $nd) = recurseDir($bpc, $hostname, \@backups, $backupNum, $share, "", $shareID);  
                         print " $nf/$f files $nd/$d dirs\n";  
                         $dbh->commit();  
                 }  
229          }          }
230  }  }
231  undef $sth;  undef $sth;
# Line 269  sub found_in_db { Line 285  sub found_in_db {
285  ####################################################  ####################################################
286  sub recurseDir($$$$$$$$) {  sub recurseDir($$$$$$$$) {
287    
288          my ($bpc, $hostname, $backups, $backupNum, $share, $dir, $shareID) = @_;          my ($bpc, $hostname, $files, $backupNum, $share, $dir, $shareID) = @_;
289    
290          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);
291    
292          my @stack;          my ($nr_files, $new_files, $nr_dirs, $new_dirs) = (0,0,0,0);
293    
294          { # scope          { # scope
295                    my @stack;
296    
                 my $files = BackupPC::View->new($bpc, $hostname, $backups);              
297                  my $filesInBackup = $files->dirAttrib($backupNum, $share, $dir);                  my $filesInBackup = $files->dirAttrib($backupNum, $share, $dir);
298    
 print STDERR "$hostname: $share | $dir | $backupNum\n";  
   
299                  # first, add all the entries in current directory                  # first, add all the entries in current directory
300                  foreach my $path_key (keys %{$filesInBackup}) {                  foreach my $path_key (keys %{$filesInBackup}) {
301                          my @data = (                          my @data = (
# Line 306  print STDERR "$hostname: $share | $dir | Line 320  print STDERR "$hostname: $share | $dir |
320    
321    
322                          if (! $beenThere->{$key} && ! found_in_db(@data)) {                          if (! $beenThere->{$key} && ! found_in_db(@data)) {
323                                    print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2);
324                                  $sth->{'insert_files'}->execute(@data);                                  $sth->{'insert_files'}->execute(@data);
                                 print STDERR "$key\n";  
325                                  if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {                                  if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
326                                          $new_dirs++;                                          $new_dirs++;
327                                            print STDERR " dir\n" if ($debug >= 2);
328                                  } else {                                  } else {
329                                          $new_files++;                                          $new_files++;
330                                            print STDERR " file\n" if ($debug >= 2);
331                                  }                                  }
332                          }                          }
333                          $beenThere->{$key}++;                          $beenThere->{$key}++;
# Line 319  print STDERR "$hostname: $share | $dir | Line 335  print STDERR "$hostname: $share | $dir |
335                          if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {                          if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
336                                  $nr_dirs++;                                  $nr_dirs++;
337    
338                                  push @stack, [ $bpc, $hostname, $backups, $backupNum, $share, $path_key, $shareID ] unless ($beenThere->{$key});                                  my $full_path = $dir . '/' . $path_key;
339                                    push @stack, $full_path;
340                                    print STDERR "### store to stack: $full_path\n" if ($debug >= 3);
341    
342  #                               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});
343  #  #
344  #                               $nr_files += $f;  #                               $nr_files += $f;
# Line 332  print STDERR "$hostname: $share | $dir | Line 351  print STDERR "$hostname: $share | $dir |
351                          }                          }
352                  }                  }
353    
354          }                  print STDERR "## STACK ",join(", ", @stack),"\n" if ($debug >= 2);
355    
356          foreach my $r (@stack) {                  while ( my $dir = shift @stack ) {
357                  my ($f,$nf,$d,$nd) = recurseDir(@{$r});                          my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $files, $backupNum, $share, $dir, $shareID);
358                  $nr_files += $f;                          print STDERR "# $dir f: $f nf: $nf d: $d nd: $nd\n" if ($debug >= 1);
359                  $new_files += $nf;                          $nr_files += $f;
360                  $nr_dirs += $d;                          $new_files += $nf;
361                  $new_dirs += $nd;                          $nr_dirs += $d;
362                            $new_dirs += $nd;
363                    }
364          }          }
365    
366          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.37

  ViewVC Help
Powered by ViewVC 1.1.26