template-verify-db.pl 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. #{{PERL-EXEC}}
  2. #
  3. # BEGIN COPYRIGHT BLOCK
  4. # This Program is free software; you can redistribute it and/or modify it under
  5. # the terms of the GNU General Public License as published by the Free Software
  6. # Foundation; version 2 of the License.
  7. #
  8. # This Program is distributed in the hope that it will be useful, but WITHOUT
  9. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License along with
  13. # this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  14. # Place, Suite 330, Boston, MA 02111-1307 USA.
  15. #
  16. # In addition, as a special exception, Red Hat, Inc. gives You the additional
  17. # right to link the code of this Program with code not covered under the GNU
  18. # General Public License ("Non-GPL Code") and to distribute linked combinations
  19. # including the two, subject to the limitations in this paragraph. Non-GPL Code
  20. # permitted under this exception must only link to the code of this Program
  21. # through those well defined interfaces identified in the file named EXCEPTION
  22. # found in the source code files (the "Approved Interfaces"). The files of
  23. # Non-GPL Code may instantiate templates or use macros or inline functions from
  24. # the Approved Interfaces without causing the resulting work to be covered by
  25. # the GNU General Public License. Only Red Hat, Inc. may make changes or
  26. # additions to the list of Approved Interfaces. You must obey the GNU General
  27. # Public License in all respects for all of the Program code and other code used
  28. # in conjunction with the Program except the Non-GPL Code covered by this
  29. # exception. If you modify this file, you may extend this exception to your
  30. # version of the file, but you are not obligated to do so. If you do not wish to
  31. # provide this exception without modification, you must delete this exception
  32. # statement from your version and license this file solely under the GPL without
  33. # exception.
  34. #
  35. #
  36. # Copyright (C) 2005 Red Hat, Inc.
  37. # All rights reserved.
  38. # END COPYRIGHT BLOCK
  39. #
  40. sub getDbDir
  41. {
  42. (my $here) = @_;
  43. my @dbdirs = ();
  44. opendir(DIR, $here) or die "can't opendir $here : $!";
  45. while (defined($dir = readdir(DIR)))
  46. {
  47. my $thisdir;
  48. if ("$here" eq ".")
  49. {
  50. $thisdir = $dir;
  51. }
  52. else
  53. {
  54. $thisdir = $here . "{{SEP}}" . $dir;
  55. }
  56. if (-d $thisdir)
  57. {
  58. if (!($thisdir =~ /\./))
  59. {
  60. opendir(SUBDIR, "$thisdir") or die "can't opendir $thisdir : $!";
  61. while (defined($file = readdir(SUBDIR)))
  62. {
  63. if ($file eq "DBVERSION")
  64. {
  65. $#dbdirs++;
  66. $dbdirs[$#dbdirs] = $thisdir;
  67. }
  68. }
  69. closedir(SUBDIR);
  70. }
  71. }
  72. }
  73. closedir(DIR);
  74. return \@dbdirs;
  75. }
  76. sub getLastLogfile
  77. {
  78. (my $here) = @_;
  79. my $logfile = "";
  80. opendir(DIR, $here) or die "can't opendir $here : $!";
  81. while (defined($file = readdir(DIR)))
  82. {
  83. if ($file =~ /log./)
  84. {
  85. $logfile = $file;
  86. }
  87. }
  88. closedir(DIR);
  89. return \$logfile;
  90. }
  91. $isWin = -d '\\';
  92. if ($isWin) {
  93. $NULL = "nul";
  94. } else {
  95. $NULL = "/dev/null";
  96. }
  97. print("*****************************************************************\n");
  98. print("verify-db: This tool should only be run if recovery start fails\n" .
  99. "and the server is down. If you run this tool while the server is\n" .
  100. "running, you may get false reports of corrupted files or other\n" .
  101. "false errors.\n");
  102. print("*****************************************************************\n");
  103. # get dirs having DBVERSION
  104. my $dbdirs = getDbDir(".");
  105. my $brand_ds = {{DS-BRAND}};
  106. $ENV{'PATH'} = '$prefix/usr/bin:$prefix/usr/lib:/usr/bin:/usr/lib';
  107. $ENV{'LD_LIBRARY_PATH'} = ':/usr/lib';
  108. $ENV{'SHLIB_PATH'} = ':/usr/lib';
  109. for (my $i = 0; $i < @$dbdirs; $i++)
  110. {
  111. # run db_printlog -h <dbdir> for each <dbdir>
  112. print "Verify log files in $$dbdirs[$i] ... ";
  113. open(PRINTLOG, "db_printlog -h $$dbdirs[$i] 2>&1 1> $NULL |");
  114. sleep 1;
  115. my $haserr = 0;
  116. while ($l = <PRINTLOG>)
  117. {
  118. if ("$l" ne "")
  119. {
  120. if ($haserr == 0)
  121. {
  122. print "\n";
  123. }
  124. print "LOG ERROR: $l";
  125. $haserr++;
  126. }
  127. }
  128. close(PRINTLOG);
  129. if ($haserr == 0 && $? == 0)
  130. {
  131. print "Good\n";
  132. }
  133. else
  134. {
  135. my $logfile = getLastLogfile($$dbdirs[$i]);
  136. print "Log file(s) in $$dbdirs[$i] could be corrupted.\n";
  137. print "Please delete a log file $$logfile, and try restarting the server.\n";
  138. }
  139. }
  140. for (my $i = 0; $i < @$dbdirs; $i++)
  141. {
  142. # changelog
  143. opendir(DB, $$dbdirs[$i]) or die "can't opendir $$dbdirs[$i] : $!";
  144. while (defined($db = readdir(DB)))
  145. {
  146. if ($db =~ /\.db/)
  147. {
  148. my $thisdb = $$dbdirs[$i] . "{{SEP}}" . $db;
  149. print "Verify $thisdb ... ";
  150. open(DBVERIFY, "db_verify $thisdb 2>&1 1> $NULL |");
  151. sleep 1;
  152. my $haserr = 0;
  153. while ($l = <DBVERIFY>)
  154. {
  155. if ($haserr == 0)
  156. {
  157. print "\n";
  158. }
  159. if ("$l" ne "")
  160. {
  161. $haserr++;
  162. print "DB ERROR: $l";
  163. }
  164. }
  165. close(DBVERIFY);
  166. if ($haserr == 0 && $? == 0)
  167. {
  168. print "Good\n";
  169. }
  170. else
  171. {
  172. print "changelog file $db in $$dbdirs[$i] is corrupted.\n";
  173. print "Please restore your backup and recover the database.\n";
  174. }
  175. }
  176. }
  177. closedir(DB);
  178. # backend: get instance dirs under <dbdir>
  179. my $instdirs = getDbDir($$dbdirs[$i]);
  180. for (my $j = 0; $j < @$instdirs; $j++)
  181. {
  182. opendir(DIR, $$instdirs[$j]) or die "can't opendir $here : $!";
  183. while (defined($db = readdir(DIR)))
  184. {
  185. if ($db =~ /\.db/)
  186. {
  187. my $thisdb = $$instdirs[$j] . "{{SEP}}" . $db;
  188. print "Verify $thisdb ... ";
  189. open(DBVERIFY, "db_verify $thisdb 2>&1 1> $NULL |");
  190. sleep 1;
  191. my $haserr = 0;
  192. while ($l = <DBVERIFY>)
  193. {
  194. if ($haserr == 0)
  195. {
  196. print "\n";
  197. }
  198. if ("$l" ne "")
  199. {
  200. $haserr++;
  201. print "DB ERROR: $l";
  202. }
  203. }
  204. close(DBVERIFY);
  205. if ($haserr == 0 && $? == 0)
  206. {
  207. print "Good\n";
  208. }
  209. else
  210. {
  211. if ("$db" =~ /id2entry.db/)
  212. {
  213. print "Primary db file $db in $$instdirs[$j] is corrupted.\n";
  214. print "Please restore your backup and recover the database.\n";
  215. }
  216. else
  217. {
  218. print "Secondary index file $db in $$instdirs[$j] is corrupted.\n";
  219. print "Please run db2index(.pl) for reindexing.\n";
  220. }
  221. }
  222. }
  223. }
  224. closedir(DIR);
  225. }
  226. }