restore
Restore a database from a local or remote backup file.
The restore command restores a gzip-compressed SQL dump to a target database. Run it without arguments to open the interactive wizard.
Restore overwrites the target database. All existing data will be replaced by the contents of the backup file. There is no undo. The wizard always asks for explicit confirmation before proceeding.
restore (wizard)
opsvault restoreOpens a step-by-step TUI wizard:
- Select source — Local (files in your backup directory) or Remote (rclone)
- Select file — All available backup files are listed with size and modification date, newest first
- Select target database — Choose from databases in your config, or enter custom connection details
- Confirm — Review the full restore summary and confirm with Yes, restore now
Remote source
When you select Remote, OpsVault runs rclone lsjson --recursive against your configured remote and lists all .sql.gz files found. Select one and OpsVault downloads it before the restore begins.
Downloaded files are cached locally so that selecting the same file a second time is instant. Before using a cached file, OpsVault fetches the remote SHA1 hash via rclone hashsum SHA1 and compares it against the local copy — if they match, no download happens. If the backend does not support SHA1, the file is always re-downloaded.
Cache location: ~/.cache/opsvault/restore/ (or $XDG_CACHE_HOME/opsvault/restore/). Files accumulate over time; delete this directory manually to free disk space.
Custom database
The database picker includes a + Enter custom database details option. Use this to restore to a database that is not in your config — useful for testing a backup against a staging or scratch database. You enter type, host, port, database name, user, and password directly in the wizard.
restore run
For scripting and automation, the non-interactive command is still available:
opsvault restore run --name <database> --file <path> [flags]Flags
| Flag | Required | Description |
|---|---|---|
--name | yes | Database name as defined in config |
--file | yes | Path to the .sql.gz backup file |
-y, --yes | no | Skip the confirmation prompt |
Example
opsvault restore run \
--name myapp_prod \
--file /var/backups/opsvault/myapp_prod_20240115_020001.sql.gzOpsVault shows a summary before proceeding:
⚠ This will overwrite the target database. All existing data will be replaced.
Database: myapp_prod
Target: myapp (backup_user @ 127.0.0.1:5432)
File: /var/backups/opsvault/myapp_prod_20240115_020001.sql.gz (4.2 MB)
? Type yes to confirm:Type yes and press Enter to proceed. Anything else aborts.
Skip confirmation
Use --yes to restore non-interactively:
opsvault restore run --name myapp_prod --file ./backup.sql.gz --yesWhat the restore does
PostgreSQL:
- Runs
DROP SCHEMA public CASCADE+CREATE SCHEMA publicinside the target database — clears all tables, indexes, and sequences without dropping the database or disconnecting active connections - Decompresses the
.sql.gzand pipes it intopsql - Password is passed via
PGPASSWORDenv var
MySQL:
- Decompresses the
.sql.gzand pipes it intomysql mysqldumpalready includesDROP TABLE IF EXISTSbefore each table, so no pre-clean step is needed- Password is passed via a temporary
.my.cnffile (mode 0600)
Finding backup files
Use backup list to see available local files:
opsvault backup listOr check backup history to find a specific point in time:
opsvault backup history --db myapp_prod