01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: DbRecover.java,v 1.13.2.3 2008/01/07 15:14:17 cwl Exp $
07: */
08:
09: 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: /**
17: * DbRecover is a utility that allows the user to resume use of the environment
18: * from a given time point. Not for general use yet!
19: */
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: /*
32: * Usage: -h <envHomeDir>
33: -f <file number, in hex>
34: * -o <offset, in hex. The log is truncated at the position
35: * including this offset>
36: */
37: File envHome = new File("."); // default to current directory
38: 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 = CmdUtil.readLongNumber(CmdUtil
47: .getArg(argv, whichArg));
48: seenFile = true;
49: } else if (nextArg.equals("-o")) {
50: whichArg++;
51: truncateOffset = CmdUtil.readLongNumber(CmdUtil
52: .getArg(argv, whichArg));
53: seenOffset = true;
54: } else {
55: throw new IllegalArgumentException(nextArg
56: + " is not a supported option.");
57: }
58: whichArg++;
59: }
60:
61: if ((!seenFile) || (!seenOffset)) {
62: usage();
63: System.exit(1);
64: }
65:
66: /* Make a read/write environment */
67: EnvironmentImpl env = CmdUtil.makeUtilityEnvironment(
68: envHome, false);
69:
70: /* Go through the file manager to get the JE file. Truncate. */
71: env.getFileManager().truncateLog(truncateFileNum,
72: truncateOffset);
73:
74: env.close();
75: } catch (Exception e) {
76: e.printStackTrace();
77: System.out.println(e.getMessage());
78: usage();
79: System.exit(1);
80: }
81: }
82:
83: private static void usage() {
84: System.out.println("Usage: "
85: + CmdUtil.getJavaCommand(DbRecover.class));
86: System.out.println(" -h <environment home>");
87: System.out.println("(optional)");
88: System.out.println(" -f <file number, in hex>");
89: System.out.println(" -o <offset, in hex>");
90: System.out
91: .println("Log file is truncated at position starting at"
92: + " and inclusive of the offset. Beware, not "
93: + " for general purpose use yet!");
94: }
95: }
|