Package org.h2.tools
Class Recover
- java.lang.Object
-
- org.h2.util.Tool
-
- org.h2.tools.Recover
-
- All Implemented Interfaces:
DataHandler
public class Recover extends Tool implements DataHandler
Helps recovering a corrupted database.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashMap<java.lang.String,java.lang.String>
columnTypeMap
private java.lang.String
databaseName
private boolean
lobMaps
private java.util.HashSet<java.lang.Integer>
objectIdSet
private int
recordLength
private java.util.ArrayList<MetaRecord>
schema
private int
storageId
private java.lang.String
storageName
private java.util.HashMap<java.lang.Integer,java.lang.String>
tableMap
private boolean
trace
private int
valueId
-
Constructor Summary
Constructors Constructor Description Recover()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkPowerOff()
INTERNALvoid
checkWritingAllowed()
INTERNALprivate void
createTemporaryTable(java.io.PrintWriter writer)
private static void
dumpLayout(java.io.PrintWriter writer, MVStore mv)
private void
dumpLobMaps(java.io.PrintWriter writer, MVStore mv)
private static void
dumpMeta(java.io.PrintWriter writer, MVStore mv)
private void
dumpMVStoreFile(java.io.PrintWriter writer, java.lang.String fileName)
private static void
dumpTypes(java.io.PrintWriter writer, MVStore mv)
static void
execute(java.lang.String dir, java.lang.String db)
Dumps the contents of a database to a SQL script file.private static java.lang.String
extractTableOrViewName(java.lang.String sql)
CompareMode
getCompareMode()
Return compare mode.java.lang.String
getDatabasePath()
INTERNALSmallLRUCache<java.lang.String,java.lang.String[]>
getLobFileListCache()
INTERNALLobStorageInterface
getLobStorage()
INTERNALjava.lang.Object
getLobSyncObject()
INTERNALint
getMaxLengthInplaceLob()
INTERNALprivate void
getSQL(java.lang.StringBuilder builder, java.lang.String column, Value v)
TempFileDeleter
getTempFileDeleter()
INTERNALprivate java.io.PrintWriter
getWriter(java.lang.String fileName, java.lang.String suffix)
private static boolean
isLobTable(java.lang.String name)
private static boolean
isSchemaObjectTypeDelayed(MetaRecord m)
static void
main(java.lang.String... args)
Options are case sensitive.FileStore
openFile(java.lang.String name, java.lang.String mode, boolean mustExist)
INTERNALprivate void
process(java.lang.String dir, java.lang.String db)
static java.io.InputStream
readBlobMap(java.sql.Connection conn, long lobId, long precision)
INTERNALstatic java.io.Reader
readClobMap(java.sql.Connection conn, long lobId, long precision)
INTERNALint
readLob(long lobId, byte[] hmac, long offset, byte[] buff, int off, int length)
INTERNALprivate void
resetSchema()
void
runTool(java.lang.String... args)
Dumps the contents of a database file to a human readable text file.private void
setDatabaseName(java.lang.String name)
private java.lang.String
setStorage(int storageId)
private void
trace(java.lang.String message)
private void
traceError(java.lang.String message, java.lang.Throwable t)
private void
writeError(java.io.PrintWriter writer, java.lang.Throwable e)
private void
writeMetaRow(Row r)
private void
writeSchema(java.io.PrintWriter writer)
private void
writeSchemaSET(java.io.PrintWriter writer)
-
Methods inherited from class org.h2.util.Tool
isOption, printNoDatabaseFilesFound, setOut, showUsage, showUsageAndThrowUnsupportedOption, throwUnsupportedOption
-
-
-
-
Field Detail
-
databaseName
private java.lang.String databaseName
-
storageId
private int storageId
-
storageName
private java.lang.String storageName
-
recordLength
private int recordLength
-
valueId
private int valueId
-
trace
private boolean trace
-
schema
private java.util.ArrayList<MetaRecord> schema
-
objectIdSet
private java.util.HashSet<java.lang.Integer> objectIdSet
-
tableMap
private java.util.HashMap<java.lang.Integer,java.lang.String> tableMap
-
columnTypeMap
private java.util.HashMap<java.lang.String,java.lang.String> columnTypeMap
-
lobMaps
private boolean lobMaps
-
-
Method Detail
-
main
public static void main(java.lang.String... args) throws java.sql.SQLException
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:
java.sql.SQLException
- on failure
-
runTool
public void runTool(java.lang.String... args) throws java.sql.SQLException
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.
-
readBlobMap
public static java.io.InputStream readBlobMap(java.sql.Connection conn, long lobId, long precision) throws java.sql.SQLException
INTERNAL- Parameters:
conn
- to uselobId
- id of the LOB streamprecision
- not used- Returns:
- InputStream to read LOB content from
- Throws:
java.sql.SQLException
- on failure
-
readClobMap
public static java.io.Reader readClobMap(java.sql.Connection conn, long lobId, long precision) throws java.lang.Exception
INTERNAL- Parameters:
conn
- to uselobId
- id of the LOB streamprecision
- not used- Returns:
- Reader to read LOB content from
- Throws:
java.sql.SQLException
- on failurejava.lang.Exception
-
trace
private void trace(java.lang.String message)
-
traceError
private void traceError(java.lang.String message, java.lang.Throwable t)
-
execute
public static void execute(java.lang.String dir, java.lang.String db) throws java.sql.SQLException
Dumps the contents of a database to a SQL script file.- Parameters:
dir
- the directorydb
- the database name (null for all databases)- Throws:
java.sql.SQLException
- on failure
-
process
private void process(java.lang.String dir, java.lang.String db)
-
getWriter
private java.io.PrintWriter getWriter(java.lang.String fileName, java.lang.String suffix)
-
getSQL
private void getSQL(java.lang.StringBuilder builder, java.lang.String column, Value v)
-
setDatabaseName
private void setDatabaseName(java.lang.String name)
-
dumpMVStoreFile
private void dumpMVStoreFile(java.io.PrintWriter writer, java.lang.String fileName)
-
dumpLayout
private static void dumpLayout(java.io.PrintWriter writer, MVStore mv)
-
dumpMeta
private static void dumpMeta(java.io.PrintWriter writer, MVStore mv)
-
dumpTypes
private static void dumpTypes(java.io.PrintWriter writer, MVStore mv)
-
dumpLobMaps
private void dumpLobMaps(java.io.PrintWriter writer, MVStore mv)
-
setStorage
private java.lang.String setStorage(int storageId)
-
writeMetaRow
private void writeMetaRow(Row r)
-
resetSchema
private void resetSchema()
-
writeSchemaSET
private void writeSchemaSET(java.io.PrintWriter writer)
-
writeSchema
private void writeSchema(java.io.PrintWriter writer)
-
isLobTable
private static boolean isLobTable(java.lang.String name)
-
isSchemaObjectTypeDelayed
private static boolean isSchemaObjectTypeDelayed(MetaRecord m)
-
createTemporaryTable
private void createTemporaryTable(java.io.PrintWriter writer)
-
extractTableOrViewName
private static java.lang.String extractTableOrViewName(java.lang.String sql)
-
writeError
private void writeError(java.io.PrintWriter writer, java.lang.Throwable e)
-
getDatabasePath
public java.lang.String getDatabasePath()
INTERNAL- Specified by:
getDatabasePath
in interfaceDataHandler
- Returns:
- the database path
-
openFile
public FileStore openFile(java.lang.String name, java.lang.String mode, boolean mustExist)
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
public java.lang.Object getLobSyncObject()
INTERNAL- Specified by:
getLobSyncObject
in interfaceDataHandler
- Returns:
- the synchronization object
-
getLobFileListCache
public SmallLRUCache<java.lang.String,java.lang.String[]> getLobFileListCache()
INTERNAL- Specified by:
getLobFileListCache
in interfaceDataHandler
- Returns:
- the cache or null
-
getTempFileDeleter
public TempFileDeleter getTempFileDeleter()
INTERNAL- Specified by:
getTempFileDeleter
in interfaceDataHandler
- Returns:
- the temp file deleter
-
getLobStorage
public LobStorageInterface 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
public CompareMode getCompareMode()
Description copied from interface:DataHandler
Return compare mode.- Specified by:
getCompareMode
in interfaceDataHandler
- Returns:
- Compare mode.
-
-