Diff for /loncom/debugging_tools/db_copy.pl between versions 1.3 and 1.4

version 1.3, 2006/10/03 18:01:01 version 1.4, 2006/10/13 18:34:07
Line 19  if (!-x $dump_db || !-x $create_db) { Line 19  if (!-x $dump_db || !-x $create_db) {
   
 my  %perlvar=%{&LONCAPA::Configuration::read_conf('loncapa.conf')};  my  %perlvar=%{&LONCAPA::Configuration::read_conf('loncapa.conf')};
   
   my $do_locks = 1;
 {  {
     my $straight;  
     sub lock_db {      sub lock_db {
  my ($fname) = @_;          my ($fname) = @_;
  my $dbref;          my $sym;
  $fname = &Cwd::abs_path($fname);          if ($do_locks) {
  if ($fname =~ m/^\Q$perlvar{'lonUsersDir'}\E/) {              open($sym,">>$fname.lock");
     $dbref=&LONCAPA::locking_hash_tie($fname,&GDBM_READER());              flock($sym,(LOCK_EX));
     $straight=0;          }
  } else {          return $sym;
     if (tie(my %db,'GDBM_File',$fname,&GDBM_READER(),0640)) {  
  $dbref = \%db;  
     }  
     $straight=1;  
  }  
  return $dbref;  
     }      }
   
     sub unlock_db {      sub unlock_db {
  my ($dbref) = @_;          my ($sym) = @_;
  if ($straight) {          if (ref($sym)) {
     untie($dbref);              flock($sym,(LOCK_UN));
  } else {          }
     &LONCAPA::locking_hash_untie($dbref);  
  }  
     }      }
 }  }
   
   my $count=0;
   sub count_db {
       return if ($_!~m/\.db$/);
       $count++;
   }
   
   my $done=0;
   my $starttime;
   my $last_100_start_time;
 sub process_db {  sub process_db {
     return if ($_!~m/\.db$/);      return if ($_!~m/\.db$/);
     my $file = $_;      if (!-e "$_.old") {
     my $dbref =&lock_db($file);   my $file = $_;
     print("attempting $file\n");   my $dbref =&lock_db($file);
     my %newdb;   #print("attempting $file\n");
     my $new_file = $file.'.new';   system("$dump_db -f $file|$create_db -f $file.new");
     system("$dump_db -f $file|$create_db -f $new_file");  
 #    print("finishing $dbref\n");  #    print("finishing $dbref\n");
     untie($dbref);   rename($file,"$file.old");
     system("/bin/mv $file $file.old");   rename("$file.new","$file");
     system("/bin/mv $file.new $file");   &unlock_db($dbref);
     &unlock_db($dbref);      }
       $done++;
       if (!($done %100)) {
           print("$_\n");
           my $took = time()-$starttime;
           my $togo = int(($took/$done) * ($count-$done));
           my $total = $togo+$took;
           my $per = $took/$done;
           my $last_per = (time()-$last_100_start_time)/100;
           printf("%6d in %6d, togo %6d, overall %6d, %.4f (for one), %.4f)\n",
          $done,$took,$togo,$total,$per,$last_per);
           $last_100_start_time = time();
       }
 }  }
   
 sub main {  sub main {
     find(      my $dir = $perlvar{'lonUsersDir'}.'/temp/y/';
  {      print("Doing $dir\n");
      no_chdir   => 1,      &find({ no_chdir   => 1,
      wanted     => \&process_db,              wanted     => \&count_db, },
  },             $dir);
  $perlvar{'lonUsersDir'}      print("Found $count db to do\n");
  );      $last_100_start_time = $starttime = time();
       &find({ no_chdir   => 1,
               wanted     => \&process_db, },
             $dir);
   
 }  }
   
 &main();  &main();

Removed from v.1.3  
changed lines
  Added in v.1.4


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>