Mail-SpamCannibal
view release on metacpan or search on metacpan
scripts/sc_recoverdb.pl view on Meta::CPAN
push @{$default{txtfile}}, $newfile;
}
} else {
$default{dbfile} = [$dbfile,$newfile];
unless ($VERIFY) {
push @{$default{dbfile}}, $newfile;
}
}
my @evfiles;
unless ($VERIFY) {
opendir(D,$environment) or die "could not open db environment directory $environment\n\n";
my @jobs = grep(/\.pid$/,readdir(D));
@evfiles = grep(/^__/,readdir(D));
closedir D;
foreach (@jobs) {
die "running DB jobs, stop all DB jobs before recovery of DB files\n\n"
if is_running($environment .'/'. $_);
}
dbjob_recover(\%default);
}
my $tool = new IPTables::IPv4::DBTarpit::Tools(%default) ||
die "could not open database ${environment}/$dbfile\n\n";
my $recno = 1;
print STDERR ($VERIFY) ? 'verifying ' : 'checking ';
print STDERR "\t",$tool->nkeys($dbfile), " records...\n";
while (1) {
my($key,$txt) = $tool->getrecno($dbfile,$recno);
if ($key) {
print STDERR "$recno\t ", inet_ntoa($key), "\n" if $DEBUG;
$tool->put($newfile,$key,$txt) unless $VERIFY
}
else {
last if $recno >= $tool->nkeys($dbfile);
print "bad record $recno\t ", db_strerror($DBTP_ERROR),"\n";
}
++$recno;
}
--$recno;
my $records = $tool->nkeys($dbfile);
if ($VERIFY) {
print STDERR "verified\t$recno records\n";
print STDERR "ERROR: found $records in $dbfile\n"
unless $records == $recno;
} else {
print STDERR "$dbfile $recno -> $newfile ",$tool->nkeys($newfile),"\n";
}
$tool->closedb;
unless ($VERIFY) {
$_ = $environment .'/'. $dbfile;
my($mode,$uid,$gid) = (stat($environment .'/'. $dbfile))[2,4,5];
$mode &= 0777;
chmod $mode, $environment .'/'. $newfile;
chown $uid, $gid, $environment .'/'. $newfile;
foreach (0..$#evfiles) {
$evfiles[$_] = $environment .'/'. $evfiles[$_];
}
unlink @evfiles; # delete environment
}
( run in 0.699 second using v1.01-cache-2.11-cpan-71847e10f99 )