NEW RasterizedDB 1.1.0 is out: sharding and the gateway, the message broker, roles and row-level security, compression, .NET on NuGet, and the enterprise edition. What's new ›
DOCS / RASTERIZEDDB SERVER / BACKUP AND RESTORE

Backup and restore

RasterizedDB backs a server up continuously to any S3-compatible object store: AWS S3, MinIO, RustFS, Ceph RGW, Cloudflare R2, Backblaze B2 or Wasabi. You get full snapshots on a schedule plus an archive of the write-ahead log, so you can restore the latest state after losing a host, or rewind to a point in time before a bad migration.

Backups are built into the standard server and do nothing until you name a bucket.

How a backup is made

  • A snapshot is the whole data directory, every database in it, packed and compressed with zstd into one object. It is taken while the server keeps taking writes; the archived log makes it consistent.
  • The archived log: at each checkpoint the write-ahead log is staged locally instead of discarded, and every few minutes the staged log is uploaded as one compressed bundle.
  • A catalogue, MANIFEST.json, lists every snapshot and bundle and the range of commits each one covers.
text
s3://my-backups/prod/orders/
    MANIFEST.json
    snapshots/snap-20260820T134737Z-b57e1f06.rdba.zst
    wal/0000000000000000-0000000000000003.wseg.zst
    wal/<database>/...          one log per database created with CREATE DATABASE

A restore downloads one snapshot and the log bundles after it, and replays the log up to the point you ask for. A transaction is either wholly in the restore or wholly absent.

The request count depends on time, not on how much you write: at the defaults (a daily snapshot and a five-minute log flush) it is roughly 600 requests a day.

Turn backups on

Name a bucket and a prefix. The first snapshot is taken as soon as the server starts against an empty prefix, and the log is archived from then on.

sh
export AWS_ACCESS_KEY_ID=AKIA...
export AWS_SECRET_ACCESS_KEY=...
rasterizeddb --location /var/lib/rasterizeddb \
  --s3-bucket my-backups --s3-region eu-central-1 \
  --s3-prefix prod/orders

The server logs Backing up to s3://my-backups/prod/orders/ as instance rdb-… once it is connected. Check it from SQL:

sql
SHOW BACKUP STATUS;
SHOW BACKUPS;

By default a server whose bucket does not answer at start-up refuses to start (could not start backups: …), so you are never silently running without backups. See Starting while the bucket is unreachable for the alternative.

Credentials

Credentials come from AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN, or from --s3-access-key, --s3-secret-key and --s3-session-token. Prefer the environment variables: a command-line argument is visible to anyone who can list processes. The access key and secret must be given together, both as flags or both from the environment.

Give the credentials these permissions on the prefix and nothing else: s3:PutObject, s3:GetObject, s3:DeleteObject, s3:AbortMultipartUpload and s3:ListBucketMultipartUploads.

AWS S3

sh
export AWS_ACCESS_KEY_ID=AKIA...
export AWS_SECRET_ACCESS_KEY=...
rasterizeddb --location /var/lib/rasterizeddb \
  --s3-bucket my-backups --s3-region eu-central-1 --s3-prefix prod/orders

The endpoint defaults to https://s3.<region>.amazonaws.com, and buckets are addressed virtual-host style (bucket.host/key). The region defaults to $AWS_REGION, then $AWS_DEFAULT_REGION, then us-east-1.

MinIO

MinIO needs path-style addressing:

sh
export AWS_ACCESS_KEY_ID=minioadmin-user
export AWS_SECRET_ACCESS_KEY=minioadmin-secret
rasterizeddb --location /var/lib/rasterizeddb \
  --s3-endpoint http://minio.internal:9000 --s3-path-style \
  --s3-bucket rasterizeddb-backup --s3-prefix prod

Create the bucket first; the server does not create buckets.

RustFS

RustFS is also S3-compatible and is used the same way, with path-style addressing:

sh
export AWS_ACCESS_KEY_ID=rustfs-user
export AWS_SECRET_ACCESS_KEY=rustfs-secret
export AWS_REGION=us-east-1
rasterizeddb --location /var/lib/rasterizeddb \
  --s3-endpoint http://127.0.0.1:9000 --s3-path-style \
  --s3-bucket rasterizeddb-backup

The RasterizedDB-with-RustFS Docker image runs exactly this inside one container; see Docker.

Other providers

Cloudflare R2, Backblaze B2, Wasabi and Ceph RGW work by pointing --s3-endpoint at the provider's S3 endpoint. Add --s3-path-style for a provider that does not serve virtual-host buckets, or for a bucket name that is not DNS-safe. --s3-endpoint also falls back to $AWS_ENDPOINT_URL and $AWS_ENDPOINT_URL_S3. A URL without a scheme is treated as https://.

