How to convert H2 database to v3 format#
nJAMS Server 6.1 comes with a new format of the internal H2 database. nJAMS installer will automatically migrate the H2 database format from v2 to v3, when an update is performed from nJAMS Server 6.0.
In case you prefer to install a new nJAMS Server instance in parallel to your existing instance and you want to manually switch from the old instance to the new instance, you have to manually convert the existing H2 database from v2 to v3. Or there might be cases where the installer will reject to convert the database, if no sufficient space is available. You can then copy the old database to a system or drive with sufficient space and run the conversion there.
This chapter is about the instructions you have to follow to convert the internal nJAMS H2 database from v2 to v3.
Note
If you are using any other relational database system, such as Oracle, SQL Server, or PostgreSQL, these steps are NOT required. The migration is only required, if are on H2 database in format v2.
Introduction#
Starting with version 6.1 nJAMS Server introduced a new version of H2 database (v3), which is not compatible to its old format.
The actual conversion procedure is quite simple:
Export the old database into a SQL script file
Import the SQL script into the new database.
This approach is actually the same as when doing a full-rebuilding of the H2 in the maintenance case, except that the import is done with a different database version than the export.
Prerequisites#
Java needs to be installed and must be available on the search path. Otherwise you need to use the full Java executable path with the following commands.
Instructions#
If applicable, copy the old H2 database file
njams.mv.db
from the nJAMS installation (typically.../njams/data/h2
) into a work folder with the same amount of free space as the original database’s size.Copy both the old
h2-2.1.210.jar
and the newh2-2.2.224.jar
H2 JDBC driver files (which can be found in the nJAMS installation folder) into a work folder on the same drive as the database file from step 1.Run the export using the following command in the work folder containing the JDBC driver. Please note that this command uses the old (2.1.210) JDBC driver and references the original v3 database!
java -cp h2-2.1.210.jar org.h2.tools.Script -url "jdbc:h2:file:/path/to/db/njams-v2;DB_CLOSE_ON_EXIT=TRUE;AUTO_SERVER=FALSE;TRACE_LEVEL_FILE=0;TRACE_LEVEL_SYSTEM_OUT=2" -user admin -password secret123 -script njams.sql.zip -options compression zip
The command creates njams.sql.zip file as output.
Run the import into the new database using the following command.
Please note that this command uses the new (2.2.224) JDBC driver and the new database name (njams-v3) as well as a compatibility option that allows importing old format data.
java -cp h2-2.2.224.jar org.h2.tools.RunScript -url "jdbc:h2:file:/path/to/db/njams-v3;DB_CLOSE_ON_EXIT=TRUE;AUTO_SERVER=FALSE;TRACE_LEVEL_FILE=0;TRACE_LEVEL_SYSTEM_OUT=1" -user admin -password secret123 -script njams.sql.zip -options compression zip
After that, the new v3 database file can be found in the selected path:
njams-v3.mv.db