OpsVault

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 restore

Opens a step-by-step TUI wizard:

  1. Select source — Local (files in your backup directory) or Remote (rclone)
  2. Select file — All available backup files are listed with size and modification date, newest first
  3. Select target database — Choose from databases in your config, or enter custom connection details
  4. 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

FlagRequiredDescription
--nameyesDatabase name as defined in config
--fileyesPath to the .sql.gz backup file
-y, --yesnoSkip the confirmation prompt

Example

opsvault restore run \
  --name myapp_prod \
  --file /var/backups/opsvault/myapp_prod_20240115_020001.sql.gz

OpsVault 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 --yes

What the restore does

PostgreSQL:

  1. Runs DROP SCHEMA public CASCADE + CREATE SCHEMA public inside the target database — clears all tables, indexes, and sequences without dropping the database or disconnecting active connections
  2. Decompresses the .sql.gz and pipes it into psql
  3. Password is passed via PGPASSWORD env var

MySQL:

  1. Decompresses the .sql.gz and pipes it into mysql
  2. mysqldump already includes DROP TABLE IF EXISTS before each table, so no pre-clean step is needed
  3. Password is passed via a temporary .my.cnf file (mode 0600)

Finding backup files

Use backup list to see available local files:

opsvault backup list

Or check backup history to find a specific point in time:

opsvault backup history --db myapp_prod

On this page