H2 database
We do not recommend using the H2 database for production environments. |
Corrupted repository after restart
When using H2 version 2.1.x
on Java 17
, the repository can get corrupted upon shutdown.
18-Dec-2023 12:02:08.198 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [169049] milliseconds
2023-12-18 12:21:46,165 ERROR info.magnolia.cms.security.JCRSessionOp: Error caught while loading the system user anonymous: javax.jcr.PathNotFoundException: /system/anonymous
javax.jcr.PathNotFoundException: /system/anonymous
at org.apache.jackrabbit.core.ItemManager.getNode(ItemManager.java:576) ~[jackrabbit-core-2.20.13.jar:2.20.13]
A workaround for this issue is to update the version of H2:
-
Override the managed version in your BOM file.
-
Run the H2 migration script, as explained in the next section.
Running the migration script
Jackrabbit creates one H2 database per workspace, plus one for content versions in the |
Example JDBC URLs are listed below:
-
jdbc:h2:~/<magnolia.home>/repositories/magnolia/workspaces/website/db
-
jdbc:h2:~/<magnolia.home>/repositories/magnolia/workspaces/dam/db
-
jdbc:h2:~/<magnolia.home>/repositories/magnolia/version/db
For each of these databases:
-
Export your database into an SQL script using version
2.1.214
(or the earlier version you were using). -
Create a new database using version
2.3.232
. -
Run the SQL script to restore the database, using the file created with version
2.1.214
(or the earlier version that applies in your case).
H2 Migration script
A migration script for exporting and restoring your databases is given below.
#!/bin/bash
# h2-2.1.214.jar and h2-2.3.232.jar files must be present in the current working directory.
# They can be found respectively in 6.2.27 and 6.3 Magnolia webapps
path=/path/to/webapps/magnoliaAuthor/repositories/magnolia #repeat on public
for filepath in $(find $path -name '*.mv.db'); do
parentdir="$(dirname "$filepath")"
# Export data from old db file to backup.zip
echo "Exporting database $parentdir/db..."
java -cp h2-2.1.214.jar org.h2.tools.Script -url jdbc:h2:$parentdir/db -script $parentdir/backup.zip -options compression zip
rm -f $parentdir/db.mv.db
# Import data from the backup.zip to the new db file
echo "Importing data..."
java -cp h2-2.3.232.jar org.h2.tools.RunScript -url jdbc:h2:$parentdir/db -script $parentdir/backup.zip -options compression zip variable_binary
rm -f $parentdir/backup.zip
echo "$parentdir/db migrated succesfully"
done
If you are experiencing index-related errors while upgrading H2 databases, try running the script below to remove indexes before using the migration script.
|