[Fedora-directory-commits] ldapserver/ldap/admin/src/scripts template-verify-db.pl.in, 1.6, 1.7

Noriko Hosoi (nhosoi) fedora-directory-commits at redhat.com
Wed Mar 21 17:43:00 UTC 2007


Author: nhosoi

Update of /cvs/dirsec/ldapserver/ldap/admin/src/scripts
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv19769

Modified Files:
	template-verify-db.pl.in 
Log Message:
Resolves: #233215
Summary: verify-db.pl still assumes the db dir is always in the instance dir
Changes:
0) eliminated the "current directory" from the utility.  Now, it can be run
from  any location.
1) updated to take a new option [-a <fullpath_to_db_dir> ] to allow specifying
the db dir/changelog dir; by default the start point is "db_dir"
(nsslapd-directory in cn=config,cn=ldbm database,cn=plugins,cn=config)
2) instead of assuming the db dir structure (e.g.,
db/<backend_instance>/<db_files>), now it checks all the db files found under
the specified path.  This allows to run the utility against the backup files,
as well.



Index: template-verify-db.pl.in
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/admin/src/scripts/template-verify-db.pl.in,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- template-verify-db.pl.in	12 Feb 2007 19:55:10 -0000	1.6
+++ template-verify-db.pl.in	21 Mar 2007 17:42:58 -0000	1.7
@@ -38,68 +38,121 @@
 # END COPYRIGHT BLOCK
 #
 
