org.h2.tools
Class Recover

java.lang.Object
  extended by org.h2.util.Tool
      extended by org.h2.tools.Recover
All Implemented Interfaces:
DataHandler

public class Recover
extends Tool
implements DataHandler

Helps recovering a corrupted database.


Field Summary
 
Fields inherited from class org.h2.util.Tool
out
 
Constructor Summary
Recover()
           
 
Method Summary
 int allocateObjectId(boolean b, boolean c)
          INTERNAL
 void checkPowerOff()
          INTERNAL
 void checkWritingAllowed()
          INTERNAL
 int compareTypeSave(Value a, Value b)
          INTERNAL
 java.lang.String createTempFile()
          INTERNAL
static void execute(java.lang.String dir, java.lang.String db)
          Dumps the contents of a database to a SQL script file.
 void freeUpDiskSpace()
          INTERNAL
 int getChecksum(byte[] data, int start, int end)
          INTERNAL
 java.lang.String getDatabasePath()
          INTERNAL
 java.lang.String getLobCompressionAlgorithm(int type)
          INTERNAL
 SmallLRUCache<java.lang.String,java.lang.String[]> getLobFileListCache()
          INTERNAL
 boolean getLobFilesInDirectories()
          INTERNAL
 java.lang.Object getLobSyncObject()
          INTERNAL
 int getMaxLengthInplaceLob()
          INTERNAL
 TempFileDeleter getTempFileDeleter()
          INTERNAL
 Trace getTrace()
          INTERNAL
 void handleInvalidChecksum()
          INTERNAL
static void main(java.lang.String... args)
          Options are case sensitive.
 FileStore openFile(java.lang.String name, java.lang.String mode, boolean mustExist)
          INTERNAL
static java.io.InputStream readBlob(java.lang.String fileName)
          INTERNAL
static java.io.Reader readClob(java.lang.String fileName)
          INTERNAL
 void run(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
printNoDatabaseFilesFound, readArgBoolean, setOut, showUsage, throwUnsupportedOption
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Recover

public Recover()
Method Detail

main

public static void main(java.lang.String... args)
                 throws java.sql.SQLException
Options are case sensitive. Supported options are:
[-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
Encrypted databases need to be decrypted first.

Parameters:
args - the command line arguments
Throws:
java.sql.SQLException

run

public void run(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 the file format, or if there is a hardware problem.

Specified by:
run in class Tool
Parameters:
args - the command line arguments
Throws:
java.sql.SQLException

readClob

public static java.io.Reader readClob(java.lang.String fileName)
                               throws java.io.IOException
INTERNAL

Throws:
java.io.IOException

readBlob

public static java.io.InputStream readBlob(java.lang.String fileName)
                                    throws java.io.IOException
INTERNAL

Throws:
java.io.IOException

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 directory
db - the database name (null for all databases)
Throws:
java.sql.SQLException

getDatabasePath

public java.lang.String getDatabasePath()
INTERNAL

Specified by:
getDatabasePath in interface DataHandler
Returns:
the database path

openFile

public FileStore openFile(java.lang.String name,
                          java.lang.String mode,
                          boolean mustExist)
                   throws java.sql.SQLException
INTERNAL

Specified by:
openFile in interface DataHandler
Parameters:
name - the file name
mode - the mode
mustExist - whether the file must already exist
Returns:
the file
Throws:
java.sql.SQLException

getChecksum

public int getChecksum(byte[] data,
                       int start,
                       int end)
INTERNAL

Specified by:
getChecksum in interface DataHandler
Parameters:
data - the byte array
start - the starting offset
end - the end offset
Returns:
the checksum

checkPowerOff

public void checkPowerOff()
INTERNAL

Specified by:
checkPowerOff in interface DataHandler

checkWritingAllowed

public void checkWritingAllowed()
INTERNAL

Specified by:
checkWritingAllowed in interface DataHandler

freeUpDiskSpace

public void freeUpDiskSpace()
INTERNAL

Specified by:
freeUpDiskSpace in interface DataHandler

handleInvalidChecksum

public void handleInvalidChecksum()
                           throws java.sql.SQLException
INTERNAL

Specified by:
handleInvalidChecksum in interface DataHandler
Throws:
java.sql.SQLException - if this should not be ignored

compareTypeSave

public int compareTypeSave(Value a,
                           Value b)
INTERNAL

Specified by:
compareTypeSave in interface DataHandler
Parameters:
a - the first value
b - the second value
Returns:
0 for equal, 1 if a is larger than b, and -1 otherwise

getMaxLengthInplaceLob

public int getMaxLengthInplaceLob()
INTERNAL

Specified by:
getMaxLengthInplaceLob in interface DataHandler
Returns:
the maximum size

allocateObjectId

public int allocateObjectId(boolean b,
                            boolean c)
INTERNAL

Specified by:
allocateObjectId in interface DataHandler
Parameters:
b - if a fresh id is required
c - true if the id is for the data file
Returns:
the new id

createTempFile

public java.lang.String createTempFile()
INTERNAL

Specified by:
createTempFile in interface DataHandler
Returns:
the file name

getLobCompressionAlgorithm

public java.lang.String getLobCompressionAlgorithm(int type)
INTERNAL

Specified by:
getLobCompressionAlgorithm in interface DataHandler
Parameters:
type - the data type (CLOB or BLOB)
Returns:
the compression algorithm, or null

getLobSyncObject

public java.lang.Object getLobSyncObject()
INTERNAL

Specified by:
getLobSyncObject in interface DataHandler
Returns:
the synchronization object

getLobFilesInDirectories

public boolean getLobFilesInDirectories()
INTERNAL

Specified by:
getLobFilesInDirectories in interface DataHandler
Returns:
true if lob files are stored in directories.

getLobFileListCache

public SmallLRUCache<java.lang.String,java.lang.String[]> getLobFileListCache()
INTERNAL

Specified by:
getLobFileListCache in interface DataHandler
Returns:
the cache or null

getTempFileDeleter

public TempFileDeleter getTempFileDeleter()
INTERNAL

Specified by:
getTempFileDeleter in interface DataHandler
Returns:
the temp file deleter

getTrace

public Trace getTrace()
INTERNAL

Specified by:
getTrace in interface DataHandler
Returns:
the trace writer