SQLite continuous replication

Scheduled snapshots restore a SQLite database to the moment each one was taken. Turn on continuous replication and ButlerDB also streams every change the app commits to your storage, within about a second, so you can restore to any moment: the minute before a bad migration, or before someone deleted the wrong rows.

Every changeShipped to one destination within about a second, while the app keeps running.
Any momentRestore to a date and time in the window (7 days by default), to a new file.
Tested dailyThe latest replicated state is restored and integrity-checked every day.

How it works

Replication uses Litestream, the open-source SQLite replicator, run by ButlerDB for every replicated database on the server. Snapshots keep running on their schedule to every destination in the database's backup policy; replication adds one destination that receives each change as it happens. Litestream keeps a snapshot each day and every change since, and drops what's older than the window.

Requirements and limits

Litestream changes the database slightly: it adds two small tables, _litestream_seq and _litestream_lock, and takes over checkpointing (folding the write-ahead log back into the file). Apps don't notice, but don't run a second replicator, or your own checkpoints, on the same file.

Turning it on

In the app

  1. Open the SQLite database (add it first with Add SQLite Database… if needed).
  2. Under Continuous Replication, choose Turn On…, pick the destination and how far back restores should reach, and choose Turn On.

The section then shows the latest change on the replica and the oldest moment you can restore.

From the command line

butlerdb install litestream
butlerdb sqlite replicate shop --to offsite --window 7d
butlerdb sqlite replica shop          # status: latest change, how far back
butlerdb sqlite replicate shop --off  # stop; what's on the destination stays

Restoring to a point in time

A restore writes a new file next to the live database and never touches the live one. Stop the app and swap the file in when you're ready, or copy the rows you need out of it.

In the app

Choose Restore to a Point in Time…, pick the date and time (or the latest replicated state) and the new file's path, and choose Restore.

From the command line

butlerdb sqlite restore shop --at "2026-11-03 14:05" --to /srv/shop/restored.sqlite
butlerdb sqlite restore shop --at "15m ago" --to /srv/shop/restored.sqlite
butlerdb sqlite restore shop --at latest --to /srv/shop/restored.sqlite

Times are the server's local time unless written with a zone (2026-11-03T19:05:00Z). A moment after the last change restores the latest state; one before the window is refused, and says how far back the replica reaches. Older moments are still there in your snapshot backups.

Restore tests and warnings

Once a day ButlerDB restores the latest replicated state into scratch space and runs SQLite's full integrity check, and the result joins the database's restore-test history (and its webhook, if one is set). Run one any time with Test Restore or butlerdb sqlite replica shop --test. If replication stops running, the database shows a backup warning in the app until it's back.

Restoring without ButlerDB

The replica is plain Litestream, so the stock litestream tool can restore it anywhere. It lives in the destination under <instance>/litestream:

# a local or mounted folder
litestream restore -o shop.sqlite -timestamp 2026-11-03T19:05:00Z file:///Volumes/Backups/shop/litestream
# S3-compatible storage (credentials in LITESTREAM_ACCESS_KEY_ID / LITESTREAM_SECRET_ACCESS_KEY;
# for anything but AWS, add the endpoint)
litestream restore -o shop.sqlite "s3://my-bucket/prefix/shop/litestream?endpoint=https://s3.example.com"

Leave out -timestamp for the latest state. Use Litestream 0.5 or later.