+sub usage
+{
+  print "Usage: $0 [ -a <fullpath_to_db_dir> ]\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 = ();
+  (my $here) = @_;
+  my @dbdirs = ();
 
-    opendir(DIR, $here) or die "can't opendir $here : $!";
-    while (defined($dir = readdir(DIR)))
+  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 . "{{SEP}}" . $file0 )
     {
-        my $thisdir;
-        if ("$here" eq ".")
+      opendir(DIR1, $here . "{{SEP}}" . $file0) or die "can't opendir $file0 : $!";
+      while (defined(my $file1 = readdir(DIR1)))
+      {
+        if ( "$file1" eq "\." || "$file1" eq "\.\." ) 
         {
-            $thisdir = $dir;
+          ;
         }
-        else
+        elsif ( "$file1" eq "DBVERSION" )
         {
-            $thisdir = $here . "{{SEP}}" . $dir;
+          $#dbdirs++;
+          $dbdirs[$#dbdirs] = $here . "{{SEP}}" . $file0;
         }
-        if (-d $thisdir)
+        elsif ( -d $here . "{{SEP}}" . $file0 . "{{SEP}}" . $file1 )
         {
-            if (!($thisdir =~ /\./))
+          opendir(DIR2, $here . "{{SEP}}" . $file0 . "{{SEP}}" . $file1) or die "can't opendir $file1 : $!";
+          while (defined(my $file2 = readdir(DIR2)))
+          {
+            if ( "$file2" eq "\." || "$file2" eq "\.\." ) 
             {
-                opendir(SUBDIR, "$thisdir") or die "can't opendir $thisdir : $!";
-                while (defined($file = readdir(SUBDIR)))
+              ;
+            }
+            elsif ("$file2" eq "DBVERSION")
+            {
+              $#dbdirs++;
+              $dbdirs[$#dbdirs] = $here . "{{SEP}}" . $file0 . "{{SEP}}" . $file1;
+            }
+            elsif ( -d $here . "{{SEP}}" . $file0 . "{{SEP}}" . $file1 . "{{SEP}}" . $file2 )
+            {
+              opendir(DIR3, $here . "{{SEP}}" . $file0 . "{{SEP}}" . $file1 . "{{SEP}}" . $file2) or die "can't opendir $file1 : $!";
+              while (defined(my $file3 = readdir(DIR3)))
+              {
+                if ( "$file3" eq "\." || "$file3" eq "\.\." ) 
+                {
+                  ;
+                }
+                elsif ("$file3" eq "DBVERSION")
                 {
-                    if ($file eq "DBVERSION")
-                    {
-                        $#dbdirs++;
-                        $dbdirs[$#dbdirs] = $thisdir;
-                    }
+                  $#dbdirs++;
+                  $dbdirs[$#dbdirs] = $here . "{{SEP}}" . $file0 . "{{SEP}}" . $file1 . "{{SEP}}" . $file2;
                 }
-                closedir(SUBDIR);
+              }
+              closedir(DIR3);
             }
+          }
+          closedir(DIR2);
         }
+      }
+      closedir(DIR1);
     }
-    closedir(DIR);
+  }
+  closedir(DIR0);
 
-    return \@dbdirs;
+  return \@dbdirs;
 }
 
 sub getLastLogfile
 {
-    (my $here) = @_;
-    my $logfile = "";
+  (my $here) = @_;
+  my $logfile = "";
 
-    opendir(DIR, $here) or die "can't opendir $here : $!";
-    while (defined($file = readdir(DIR)))
+  opendir(DIR, $here) or die "can't opendir $here : $!";
+  while (defined($file = readdir(DIR)))
+  {
+    if ($file =~ /log./)
     {
-        if ($file =~ /log./)
-        {
-            $logfile = $file;
-        }
+      $logfile = $file;
     }
-    closedir(DIR);
+  }
+  closedir(DIR);
 
-    return \$logfile;
+  return \$logfile;
 }
 
 $isWin = -d '\\';
 if ($isWin) {
-	$NULL = "nul";
+  $NULL = "nul";
 } else {
-	$NULL = "/dev/null";
+  $NULL = "/dev/null";
+}
+
+my $i = 0;
+$startpoint = "";
+while ($i <= $#ARGV) {
+  if ( "$ARGV[$i]" eq "-a" ) {  # path to search the db files
+    $i++; $startpoint = $ARGV[$i];
+  } else {
+    &usage; exit(1);
+  }
+  $i++;
 }
 
 print("*****************************************************************\n");
@@ -109,16 +162,24 @@
       "false errors.\n");
 print("*****************************************************************\n");
 
+if ( "$startpoint" eq "" ) {
+  $startpoint = "{{DB-DIR}}";
+}
 # get dirs having DBVERSION
-my $dbdirs = getDbDir(".");
+my $dbdirs = getDbDir($startpoint);
 my $prefix = "{{DS-ROOT}}";
 
 $ENV{'PATH'} = "$prefix at db_bindir@:$prefix/usr/bin:@db_bindir@:/usr/bin";
 $ENV{'LD_LIBRARY_PATH'} = "@db_libdir@:@libdir@";
 $ENV{'SHLIB_PATH'} = "@db_libdir@:@libdir@";
 
-for (my $i = 0; $i < @$dbdirs; $i++)
+# 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 |");
@@ -126,115 +187,65 @@
     my $haserr = 0;
     while ($l = <PRINTLOG>)
     {
-        if ("$l" ne "")
-        {
-            if ($haserr == 0)
-            {
-                print "\n";
-            }
-            print "LOG ERROR: $l";
-            $haserr++;
-        }
+      if ("$l" ne "")
+      {
+        if ($haserr == 0)
+        {
+          print "\n";
+        }
+        print "LOG ERROR: $l";
+        $haserr++;
+      }
     }
     close(PRINTLOG);
     if ($haserr == 0 && $? == 0)
     {
-        print "Good\n";
+      print "Good\n";
     }
     else
     {
-        my $logfile = getLastLogfile($$dbdirs[$i]);
-        print "Log file(s) in $$dbdirs[$i] could be corrupted.\n";
-        print "Please delete a log file $$logfile, and try restarting the server.\n";
+      print "Log file(s) in $$dbdirs[$i] could be corrupted.\n";
+      print "Please delete a log file $$logfile, and try restarting the server.\n";
     }
+  }
 }
 
