1 8 9 package com.sleepycat.je.util; 10 11 import java.io.File ; 12 13 import com.sleepycat.je.dbi.EnvironmentImpl; 14 import com.sleepycat.je.utilint.CmdUtil; 15 16 20 public class DbRecover { 21 22 public static void main(String [] argv) { 23 try { 24 int whichArg = 0; 25 boolean seenFile = false; 26 boolean seenOffset = false; 27 28 long truncateFileNum = -1; 29 long truncateOffset = -1; 30 31 37 File envHome = new File ("."); while (whichArg < argv.length) { 39 String nextArg = argv[whichArg]; 40 41 if (nextArg.equals("-h")) { 42 whichArg++; 43 envHome = new File (CmdUtil.getArg(argv, whichArg)); 44 } else if (nextArg.equals("-f")) { 45 whichArg++; 46 truncateFileNum = 47 CmdUtil.readLongNumber(CmdUtil.getArg(argv, whichArg)); 48 seenFile = true; 49 } else if (nextArg.equals("-o")) { 50 whichArg++; 51 truncateOffset = 52 CmdUtil.readLongNumber(CmdUtil.getArg(argv, whichArg)); 53 seenOffset = true; 54 } else { 55 throw new IllegalArgumentException 56 (nextArg + " is not a supported option."); 57 } 58 whichArg++; 59 } 60 61 if ((!seenFile) || (!seenOffset)) { 62 usage(); 63 System.exit(1); 64 } 65 66 67 EnvironmentImpl env = 68 CmdUtil.makeUtilityEnvironment(envHome, false); 69 70 71 env.getFileManager().truncateLog(truncateFileNum, truncateOffset); 72 73 env.close(); 74 } catch (Exception e) { 75 e.printStackTrace(); 76 System.out.println(e.getMessage()); 77 usage(); 78 System.exit(1); 79 } 80 } 81 82 private static void usage() { 83 System.out.println("Usage: " + 84 CmdUtil.getJavaCommand(DbRecover.class)); 85 System.out.println(" -h <environment home>"); 86 System.out.println("(optional)"); 87 System.out.println(" -f <file number, in hex>"); 88 System.out.println(" -o <offset, in hex>"); 89 System.out.println("Log file is truncated at position starting at" + 90 " and inclusive of the offset. Beware, not " + 91 " for general purpose use yet!"); 92 } 93 } 94 | Popular Tags |