Backup flags

FlagDefaultWhat it does
--s3-bucket <BUCKET>noneBucket to back up into. Setting it is what enables backups.
--s3-prefix <PREFIX>""Key prefix within the bucket. One database directory per prefix.
--s3-region <REGION>$AWS_REGION, $AWS_DEFAULT_REGION, else us-east-1Region for request signing.
--s3-endpoint <URL>$AWS_ENDPOINT_URL, else the regional AWS endpointEndpoint for non-AWS stores. http:// and https:// are accepted.
--s3-access-key <KEY>$AWS_ACCESS_KEY_IDAccess key.
--s3-secret-key <SECRET>$AWS_SECRET_ACCESS_KEYSecret key. Prefer the environment variable.
--s3-session-token <TOKEN>$AWS_SESSION_TOKENSession token for temporary credentials.
--s3-path-styleoffAddress buckets as host/bucket/key. Needed by MinIO and RustFS.
--s3-snapshot-interval-secs <N>86400 (daily)Seconds between automatic snapshots; 0 for manual only. Measured from the last snapshot in the catalogue, so restarts do not postpone it.
--s3-wal-flush-secs <N>300Seconds between log uploads; 0 for manual only. This is your recovery point objective: a lost host can lose at most this much recent write history.
--s3-wal-bundle-mb <MB>64Upload early when this much log is staged.
--s3-retain-snapshots <N>7Snapshots to keep, oldest deleted first; 0 keeps everything. Log bundles only an expired snapshot could use are deleted with it.
--s3-rollover-hours <HOURS>0 (never)Every this many hours, take a fresh full snapshot and, once it has landed, delete every earlier generation.
--s3-incremental-min-mb <MIB>0 (off)Store files of at least this size as separate objects, so a later snapshot reuses unchanged ones instead of uploading them again.
--s3-staging-max-mb <MB>4096Staged log after which archiving is suspended; 0 for no ceiling. See When uploads keep failing.
--s3-backup-nowoffTake a snapshot at every start, on top of the schedule.
--s3-start-offlineoffStart even if the bucket does not answer; hold the log locally until it does.
--s3-snapshot-level <1..22>12zstd level for snapshots.
--s3-segment-level <1..22>6zstd level for log bundles.
--s3-compression-threads <N>0Compression threads; 0 uses half the cores, at most 8.
--s3-no-long-rangeoffTurn off zstd long-distance matching.
--s3-part-size-mb <MB>32 (minimum 5)Multipart part size. Raise it for a database beyond about 320 GB, where 32 MiB parts reach S3's 10,000-part limit.
--s3-upload-concurrency <N>3Parts uploaded at once. Peak memory is about this times the part size.
--s3-max-attempts <N>4Attempts per request, including the first.

Backup statements

These run over the PostgreSQL and the native protocol, on a server started with --s3-bucket.

sql
BACKUP DATABASE;        -- take a snapshot now, then upload the log so it is restorable
BACKUP DATABASE TO S3;  -- the same
BACKUP WAL;             -- upload all log written so far: a point-in-time barrier
BACKUP PRUNE;           -- apply the retention policy now
BACKUP ROLLOVER;        -- fresh full snapshot, then delete every earlier generation
SHOW BACKUPS;           -- one row per snapshot and per log bundle
SHOW BACKUP STATUS;     -- configuration, catalogue state and the last attempts

BACKUP WAL before a risky change gives you a restore point exactly at that moment, independent of the flush interval.

SHOW BACKUPS returns kind (snapshot or wal), id, created_at, start_lsn, end_lsn, uncompressed_bytes, compressed_bytes and detail. A snapshot that could not cover every table starts its detail with INCOMPLETE: and names the tables.

SHOW BACKUP STATUS returns metric, value and detail rows. The ones to watch:

MetricMeaning
configuredtrue when backups are on.
catalogueloaded, unreachable (started offline and still waiting for the bucket) or refused.
snapshots, wal_bundlesWhat the catalogue holds.
newest_snapshot, newest_snapshot_completeThe latest snapshot and whether it covers every table.
recoverable_to_lsnThe highest commit any archived log bundle covers.
staged_bytes, staging_max_bytes, archiving_suspendedLog waiting to be uploaded, and whether archiving has been suspended.
last_snapshot_outcome, last_wal_flush_outcome, last_rollover_outcomeok, failed or running, with the time in last_…_attempt_at.
last_error, last_error_atThe most recent failure since start-up.
next_snapshot_at, next_wal_flush_at, next_rollover_atWhen each schedule next fires.

