Search code examples
backuph2lockfile

H2 Database : how unlock a database file for backup copy?


I'm using h2database version 1.4.200 with hibernate for saving in database file.

My programs needs to regulary save backup and I don't care about corruption's file's problems.

After looking the documentation : http://h2database.com/html/features.html#database_file_locking

I decided to use parameter LOCK_FILE=NO. I saved my models and keeped the entity manager opened. When I tryed to copy the db file "data.mv.db", my database file was always locked even if I used Lock_FILE=NO.

Parameter LOCK_FILE=NO, does it work correctly ? There is a alternative for copying speedly my db-file in java ?


Solution

  • Any attempt to copy the file when database is in use is a way to get a possibly corrupted backup.

    H2 has BACKUP command for online backups.

    BACKUP TO 'filename.zip'
    

    This command creates a ZIP archive with a consistent copy of the database file.