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 Details

    • databaseName

      private String databaseName
    • storageId

      private int storageId
    • storageName

      private String storageName
    • recordLength

      private int recordLength
    • valueId

      private int valueId
    • trace

      private boolean trace
    • schema

      private ArrayList<MetaRecord> schema
    • objectIdSet

      private HashSet<Integer> objectIdSet
    • tableMap

      private HashMap<Integer,String> tableMap
    • columnTypeMap

      private HashMap<String,String> columnTypeMap
    • lobMaps

      private boolean lobMaps
  • Constructor Details

    • Recover

      public Recover()
  • Method Details

    • main

      public static void main(String... args) throws 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
      Encrypted databases need to be decrypted first.
      Parameters:
      args - the command line arguments
      Throws:
      SQLException - on failure
    • runTool

      public void runTool(String... args) throws 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.
      Specified by:
      runTool in class Tool
      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 use
      lobId - id of the LOB stream
      precision - not used
      Returns:
      InputStream to read LOB content from
      Throws:
      SQLException - on failure
    • readClobMap

      public static Reader readClobMap(Connection conn, long lobId, long precision) throws Exception
      INTERNAL
      Parameters:
      conn - to use
      lobId - id of the LOB stream
      precision - not used
      Returns:
      Reader to read LOB content from
      Throws:
      SQLException - on failure
      Exception
    • trace

      private void trace(String message)
    • traceError

      private void traceError(String message, Throwable t)
    • execute

      public static void execute(String dir, String db) throws 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:
      SQLException - on failure
    • process

      private void process(String dir, String db)
    • getWriter

      private PrintWriter getWriter(String fileName, String suffix)
    • getSQL

      private void getSQL(StringBuilder builder, String column, Value v)
    • setDatabaseName

      private void setDatabaseName(String name)
    • dumpMVStoreFile

      private void dumpMVStoreFile(PrintWriter writer, String fileName)
    • dumpLayout

      private static void dumpLayout(PrintWriter writer, MVStore mv)
    • dumpMeta

      private static void dumpMeta(PrintWriter writer, MVStore mv)
    • dumpTypes

      private static void dumpTypes(PrintWriter writer, MVStore mv)
    • dumpLobMaps

      private void dumpLobMaps(PrintWriter writer, MVStore mv)
    • setStorage

      private String setStorage(int storageId)
    • writeMetaRow

      private void writeMetaRow(Row r)
    • resetSchema

      private void resetSchema()
    • writeSchemaSET

      private void writeSchemaSET(PrintWriter writer)
    • writeSchema

      private void writeSchema(PrintWriter writer)
    • isLobTable

      private static boolean isLobTable(String name)
    • isSchemaObjectTypeDelayed

      private static boolean isSchemaObjectTypeDelayed(MetaRecord m)
    • createTemporaryTable

      private void createTemporaryTable(PrintWriter writer)
    • extractTableOrViewName

      private static String extractTableOrViewName(String sql)
    • writeError

      private void writeError(PrintWriter writer, Throwable e)
    • getDatabasePath

      public String getDatabasePath()
      INTERNAL
      Specified by:
      getDatabasePath in interface DataHandler
      Returns:
      the database path
    • openFile

      public FileStore openFile(String name, String mode, boolean mustExist)
      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
    • checkPowerOff

      public void checkPowerOff()
      INTERNAL
      Specified by:
      checkPowerOff in interface DataHandler
    • checkWritingAllowed

      public void checkWritingAllowed()
      INTERNAL
      Specified by:
      checkWritingAllowed in interface DataHandler
    • getMaxLengthInplaceLob

      public int getMaxLengthInplaceLob()
      INTERNAL
      Specified by:
      getMaxLengthInplaceLob in interface DataHandler
      Returns:
      the maximum size
    • getLobSyncObject

      public Object getLobSyncObject()
      INTERNAL
      Specified by:
      getLobSyncObject in interface DataHandler
      Returns:
      the synchronization object
    • getLobFileListCache

      public SmallLRUCache<String,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
    • getLobStorage

      public LobStorageInterface getLobStorage()
      INTERNAL
      Specified by:
      getLobStorage in interface DataHandler
      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 interface DataHandler
      Parameters:
      lobId - the lob id
      hmac - the message authentication code
      offset - the offset within the lob
      buff - the target buffer
      off - the offset within the target buffer
      length - 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 interface DataHandler
      Returns:
      Compare mode.