I had to recover a corrupted database that was still damaged after using the repair tool. the database was so damaged attempts to connect resulted in "Connection broken" jdbc exceptions.
repairs would allow connection but inserts in a junit test fell over with an IOException.
Anyway, the .data.sql file allow m to reconstruct the database from scratch, however it was exactly smooth. Two problems needed fixing to succeed:
- CREATE USER -- fell over because SA always exists in new databases and can't be drop because they are the current user.
I fixed this by adding IF NOT EXISTS
- Referential integrity errors -- Data added to in an order that did not respect foreign key dependencies.
I rearranged the insert commands, so that dependencies were added first
The script was generated by h2 version 1.1.111, if these issues haven't addressed yet, I think would be worth considering.
Trivially adding IF NOT EXISTS to the script generating code.solves one problem.
The other problem might be harder, using graph analysis to determine the order of inserts taking into account referential integrity contrstaints. Alternatively, the script could turn off referential integrity, insert data in arbitrary order, then turn referential integrity. Though the second option doesn't catch problems that exist in the reconstructed dataset, I doubt that is an overriding concern when trying to recover a database.