KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > util > DbRecover


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: DbRecover.java,v 1.13 2006/10/30 21:14:28 bostic Exp $
7  */

8
9 package com.sleepycat.je.util;
10
11 import java.io.File JavaDoc;
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 JavaDoc [] 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 JavaDoc envHome = new File JavaDoc("."); // default to current directory
38
while (whichArg < argv.length) {
39                 String JavaDoc nextArg = argv[whichArg];
40
41                 if (nextArg.equals("-h")) {
42                     whichArg++;
43                     envHome = new File JavaDoc(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 JavaDoc
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             /* Make a read/write environment */
67             EnvironmentImpl env =
68         CmdUtil.makeUtilityEnvironment(envHome, false);
69
70             /* Go through the file manager to get the JE file. Truncate. */
71             env.getFileManager().truncateLog(truncateFileNum, truncateOffset);
72
73             env.close();
74         } catch (Exception JavaDoc 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