Skip to content

querybara restore

  • CLI
  • PostgreSQL
  • MySQL
  • MariaDB
  • MongoDB
  • Redis / Valkey

querybara restore restores a backup file into a database: a Querybara archive (.qbak), a .sql or .sql.gz script, or a pg_dump archive. From an archive you can restore everything or selected objects, into the original database or another one. Before it changes anything that exists, it lists what would be dropped and asks.

querybara restore --help
Usage: querybara restore [options] <target> <file>
restore a backup (.qbak, .sql, .sql.gz or a pg_dump archive) into a database
Arguments:
target profile name or id, or connection URI
file the backup file
Options:
--list print the objects in the archive and exit; nothing
connects
--dry-run show what would be restored and dropped, and change
nothing
--select <object> restore this object (id, schema.name or name) and
what it needs; repeatable
--schema-only the structure without data
--data-only the data without the structure
--database <name> the database to restore into (Redis: its number)
--create-database create --database first (PostgreSQL, MySQL, MariaDB)
--native run a SQL script with psql or mysql (pg_dump
archives use pg_restore)
--continue keep going after a failed statement (default: stop
and roll back)
--error-log <file> write failed statements and their errors to a file
--replace Redis: overwrite keys that exist (default: keep
them)
--keep-expiry Redis: expire keys at their original time, not their
TTL from now
--passphrase-env <VAR> take the passphrase from this variable (default
QUERYBARA_BACKUP_PASSPHRASE, else a prompt)
--read-only refuse to write (the restore is refused)
-y, --yes restore over existing objects and into production
without asking
--tls <mode> TLS mode for this run: disable, require, verify-ca
or verify-full
--ssh <user@host[:port]> reach URI targets through this SSH server; repeat
for jump hosts, in order
--ssh-key <path> SSH private key file (OpenSSH, PEM or PuTTY .ppk)
--ssh-password-env <VAR> take the SSH password from this variable (default
QUERYBARA_SSH_PASSWORD, else a prompt)
--ssh-agent log in with the keys of ssh-agent (SSH_AUTH_SOCK) or
Pageant
--proxy <url> reach URI targets (or their first SSH server)
through socks5://host:port or http://host:port
--ssh-accept-new trust and remember an SSH host key not seen before
(a changed key is always refused)
--known-hosts <path> SSH known hosts file (default: the desktop app's)
-h, --help show help for a command
Restoring over existing objects drops and recreates them (Redis --replace overwrites keys):
the objects are listed first and the restore needs a confirmation or --yes, every time.
Read-only targets refuse; production and "confirm writes" profiles ask first. PostgreSQL
restores run in one transaction; MySQL and MariaDB commit table by table.
Exit codes: 0 restored, 1 restored but statements failed (--continue), 2 failed, 130
interrupted.
Examples:
querybara restore dev shop.qbak --list
querybara restore dev shop.qbak --database shop_copy --create-database
querybara restore dev shop.qbak --select public.orders --dry-run
querybara restore dev shop.sql.gz --native --continue --error-log restore-errors.log

The --tls and SSH options are described in Global options.

List what an archive holds, without connecting:

Terminal window
querybara restore shop-dev shop.qbak --list

Restore into a new database:

Terminal window
querybara restore shop-dev shop.qbak --database shop_copy --create-database

Restore one table, after checking the plan:

Terminal window
querybara restore shop-dev shop.qbak --select shop.orders --dry-run
querybara restore shop-dev shop.qbak --select shop.orders --database shop_copy --create-database

Run a SQL dump with psql or mysql, keeping going past errors:

Terminal window
querybara restore shop-dev shop.sql.gz --native --continue --error-log restore-errors.log

Restore Redis keys with their original expiry times, overwriting keys that exist:

Terminal window
querybara restore cache-dev carts.qbak --replace --keep-expiry

--select takes an object id, schema.name or a name, and can be repeated. The restore also takes what the chosen objects depend on and what is attached to them. A foreign key comes only with both of its tables. --select needs a Querybara archive.

--schema-only restores the structure without data, and --data-only the data without the structure.

The passphrase comes from QUERYBARA_BACKUP_PASSPHRASE, from the variable --passphrase-env names, or from a hidden prompt.

  • Restoring over existing objects drops and recreates them, and Redis --replace overwrites keys. The objects are listed first, and the restore needs a confirmation or --yes, every time, on every profile.
  • Read-only targets refuse, and so does --read-only.
  • Production and confirm-writes profiles ask before any restore.
  • PostgreSQL restores run in one transaction. MySQL and MariaDB commit table by table.
Code Meaning
0 Restored
1 Restored, but statements failed (--continue)
2 Failed
130 Interrupted

Documents Querybara 0.1.1 · built frombc9f5aa