Package org.h2.tools
Class Recover
java.lang.Object
org.h2.util.Tool
org.h2.tools.Recover
- All Implemented Interfaces:
DataHandler
Helps recovering a corrupted database.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
private boolean
private int
private ArrayList
<MetaRecord> private int
private String
private boolean
private int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
INTERNALvoid
INTERNALprivate void
createTemporaryTable
(PrintWriter writer) private static void
dumpLayout
(PrintWriter writer, MVStore mv) private void
dumpLobMaps
(PrintWriter writer, MVStore mv) private static void
dumpMeta
(PrintWriter writer, MVStore mv) private void
dumpMVStoreFile
(PrintWriter writer, String fileName) private static void
dumpTypes
(PrintWriter writer, MVStore mv) static void
Dumps the contents of a database to a SQL script file.private static String
Return compare mode.INTERNALINTERNALINTERNALINTERNALint
INTERNALprivate void
getSQL
(StringBuilder builder, String column, Value v) INTERNALprivate PrintWriter
private static boolean
isLobTable
(String name) private static boolean
static void
Options are case sensitive.INTERNALprivate void
static InputStream
readBlobMap
(Connection conn, long lobId, long precision) INTERNALstatic Reader
readClobMap
(Connection conn, long lobId, long precision) INTERNALint
readLob
(long lobId, byte[] hmac, long offset, byte[] buff, int off, int length) INTERNALprivate void
void
Dumps the contents of a database file to a human readable text file.private void
setDatabaseName
(String name) private String
setStorage
(int storageId) private void
private void
traceError
(String message, Throwable t) private void
writeError
(PrintWriter writer, Throwable e) private void
writeMetaRow
(Row r) private void
writeSchema
(PrintWriter writer) private void
writeSchemaSET
(PrintWriter writer) Methods inherited from class org.h2.util.Tool
isOption, printNoDatabaseFilesFound, setOut, showUsage, showUsageAndThrowUnsupportedOption, throwUnsupportedOption
-
Field Details
-
databaseName
-
storageId
private int storageId -
storageName
-
recordLength
private int recordLength -
valueId
private int valueId -
trace
private boolean trace -
schema
-
objectIdSet
-
tableMap
-
columnTypeMap
-
lobMaps
private boolean lobMaps
-
-
Constructor Details
-
Recover
public Recover()
-
-
Method Details
-
main
Options are case sensitive.Supported options [-help] or [-?] Print the list of options [-dir <dir>] The directory (default: .) [-db <database>] The database name (all databases if not set) [-trace] Print additional trace information [-transactionLog] Print the transaction log - Parameters:
args
- the command line arguments- Throws:
SQLException
- on failure
-
runTool
Dumps the contents of a database file to a human readable text file. This text file can be used to recover most of the data. This tool does not open the database and can be used even if the database files are corrupted. A database can get corrupted if there is a bug in the database engine or file system software, or if an application writes into the database file that doesn't understand the file format, or if there is a hardware problem.- Specified by:
runTool
in classTool
- Parameters:
args
- the command line arguments- Throws:
SQLException
- on failure
-
readBlobMap
public static InputStream readBlobMap(Connection conn, long lobId, long precision) throws SQLException INTERNAL- Parameters:
conn
- to uselobId
- id of the LOB streamprecision
- not used- Returns:
- InputStream to read LOB content from
- Throws:
SQLException
- on failure
-
readClobMap
INTERNAL- Parameters:
conn
- to uselobId
- id of the LOB streamprecision
- not used- Returns:
- Reader to read LOB content from
- Throws:
SQLException
- on failureException
-
trace
-
traceError
-
execute
Dumps the contents of a database to a SQL script file.- Parameters:
dir
- the directorydb
- the database name (null for all databases)- Throws:
SQLException
- on failure
-
process
-
getWriter
-
getSQL
-
setDatabaseName
-
dumpMVStoreFile
-
dumpLayout
-
dumpMeta
-
dumpTypes
-
dumpLobMaps
-
setStorage
-
writeMetaRow
-
resetSchema
private void resetSchema() -
writeSchemaSET
-
writeSchema
-
isLobTable
-
isSchemaObjectTypeDelayed
-
createTemporaryTable
-
extractTableOrViewName
-
writeError
-
getDatabasePath
INTERNAL- Specified by:
getDatabasePath
in interfaceDataHandler
- Returns:
- the database path
-
openFile
INTERNAL- Specified by:
openFile
in interfaceDataHandler
- Parameters:
name
- the file namemode
- the modemustExist
- whether the file must already exist- Returns:
- the file
-
checkPowerOff
public void checkPowerOff()INTERNAL- Specified by:
checkPowerOff
in interfaceDataHandler
-
checkWritingAllowed
public void checkWritingAllowed()INTERNAL- Specified by:
checkWritingAllowed
in interfaceDataHandler
-
getMaxLengthInplaceLob
public int getMaxLengthInplaceLob()INTERNAL- Specified by:
getMaxLengthInplaceLob
in interfaceDataHandler
- Returns:
- the maximum size
-
getLobSyncObject
INTERNAL- Specified by:
getLobSyncObject
in interfaceDataHandler
- Returns:
- the synchronization object
-
getLobFileListCache
INTERNAL- Specified by:
getLobFileListCache
in interfaceDataHandler
- Returns:
- the cache or null
-
getTempFileDeleter
INTERNAL- Specified by:
getTempFileDeleter
in interfaceDataHandler
- Returns:
- the temp file deleter
-
getLobStorage
INTERNAL- Specified by:
getLobStorage
in interfaceDataHandler
- Returns:
- the lob storage mechanism
-
readLob
public int readLob(long lobId, byte[] hmac, long offset, byte[] buff, int off, int length) INTERNAL- Specified by:
readLob
in interfaceDataHandler
- Parameters:
lobId
- the lob idhmac
- the message authentication codeoffset
- the offset within the lobbuff
- the target bufferoff
- the offset within the target bufferlength
- the number of bytes to read- Returns:
- the number of bytes read
-
getCompareMode
Description copied from interface:DataHandler
Return compare mode.- Specified by:
getCompareMode
in interfaceDataHandler
- Returns:
- Compare mode.
-