Retention

Two policies, which work independently:

  • By count: --s3-retain-snapshots (default 7) keeps that many snapshots; the oldest goes first, with the log bundles only it could use.
  • By time: --s3-rollover-hours takes a fresh full snapshot every so many hours and then deletes every earlier generation, so the bucket goes back to one self-contained backup. The delete happens only after the new snapshot succeeds.

Pruning runs on its own; BACKUP PRUNE applies it now.

Also set a lifecycle rule on the bucket to abort incomplete multipart uploads. The server cleans up its own leftovers at start-up, but a server that is killed and never restarted leaves its parts behind.

Restore

There are three restore paths. All of them take the same --s3-bucket, --s3-prefix, endpoint and credential flags as the backup.

Restore into a new directory

--restore-to rebuilds the database into a directory and exits without starting a server. Use it to verify a backup, to clone a database, or to rebuild on a new host:

sh
rasterizeddb --s3-bucket my-backups --s3-region eu-central-1 --s3-prefix prod/orders \
  --restore-to /var/lib/rasterizeddb-restored
text
Restoring from s3://my-backups/prod/orders/ into /var/lib/rasterizeddb-restored
Restored snapshot snap-20260820T134737Z-b57e1f06 (2026-08-20T13:47:37Z): 412 files, 1862346752 bytes, 14 log bundles replayed, 90211 records applied, 12 discarded as uncommitted, recovered to LSN end of archive

The directory must be empty or not exist, and its parent must be writable by the server: the restore is built in a sibling directory and renamed into place only when complete, so a failed restore leaves nothing behind and can simply be run again.

Then start a server on it:

sh
rasterizeddb --location /var/lib/rasterizeddb-restored

Restore in place

--restore-from-s3 rebuilds the directory at --location before any table is opened, then starts the server on it:

sh
rasterizeddb --location /var/lib/rasterizeddb \
  --s3-bucket my-backups --s3-region eu-central-1 --s3-prefix prod/orders \
  --restore-from-s3

If --location already holds data, the restore refuses unless you add --restore-replace. That renames the existing directory to <name>.pre-restore-<timestamp> next to it; it is never deleted, because it may be the last local copy.

sh
# Rewind past a bad migration, keeping the damaged copy aside.
rasterizeddb --location /var/lib/rasterizeddb \
  --s3-bucket my-backups --s3-region eu-central-1 --s3-prefix prod/orders \
  --restore-from-s3 --restore-replace \
  --restore-at-time '2026-08-20T09:55:00Z'

The restored database is a new backup instance (see After a restore), and the same command line also turns backups on against the prefix it restored from. If the server then stops with could not start backups: … already holds backups for instance …, the restore itself is complete: start the server again without --restore-from-s3 and with a new --s3-prefix. To avoid the stop, restore with --restore-to and start the server on the result with the new prefix.

Restore from SQL

From a running server, RESTORE always writes to a new directory on the server's host; it never replaces the live database:

sql
RESTORE DATABASE FROM S3 TO '/var/lib/rasterizeddb-restored';
RESTORE DATABASE FROM S3 TO '/tmp/verify' AT LSN 918273;
RESTORE DATABASE FROM S3 TO '/tmp/verify' AT TIME '2026-08-20T10:00:00Z';
RESTORE DATABASE FROM SNAPSHOT 'snap-20260820T134737Z-b57e1f06' TO '/tmp/verify';

It returns snapshot_id, target_dir, recovered_to_lsn, files_restored, bytes_restored, segments_replayed, records_applied and records_discarded.

Restore flags

FlagWhat it does
--restore-to <DIR>Restore into DIR and exit. Needs no --location.
--restore-from-s3Restore over --location before opening anything, then serve.
--restore-replaceAllow --restore-from-s3 over a --location that holds data, by renaming it aside.
--restore-at-lsn <N>Stop at this commit sequence. Exact.
--restore-at-time <TIMESTAMP>Stop at the last log upload at or before this instant.
--restore-snapshot <ID>Restore this snapshot, replaying only enough log to make it consistent.

Give at most one of --restore-at-lsn, --restore-at-time and --restore-snapshot; with none, the restore goes to the end of the archive.

Point-in-time recovery

