Help › Import, export and back up

Back up and restore a database

Back up a database to a file and restore one, which databases this works for, which programs it uses and where Querlyn finds them.

Querlyn 0.1.0 is not released yet. This help describes it ahead of release.

Querlyn can write a whole database to a file, and put such a file back. How it does that depends on the database.

Which databases

DatabaseHowWhere the file is
PostgreSQLpg_dump and pg_restore, which come with QuerlynOn your computer
MySQLmysqldump and mysql, which you installOn your computer
MariaDBmariadb-dump and mariadb, which you installOn your computer
SQLiteSQLite's own backupOn your computer
DuckDBA copy of the database as a DuckDB fileOn your computer
SQL ServerBACKUP DATABASE and RESTORE DATABASE, run by the serverOn the server, at a path you type

Amazon Redshift, ClickHouse, Oracle Database, Snowflake, BigQuery, MongoDB, Cassandra, Kafka, Redis and DynamoDB cannot be backed up from Querlyn; for MongoDB, use mongodump, and for Cassandra nodetool snapshot on each node. These systems keep their backups on the server side, with their own means. To move data out of them, see Export results to a file and Copy tables between connections.

Some databases that speak another engine's protocol cannot be backed up with that engine's tools, and Querlyn says why when you choose File › Back Up…: pg_dump does not work with CockroachDB, leaves out YugabyteDB's tablet settings, mysqldump fails on TiDB, and Azure SQL Database has no BACKUP DATABASE. See Connect to CockroachDB, TiDB and other compatible databases.

Back up

  1. Connect, and select the database in the sidebar. For MySQL and MariaDB select the database (shown as a schema), or nothing to back up the connection's own database. Selecting a schema or a table of a PostgreSQL database starts with the backup narrowed to it.
  2. Choose File › Back Up…, or right-click the connection or database and choose Back Up….
  3. Check the line at the top of the dialog. It names the program that will run, for example "Uses pg_dump 18.6 (bundled with Querlyn)", or says why none can.
  4. Set the options you need (below), choose Choose… to say where the file goes, and choose Back Up.

Backing up only reads. It never asks for confirmation, and it works on a read-only connection.

The file is written under a temporary name and gets its real name only when the backup succeeded. A failed or cancelled backup leaves no file.

Backup options

DatabaseOptions
PostgreSQLFormat: Custom (pg_restore), a compressed archive, or Plain SQL. Include: Definitions and data, Definitions only or Data only. Objects: Whole database, Chosen schemas or Chosen tables. Leave out owners; leave out privileges.
MySQL, MariaDBInclude as above; chosen tables; stored procedures and functions, triggers and scheduled events. The backup is taken as a consistent snapshot without locking tables.
SQL ServerPath on server. Copy-only (on at the start, so that the server's own backup schedule is not disturbed); verify checksums; compress. A file already at that path is overwritten.
SQLite, DuckDBNone. A DuckDB backup does not include other attached databases.

Restore

Warning: Restoring writes a backup into a database and can replace what the database holds. On SQLite, DuckDB and SQL Server it replaces the whole database. Check twice which connection and database you are on.

  1. Connect, and select the database to restore into.
  2. Choose File › Restore…, or right-click and choose Restore….
  3. Choose the backup file (for SQL Server, type its path on the server).
  4. Read the sentence that says what the restore will do and what happens if it fails, then choose Restore….
  5. Confirm. On Testing, Staging and Production connections you must type the database's name exactly; on Local and Development connections a plain question is asked. The setting that turns confirmations off does not turn this one off.

A read-only connection refuses restores.

What a restore does to what is already there

DatabaseWhat happens to what the database holds
PostgreSQLIt stays. The backup's tables and other objects are added, and one that already exists makes the restore fail. With Drop existing objects first, the objects the backup also holds are dropped and created again; what the backup does not hold stays. A restore of data only adds rows to tables that must already exist.
PostgreSQL, a plain SQL fileWhatever the file says. A backup made with Drop each object before creating it drops what it then creates; any other file fails on an object that already exists.
MySQL, MariaDBA dump made by Querlyn drops each table it holds and creates it again; a dump of data only adds its rows. Tables the dump does not hold stay.
SQLite, DuckDB, SQL ServerEverything is replaced: the database becomes what the backup holds.

The dialog says which of these applies, for the options you chose, before you start.

What happens if a restore fails

DatabaseIf it fails or you cancel
PostgreSQLNothing is changed, as long as All or nothing is on (it is at the start).
SQLite, DuckDBNothing is changed.
MySQL, MariaDBNot all or nothing. What was restored before the failure stays.
SQL ServerThe database is left unusable, in the state Restoring, until a restore completes.

The dialog says which of these applies before you start.

Restore options

DatabaseOptions
PostgreSQLAll or nothing; drop existing objects first; do not restore owners; do not restore privileges. Without dropping first, restoring into a database that already has the backup's tables fails. A plain SQL file is run by Querlyn itself in one transaction; it must be a file written by pg_dump, not compressed.
MySQL, MariaDBNone. A dump that switches to another database (made with --databases) is refused before anything runs.
SQL ServerOverwrite even if the backup is of another database; disconnect other sessions first.

While it runs

The dialog shows progress and the program's messages. Hide keeps the run going: the status bar then shows it, and a click there or File › Show Backup or Restore brings the dialog back. Cancel (File › Cancel Backup or Restore) stops it.

When it ends, the dialog says how long it took. Copy Messages (Command Palette › Database: Copy Backup Messages) copies what the program printed, which is what to send along when you ask for help.

One backup or restore runs at a time. Quitting, or disconnecting its connection, asks whether to cancel it or keep it running.

Where Querlyn finds the programs

For PostgreSQL, Querlyn uses the pg_dump and pg_restore that come with it. For MySQL and MariaDB, and for a PostgreSQL server newer than the programs Querlyn brings, it looks on your computer:

  1. in the folder you set in Querlyn › Open Settings under Tools,
  2. on your PATH,
  3. in the usual places an installer or Homebrew puts them.

Rules:

  • pg_dump must be at least as new as the server.
  • MySQL servers need MySQL's programs and MariaDB servers need MariaDB's; they are not interchangeable.

Under Tools in Settings, each family shows the program that would be used, its version and where it was found, or why none can be used. Type a folder there to point Querlyn at an installation. Find Tools Again looks again after you installed something (Command Palette › Database: Find Backup Tools).

Passwords and encryption

  • Your password is handed to the backup program privately, not on its command line where other programs could see it. For MySQL and MariaDB it is in a file only you can read, which Querlyn deletes when the run ends.
  • The program uses the connection's encryption settings; see Encrypt a connection with TLS.
  • A backup through an SSH tunnel or a Kubernetes or SSM tunnel works. Querlyn opens a port on your own computer for the program for as long as the run takes, and lets only that program use it.

Note: For MySQL and MariaDB through a tunnel, the program cannot check that the server's certificate carries the server's name, because it connects to your own computer. If the connection verifies the name, the dialog shows Allow without the host-name check for this run, not ticked, and the run is disabled until you tick it. The rest of the certificate is still checked.

A backup file is not encrypted by Querlyn. Keep it as carefully as the database.

Help for Querlyn 0.1.0. All help topics