Backup and Restore H2 Database
Use this page to back up a Nexus Repository deployment that uses the H2 database. Nexus Repository supports both offline H2 database backups and the Admin - Backup H2 Database scheduled task.
Offline Backup
Sonatype recommends regular offline backups of the H2 database files while Nexus Repository is stopped.
Backing up the database while Nexus Repository is running can capture database files while they are being modified.
To mitigate this risk, we recommend periodically backing up the $data-dir/db folder.
Take the following steps to create an offline H2 database backup:
Stop Nexus Repository.
Back up the complete
$data-dir/dbdirectory.Back up custom configurations and corresponding Blob Stores.
Back up the other required Nexus Repository data described in Prepare a Backup.
Store all backed-up database files, configurations, and blob stores together in a safe backup location.
Restart Nexus Repository once the files are copied.
Backup Task for H2
You can also use the Admin - Backup H2 Database task to create an H2 database backup. Configure the Location field with the relative path where Nexus Repository should store the backup.
Nexus Repository exports the backup data when the task runs and stores a zip file containing the H2 database (nexus.mv.db).
Note
Database write access is temporarily suspended while the Admin - Backup H2 Database task creates the backup. Schedule the task during off-hours when appropriate.
See the Tasks documentation for details on creating and running tasks.
Restore an H2 Database
Use the restore procedure that corresponds to the method used to back up the H2 database.
Restore an Offline H2 Backup
Take the following steps if you performed an offline database backup:
Stop Nexus Repository.
Restore the Database Files:
Replace the files in the
$data-dir/dbdirectory with the database files from your backup.Include all database files from the same point in time. Do not attempt to restore database files individually.
Restore the corresponding blob store backups that were taken at the same time as your database backup.
Restore the Node ID. If restoring or moving to a different server, ensure the node ID files from
$data-dir/keystores/node/are placed into that exact same location prior to starting Nexus Repository so that blob storage metrics and reports function properly.Start the Nexus Repository instance and verify that it starts correctly.
If the database and blob store backups were created at different times, follow the applicable data repair guidance to reconcile differences between the database and blob storage. See Tasks.
Restore a Backup from the H2 Backup Task
Note
Restore your blob stores containing components that were backed up at the same time the task was executed. Not doing so causes synchronization issues between the blob store and database.
Include all database files exported during the backup process which have the same timestamp. Do not attempt to restore individual database files individually as this will not be successful.
Take the following steps to restore the H2 component database after running the Admin - Backup H2 Database task:
Stop Nexus Repository.
Locate the backup directory configured in the Admin - Backup H2 Database task. The backup package uses a timestamped file name similar to nexus-
2024-09-05-10-02-29.zip.Extract the ZIP file.
Replace the files in
$data-dir/dbwith the database files from the backup package.Restore the corresponding blob store backup.
Restart Nexus Repository and verify it is running correctly.
If the database and blob store backups were not created at the same time, run the applicable reconciliation task to correct differences between the database and blob storage. See Tasks.