Pick the target one of three ways:

  • AT TIME / --restore-at-time: an instant such as '2026-08-20T10:00:00Z', '2026-08-20 10:00:00', '2026-08-20 10:00+02:00' or just '2026-08-20'. A time without an offset is read as UTC. Log records carry no timestamps, so this resolves to the end of the last log upload at or before that instant: it is as precise as --s3-wal-flush-secs, or as your last BACKUP WAL.
  • AT LSN / --restore-at-lsn: an exact commit sequence, from the start_lsn / end_lsn columns of SHOW BACKUPS or recoverable_to_lsn in SHOW BACKUP STATUS. The number counts commits of the default database (the one at --location itself); other databases are cut at the moment that commit was archived.
  • FROM SNAPSHOT / --restore-snapshot: a snapshot id from SHOW BACKUPS.

A restore refuses, and names an older snapshot to use instead, when the catalogue no longer reaches the point a snapshot needs (for example after bundles were deleted by hand), rather than handing back a database that opens and is wrong.

After a restore

  • A restored database is a new backup instance. It does not take over the identity of the database it came from, so it never writes into the prefix it was restored from. When you turn backups on for it, give it a new --s3-prefix.
  • Tables on other disks (storage pools) are included. An in-place restore copies each location's files back to its own path; that location must be empty or absent. A restore elsewhere puts them in <target>/pool-location-<hash> inside the restored directory, so the copy never writes to the source's disks. Move tables back out with STORAGE MOVE TABLE once you have checked it.
  • Tables on a key/value store (key/value storage) come back as ordinary tables in the restored directory, as of the snapshot's copy: they have no log, so a point-in-time target does not reach them, and the restore says so. Snapshot more often to narrow that gap.
  • Replication files come back with the data. Keep them when restoring a node of a replicated cluster; remove them when using the restore to seed a different node. See Replication.
  • Branch merge bases are not in snapshots; a restored branch comes back without one. RESET BRANCH makes a new one. See Branching.

Test your restores: run --restore-to into a scratch directory, start a server on it and query it. For a large database, run a full snapshot and a --restore-to over your real endpoint before relying on it; long transfers can outlast temporary credentials, which the server does not refresh.

One database per prefix, and wiping a backed-up database

Each data directory carries a backup_instance.id file, and the catalogue records which instance owns the prefix. A server whose instance does not match refuses to start:

text
could not start backups: s3://my-backups/prod/orders/MANIFEST.json already holds backups for instance rdb-20260801T090000Z-…, but this database is rdb-20261127T101500Z-…. Point --s3-prefix somewhere else, or restore from that prefix instead.

This stops two servers sharing a prefix and overwriting each other's catalogue. It also means that wiping a backed-up database is a two-part job: an emptied --location gets a new instance id on its next start, and the old prefix then refuses it. When you clear the data directory, also either:

  • point --s3-prefix at a new prefix, or
  • delete the old prefix's objects (only if you no longer need those backups).

Under a service manager with automatic restart, a refused start becomes a restart loop; limit restarts (for systemd, StartLimitIntervalSec and StartLimitBurst) so a misconfiguration stops instead of spinning.

Two nodes of a replicated cluster are two instances too: give each node its own prefix.

Starting while the bucket is unreachable

With --s3-start-offline, a server whose bucket does not answer at boot starts anyway. While it waits it:

  • keeps staging the log on local disk (under --s3-staging-max-mb), so writes during the outage are archived later;
  • uploads nothing and refuses BACKUP … and SHOW BACKUPS;
  • retries reading the catalogue in the background, starting after 10 seconds and backing off to every 5 minutes.

SHOW BACKUP STATUS shows catalogue = unreachable meanwhile. Once the bucket answers, the held log is uploaded and the schedules start. A bucket that answers with another database's catalogue still refuses the start: that is a misconfiguration, not an outage.

When uploads keep failing

If uploads fail (expired credentials, a changed bucket policy, the network), staged log accumulates on local disk. Past --s3-staging-max-mb (default 4096 MiB), archiving is suspended: checkpoints go back to discarding the log so the disk does not fill and stop the database, and the server logs loudly that point-in-time recovery is broken from that moment. SHOW BACKUP STATUS shows archiving_suspended and last_error.

Archiving resumes by itself once staging drains to half the ceiling. The gap cannot be filled afterwards, so take a new snapshot (BACKUP DATABASE) as soon as uploads work again.

Limits

  • The unit of backup and restore is the whole data directory, every database in it. There is no single-table restore.
  • No client-side encryption: data at rest is protected only by whatever the bucket applies.
  • Point-in-time by time is only as fine as the log upload interval; use BACKUP WAL or AT LSN when you need an exact point.
  • Tables on a key/value store restore as of the snapshot, not to a point in time. In-memory tables and stores the server cannot reach are not copied; the snapshot is marked INCOMPLETE.
  • An in-memory server (--in-memory) cannot be backed up.
✓ page rendered in 206 µs axum + tera + htmx · no other javascript