version 1.3, 2006/10/03 18:01:01
|
version 1.6, 2007/01/25 18:05:40
|
Line 8 use GDBM_File;
|
Line 8 use GDBM_File;
|
use File::Find; |
use File::Find; |
use LONCAPA; |
use LONCAPA; |
use LONCAPA::Configuration; |
use LONCAPA::Configuration; |
use Cwd; |
use Fcntl qw(:flock); |
|
|
my $dump_db = '/home/httpd/perl/debug/dump_db_static_32'; |
my $dump_db = '/home/httpd/perl/debug/dump_db_static_32'; |
my $create_db = '/home/httpd/perl/debug/create_db_dynamic'; |
my $create_db = '/home/httpd/perl/debug/create_db_dynamic_64'; |
if (!-x $dump_db || !-x $create_db) { |
if (!-x $dump_db || !-x $create_db) { |
print("Unable to run needed helper programs\n $dump_db\n $create_db\n."); |
print("Unable to run needed helper programs\n $dump_db\n $create_db\n."); |
exit(-1); |
exit(-1); |
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 $skip=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); |
} else { |
|
#print("skip $_\n"); |
|
$skip++; |
|
} |
|
$done++; |
|
if (!($done %100)) { |
|
print("$_\n"); |
|
my $took = time()-$starttime; |
|
my $togo = int(($took/$done) * ($count-$done)); |
|
my $total = $togo+$took; |
|
my $per = ($done-$skip)?$took/($done-$skip):0; |
|
my $last_per = (time()-$last_100_start_time)/100; |
|
printf("%6d (%6d) in %6d, togo %6d, overall %6d, %.3f (each), %.3f\n", |
|
$done,$skip,$took,$togo,$total,$per,$last_per); |
|
$last_100_start_time = time(); |
|
} |
} |
} |
|
|
sub main { |
sub main { |
find( |
my $dir = $perlvar{'lonUsersDir'}; |
{ |
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(); |