-for (my $i = 0; $i < @$dbdirs; $i++)
+# Check db files by db_verify
+for (my $i = 0; "$$dbdirs[$i]" ne ""; $i++)
 {
-    # changelog
-    opendir(DB, $$dbdirs[$i]) or die "can't opendir $$dbdirs[$i] : $!";
-    while (defined($db = readdir(DB)))
-    {
-        if ($db =~ /\.db/)
-        {
-            my $thisdb = $$dbdirs[$i] . "{{SEP}}" . $db;
-            print "Verify $thisdb ... ";
-            open(DBVERIFY, "db_verify $thisdb 2>&1 1> $NULL |");
-            sleep 1;
-            my $haserr = 0;
-            while ($l = <DBVERIFY>)
-            {
-                if ($haserr == 0)
-                {
-                    print "\n";
-                }
-                if ("$l" ne "")
-                {
-                    $haserr++;
-                    print "DB ERROR: $l";
-                }
-            }
-            close(DBVERIFY);
-            if ($haserr == 0 && $? == 0)
-            {
-                print "Good\n";
-            }
-            else
-            {
-                print "changelog file $db in $$dbdirs[$i] is corrupted.\n";
-                print "Please restore your backup and recover the database.\n";
-            }
+  opendir(DB, $$dbdirs[$i]) or die "can't opendir $$dbdirs[$i] : $!";
+  while (defined($db = readdir(DB)))
+  {
+    if ($db =~ /\.db/)
+    {
+      my $thisdb = $$dbdirs[$i] . "/" . $db;
+      print "Verify $thisdb ... ";
+      open(DBVERIFY, "db_verify $thisdb 2>&1 1> $NULL |");
+      sleep 1;
+      my $haserr = 0;
+      while ($l = <DBVERIFY>)
+      {
+        if ($haserr == 0)
+        {
+          print "\n";
         }
-    }
-    closedir(DB);
-
-    # backend: get instance dirs under <dbdir>
-    my $instdirs = getDbDir($$dbdirs[$i]);
-
-    for (my $j = 0; $j < @$instdirs; $j++)
-    {
-        opendir(DIR, $$instdirs[$j]) or die "can't opendir $here : $!";
-        while (defined($db = readdir(DIR)))
+        if ("$l" ne "")
         {
-            if ($db =~ /\.db/)
-            {
-                my $thisdb = $$instdirs[$j] . "{{SEP}}" . $db;
-                print "Verify $thisdb ... ";
-                open(DBVERIFY, "db_verify $thisdb 2>&1 1> $NULL |");
-                sleep 1;
-                my $haserr = 0;
-                while ($l = <DBVERIFY>)
-                {
-                    if ($haserr == 0)
-                    {
-                        print "\n";
-                    }
-                    if ("$l" ne "")
-                    {
-                        $haserr++;
-                        print "DB ERROR: $l";
-                    }
-                }
-                close(DBVERIFY);
-                if ($haserr == 0 && $? == 0)
-                {
-                    print "Good\n";
-                }
-                else
-                {
-                    if ("$db" =~ /id2entry.db/)
-                    {
-                        print "Primary db file $db in $$instdirs[$j] is corrupted.\n";
-                        print "Please restore your backup and recover the database.\n";
-                    }
-                    else
-                    {
-                        print "Secondary index file $db in $$instdirs[$j] is corrupted.\n";
-                        print "Please run db2index(.pl) for reindexing.\n";
-                    }
-                }
-            }
+          $haserr++;
+          print "DB ERROR: $l";
         }
-        closedir(DIR);
+      }
+      close(DBVERIFY);
+      if ($haserr == 0 && $? == 0)
+      {
+        print "Good\n";
+      }
+      else
+      {
+        print "db file $db in $$dbdirs[$i] is corrupted.\n";
+        print "Please restore your backup and recover the database.\n";
+      }
     }
+  }
+  closedir(DB);
 }




More information about the Fedora-directory-commits mailing list