Package org.h2.tools
Class Recover
- java.lang.Object
-
- org.h2.util.Tool
-
- org.h2.tools.Recover
-
- All Implemented Interfaces:
DataHandler
- Direct Known Subclasses:
DirectRecover
public class Recover extends Tool implements DataHandler
Helps recovering a corrupted database.
-
-
Constructor Summary
Constructors Constructor Description Recover()Creates default instance
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckPowerOff()INTERNALvoidcheckWritingAllowed()INTERNALstatic voidexecute(java.lang.String dir, java.lang.String db)Dumps the contents of a database to a SQL script file.CompareModegetCompareMode()Return compare mode.java.lang.StringgetDatabasePath()INTERNALSmallLRUCache<java.lang.String,java.lang.String[]>getLobFileListCache()INTERNALLobStorageInterfacegetLobStorage()INTERNALjava.lang.ObjectgetLobSyncObject()INTERNALintgetMaxLengthInplaceLob()INTERNALTempFileDeletergetTempFileDeleter()INTERNALstatic voidmain(java.lang.String... args)Options are case sensitive.FileStoreopenFile(java.lang.String name, java.lang.String mode, boolean mustExist)INTERNALstatic java.io.InputStreamreadBlobMap(java.sql.Connection conn, long lobId, long precision)INTERNALstatic java.io.ReaderreadClobMap(java.sql.Connection conn, long lobId, long precision)INTERNALintreadLob(long lobId, byte[] hmac, long offset, byte[] buff, int off, int length)INTERNALvoidrunTool(java.lang.String... args)Dumps the contents of a database file to a human readable text file.-
Methods inherited from class org.h2.util.Tool
getMainClassName, isOption, printNoDatabaseFilesFound, setOut, showUsage, showUsageAndThrowUnsupportedOption, throwUnsupportedOption
-
-
-
-
Method Detail
-
main
public static void main(java.lang.String... args) throws java.sql.SQLExceptionOptions are case sensitive.
Encrypted databases need to be decrypted first.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.SQLExceptionDumps 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.SQLExceptionINTERNAL- 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.ExceptionINTERNAL- 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
-
execute
public static void execute(java.lang.String dir, java.lang.String db) throws java.sql.SQLExceptionDumps 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
-
getDatabasePath
public java.lang.String getDatabasePath()
INTERNAL- Specified by:
getDatabasePathin interfaceDataHandler- Returns:
- the database path
-
openFile
public FileStore openFile(java.lang.String name, java.lang.String mode, boolean mustExist)
INTERNAL- Specified by:
openFilein interfaceDataHandler- Parameters:
name- the file namemode- the modemustExist- whether the file must already exist- Returns:
- the file
-
checkPowerOff
public void checkPowerOff()
INTERNAL- Specified by:
checkPowerOffin interfaceDataHandler
-
checkWritingAllowed
public void checkWritingAllowed()
INTERNAL- Specified by:
checkWritingAllowedin interfaceDataHandler
-
getMaxLengthInplaceLob
public int getMaxLengthInplaceLob()
INTERNAL- Specified by:
getMaxLengthInplaceLobin interfaceDataHandler- Returns:
- the maximum size
-
getLobSyncObject
public java.lang.Object getLobSyncObject()
INTERNAL- Specified by:
getLobSyncObjectin interfaceDataHandler- Returns:
- the synchronization object
-
getLobFileListCache
public SmallLRUCache<java.lang.String,java.lang.String[]> getLobFileListCache()
INTERNAL- Specified by:
getLobFileListCachein interfaceDataHandler- Returns:
- the cache or null
-
getTempFileDeleter
public TempFileDeleter getTempFileDeleter()
INTERNAL- Specified by:
getTempFileDeleterin interfaceDataHandler- Returns:
- the temp file deleter
-
getLobStorage
public LobStorageInterface getLobStorage()
INTERNAL- Specified by:
getLobStoragein 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:
readLobin 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:DataHandlerReturn compare mode.- Specified by:
getCompareModein interfaceDataHandler- Returns:
- Compare mode.
-
-