You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从备份文件恢复H2(内存型)数据库?

Answer to Your H2 nioMemFS Backup/Restore Question

Absolutely—H2 does provide a corresponding command to restore backups created with the BACKUP command for nioMemFS file systems: the RESTORE command. Here's what you need to know to use it effectively:

Key Details About the RESTORE Command

  • Core Syntax: To restore a backup, run this SQL statement once you've connected to a nioMemFS database instance:
    RESTORE FROM '/path/to/your/backup-file.zip'
    
  • Required Database Type: Just like the BACKUP command is restricted to nioMemFS, the RESTORE command only works with nioMemFS database instances (identified by URLs starting with jdbc:h2:nioMemFS:). You cannot use this backup file to restore a standard in-memory database (URL starting with jdbc:h2:mem:).
  • Overwriting Existing Data: If the target nioMemFS database already contains data, H2 will throw an error by default. To overwrite existing data during restore, add the OVERWRITE clause:
    RESTORE FROM '/path/to/your/backup-file.zip' OVERWRITE
    

Step-by-Step Example

  1. First, create a nioMemFS database connection (this is where you'll restore the backup):
    jdbc:h2:nioMemFS:/restoredDB;DB_CLOSE_ON_EXIT=FALSE
    
  2. Execute the restore command in your SQL client:
    RESTORE FROM '/var/backups/h2-nio-backup.zip' OVERWRITE
    
  3. Verify the restore by querying your tables—your data should now be present in the nioMemFS instance.

Important Notes

  • Backup files created via BACKUP are automatically compressed as ZIP files, so you don't need to handle compression/decompression manually.
  • Ensure the user running the H2 process has read access to the backup file path.

内容的提问来源于stack exchange,提问作者Michael

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 07:23:51