1 Reply Latest reply: Jul 7, 2012 6:30 PM by 947881 RSS

    Backing up a BerkeleyDB sqlite database from Java


      I'm using BerkeleyDB (version and accessing the sqlite interface through JDBC.

      I'd like to be able to backup the database to then open it on a new machine. The database home directory
      has a DB_CONFIG file with the following content:
      set_open_flags DB_THREAD on
      set_open_flags DB_PRIVATE off

      Here's what I do to backup the db on machine A and open the db on machine B:

      1) I stop the execution of transactions on A

      2) I then run the following commands on A using Runtime.getRuntime().exec(command) calls:
      a) db_hotbackup -c -h <db_home> -b <bckup-directory>
      b) db_load -r lsn -h <bckup-directory> <dbName>
      c) db_load -r fileid -h <bckup-directory> <dbName>

      3) I send the database files and respective logs to B. Machine B stores them in the standard way, that is,
      the database files are in the home directory, and logs are in a <databaseName>-journal sub-directory.

      4) Machine B opens a connection to the database using JDBC and tries to execute transactions. Unfortunately,
      the first preparedStmt.executeQuery() I try to execute returns a SQLException:

      Caused by: SQLite.Exception: error in prepare
           at SQLite.Database.vm_compile_args(Native Method)
           at SQLite.Database.compile(Database.java:700)
           at SQLite.Database.get_table(Database.java:360)
           at SQLite.JDBC2z.JDBCStatement.executeQuery(JDBCStatement.java:126)

      Note that the query executes perfectly well when the database is created and populated on machine B. I should
      also add that running a db_verify on the databases on B after the transfer tells me that the verification succeeded.

      What have I done wrong? Any help would be really appreciated.

      Nicolas Schiper

      Edited by: 944878 on Jul 6, 2012 7:42 AM