/usr/sbin/verify-db is in 389-ds-base 1.3.2.16-0ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | #!/usr/bin/env perl
#
# BEGIN COPYRIGHT BLOCK
# This Program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 2 of the License.
#
# This Program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
#
# In addition, as a special exception, Red Hat, Inc. gives You the additional
# right to link the code of this Program with code not covered under the GNU
# General Public License ("Non-GPL Code") and to distribute linked combinations
# including the two, subject to the limitations in this paragraph. Non-GPL Code
# permitted under this exception must only link to the code of this Program
# through those well defined interfaces identified in the file named EXCEPTION
# found in the source code files (the "Approved Interfaces"). The files of
# Non-GPL Code may instantiate templates or use macros or inline functions from
# the Approved Interfaces without causing the resulting work to be covered by
# the GNU General Public License. Only Red Hat, Inc. may make changes or
# additions to the list of Approved Interfaces. You must obey the GNU General
# Public License in all respects for all of the Program code and other code used
# in conjunction with the Program except the Non-GPL Code covered by this
# exception. If you modify this file, you may extend this exception to your
# version of the file, but you are not obligated to do so. If you do not wish to
# provide this exception without modification, you must delete this exception
# statement from your version and license this file solely under the GPL without
# exception.
#
#
# Copyright (C) 2013 Red Hat, Inc.
# All rights reserved.
# END COPYRIGHT BLOCK
#
use lib qw(/usr/lib/x86_64-linux-gnu/dirsrv/perl);
use DSUtil;
DSUtil::libpath_add("/usr/lib/x86_64-linux-gnu");
DSUtil::libpath_add("/usr/lib/x86_64-linux-gnu");
$ENV{'PATH'} = "/usr/lib/x86_64-linux-gnu/dirsrv/slapd-$servid:/usr/bin:/usr/bin:/";
$ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
my $i = 0;
sub usage
{
print "Usage: verify-db.pl [-Z serverID] [ -a <fullpath_to_db_dir> ] [-h]\n";
}
# getDbDir checks up to 4 levels of db dirs
# e.g., <server_inst_dir>/db/<backend_instance_dir>/<subdir>
sub getDbDir
{
(my $here) = @_;
my @dbdirs = ();
opendir(DIR0, $here) or die "can't opendir $here : $!";
while (defined(my $file0 = readdir(DIR0)))
{
if ( "$file0" eq "\." || "$file0" eq "\.\." )
{
;
}
elsif ( "$file0" eq "DBVERSION" )
{
$#dbdirs++;
$dbdirs[$#dbdirs] = $here;
}
elsif ( -d $here . "/" . $file0 )
{
opendir(DIR1, $here . "/" . $file0) or die "can't opendir $file0 : $!";
while (defined(my $file1 = readdir(DIR1)))
{
if ( "$file1" eq "\." || "$file1" eq "\.\." )
{
;
}
elsif ( "$file1" eq "DBVERSION" )
{
$#dbdirs++;
$dbdirs[$#dbdirs] = $here . "/" . $file0;
}
elsif ( -d $here . "/" . $file0 . "/" . $file1 )
{
opendir(DIR2, $here . "/" . $file0 . "/" . $file1) or die "can't opendir $file1 : $!";
while (defined(my $file2 = readdir(DIR2)))
{
if ( "$file2" eq "\." || "$file2" eq "\.\." )
{
;
}
elsif ("$file2" eq "DBVERSION")
{
$#dbdirs++;
$dbdirs[$#dbdirs] = $here . "/" . $file0 . "/" . $file1;
}
elsif ( -d $here . "/" . $file0 . "/" . $file1 . "/" . $file2 )
{
opendir(DIR3, $here . "/" . $file0 . "/" . $file1 . "/" . $file2) or die "can't opendir $file1 : $!";
while (defined(my $file3 = readdir(DIR3)))
{
if ( "$file3" eq "\." || "$file3" eq "\.\." )
{
;
}
elsif ("$file3" eq "DBVERSION")
{
$#dbdirs++;
$dbdirs[$#dbdirs] = $here . "/" . $file0 . "/" . $file1 . "/" . $file2;
}
}
closedir(DIR3);
}
}
closedir(DIR2);
}
}
closedir(DIR1);
}
}
closedir(DIR0);
return \@dbdirs;
}
sub getLastLogfile
{
(my $here) = @_;
my $logfile = "";
opendir(DIR, $here) or die "can't opendir $here : $!";
while (defined($file = readdir(DIR)))
{
if ($file =~ /log./)
{
$logfile = $file;
}
}
closedir(DIR);
return \$logfile;
}
$isWin = -d '\\';
if ($isWin) {
$NULL = "nul";
} else {
$NULL = "/dev/null";
}
while ($i <= $#ARGV) {
if ( "$ARGV[$i]" eq "-a" ) { # path to search the db files
$i++; $startpoint = $ARGV[$i];
} elsif ( "$ARGV[$i]" eq "-Z" ) { # server instance identifier
$i++; $servid = $ARGV[$i];
} elsif ("$ARGV[$i]" eq "-h") { # help
&usage; exit(0);
} else {
&usage; exit(1);
}
$i++;
}
($servid, $notused_configdir) = DSUtil::get_server_id($servid, "/etc/default");
print("*****************************************************************\n");
print("verify-db: This tool should only be run if recovery start fails\n" .
"and the server is down. If you run this tool while the server is\n" .
"running, you may get false reports of corrupted files or other\n" .
"false errors.\n");
print("*****************************************************************\n");
if ( "$startpoint" eq "" ) {
$startpoint = "/var/lib/dirsrv/slapd-$servid/db";
}
# get dirs having DBVERSION
my $dbdirs = getDbDir($startpoint);
# Check transaction logs by db_printlog
for (my $i = 0; "$$dbdirs[$i]" ne ""; $i++)
{
my $logfile = getLastLogfile($$dbdirs[$i]);
if ( "$$logfile" ne "" )
{
# run db_printlog -h <dbdir> for each <dbdir>
print "Verify log files in $$dbdirs[$i] ... ";
open(PRINTLOG, "db_printlog -h $$dbdirs[$i] 2>&1 1> $NULL |");
sleep 1;
my $haserr = 0;
while ($l = <PRINTLOG>)
{
if ("$l" ne "")
{
if ($haserr == 0)
{
print "\n";
}
print "LOG ERROR: $l";
$haserr++;
}
}
close(PRINTLOG);
if ($haserr == 0 && $? == 0)
{
print "Good\n";
}
else
{
print "Log file(s) in $$dbdirs[$i] could be corrupted.\n";
print "Please delete a log file $$logfile, and try restarting the server.\n";
}
}
}
# Check db files by db_verify
print "Verify db files ... ";
open(DBVERIFY, "/usr/sbin/dbverify -Z $servid 2>&1 1> $NULL |");
sleep 1;
my $bad_index = 0;
my $bad_id2entry = 0;
my $isfirst = 1;
while ($l = <DBVERIFY>)
{
if ($isfirst)
{
print "\n";
$isfirst = 0;
}
if ("$l" =~ /verify failed/)
{
if ("$l" =~ /id2entry.db/)
{
$bad_id2entry++;
}
else
{
$bad_index++;
}
}
print "$l";
}
close(DBVERIFY);
if ($bad_id2entry > 0)
{
print "\nFound the db was corrupted\n";
print "Please restore your backup and recover the database.\n";
exit(1);
}
elsif ($bad_index > 0)
{
print "\nFound the index file(s) was corrupted\n";
print "Please run db2index on the corrupted index\n";
exit(1);
}
else
{
print "Good\n";
exit(0);
}
|