Svalbard

An open-source CLI for database backups. PostgreSQL or MySQL to S3, R2, or an SSH server.

A cron job or scheduled CI workflow starts Svalbard. Svalbard opens a snapshot of a PostgreSQL or MySQL database and writes a backup from it. The snapshot closes. Only then does Svalbard upload the backup to storage.

The problem

Most database backups are a cron job that pipes pg_dump into an upload. A dump can hold locks that block your app. An upload can fail halfway and leave a file that looks finished. The script can still exit 0.

Hosted backup services fix some of this. They also add a server, an account, and one more place that holds your database password.

What Svalbard does

Svalbard is a single binary that you run from cron or a CI schedule. There is no server and no hosted control plane.

It dumps the database from a snapshot and closes the snapshot before it uploads anything. A backup only counts when the dump and its completion record are both stored.

It supports PostgreSQL 15 to 18 and MySQL 8.4 and 9.7. It writes to Amazon S3, Cloudflare R2, any S3-compatible service, or an SSH server with SFTP or SCP.

svalbard backup

You run one command. It exits 0 only when the dump and its record are both in storage.

Running svalbard backup prints the run ID and the database it is dumping, then the dump size, then "Backup complete" with the names of the stored dump and record. It exits with status 0.

  1. 01

    configuration

    Reads the file, flags and environment.

  2. 02

    destination

    Checks the bucket or server. Writes nothing.

  3. 03

    staging

    Makes a private run directory.

  4. 04

    dump

    Dumps from a snapshot, then closes it.

  5. 05

    transfer

    Uploads the dump, then its record.

  6. 06

    cleanup

    Deletes the run directory.

Safe for the source database

A logical dump reads every row and keeps a snapshot open until it ends. Svalbard can't remove that cost, so it limits it. A watchdog ends the backup sessions when they block other sessions. Timeouts cap the lock wait and the length of the dump.

Every rule is written down in a database safety contract. Each one is either enforced on every run, a documented assumption, or a target that the test suite measures.

How it's built

Svalbard is written in Rust. Each database and each destination is an adapter behind a common interface. It uses the native clients, pg_dump and mysqldump, so a restore is a normal pg_restore or mysql import.

The tests run real backups across every source and destination pair. A GitHub Action wraps the CLI for scheduled backups in CI. It's MIT licensed.