wal-backup
Embedded SQLite WAL replication to S3-compatible object storage. Not a sidecar — a library.
Your app links the crate, calls DurabilityLayer::open(), and gets automatic S3 backup in the background. No separate process, no config files for another service, no health checks on something you didn't write.
// That's it. Your app writes SQL. S3 backup happens automatically.
let layer = open.await?;
layer.with_conn?;
layer.shutdown.await?; // checkpoint + final sync + release locks
Why not Litestream?
Litestream is a sidecar — a separate process you manage alongside your app. wal-backup is a library you embed in your app. Three lines instead of a separate service.
The key feature: start it, get your DB back
1. Your app writes data → backed up to S3 automatically
2. Server dies, local DB is gone
3. Start your app again → DB is restored from S3 → your data is back
No Turso, no API key, no hosted control plane. Your DB, your S3, your rules.
Multi-writer protection
Two processes writing to the same bucket prefix = silent data corruption. wal-backup prevents this at three levels:
| Guard | What it catches | How |
|---|---|---|
flock (.db.lock) |
Two processes, same machine, same DB | Kernel-enforced, released on process death |
| lock.json (bucket) | Two processes, anywhere, same prefix | Atomic put_if_not_exists + heartbeat every 10s |
| writer.json (bucket) | Wrong server opening the wrong prefix | Permanent ownership record, checked on open + every loop |
let bucket = new
.with_writer_id; // identity bound to the bucket, not the config
// Another server with writer_id "web-server-2" → Error::WrongWriter
// Another process on same machine → Error::DatabaseLocked
// Another process anywhere → Error::ReplicaLocked
Features
- Continuous WAL shipping: Frames replicated to S3 in the background as they are written
- Automatic restore on startup: Reconstructs local SQLite from bucket if local files are missing
- Automatic snapshots: Full DB snapshots uploaded at configurable intervals
- WAL segment checksums: Every segment is SHA256-verified on restore
- Atomic all-or-nothing restore: Both snapshot + WAL downloaded and verified before committing
- Encryption + compression: AES-256-GCM + gzip, enabled by default
- Memory-bounded uploads: Streaming multipart for files >64MB, temp files for compaction
- S3-compatible: AWS S3, OVH, Hetzner, Backblaze, MinIO, any S3-compatible provider
Quick Start
[]
= "0.2"
= { = "0.31", = ["bundled"] }
= { = "0.11", = ["aws"] }
= { = "1", = ["rt-multi-thread", "sync", "time", "fs"] }
With S3
use Arc;
use Duration;
use ;
async
With local filesystem (testing)
use LocalFileSystem;
let store = new;
let bucket = new;
Configuration
let config = new
// How often to poll WAL for new frames (Lazy mode) or max fallback wait (Immediate mode)
.with_poll_interval
// WAL size that triggers a snapshot (default: 50MB)
.with_snapshot_threshold
// Minimum time between snapshots (default: 1 hour)
.with_snapshot_interval
// What to do when local DB is newer than bucket
.with_restore_behavior
// Immediate: ship on write. Lazy: batched on interval.
.with_sync_mode
// For Immediate mode: how often to check for WAL changes
.with_immediate_poll_interval
// Disable replica lock for testing with shared buckets
.with_replica_lock_enabled;
SyncMode
Immediate: Ships every WAL frame as soon as written. Best for providers without per-request billing (OVH, Hetzner).Lazy: Ships WAL frames on a configurable interval. Lower request count. Best for per-request billing (AWS S3).
RestoreBehavior
UploadLocalIfNewer: If local DB is newer than bucket, upload it as the new snapshotAlwaysRestoreFromBucket: Always restore from bucket, overwriting local dataRecoverable: Restore from bucket, tolerate checksum mismatches with warningErrorIfConflict: Return error if local is newer than bucket
API
| Method | Description |
|---|---|
DurabilityLayer::open(config, bucket) |
Open or restore. Acquires locks, starts background tasks |
layer.with_conn(|conn| ...) |
Run SQL on the connection (preferred API) |
layer.conn().await |
Get a mutex guard to the raw rusqlite::Connection |
layer.sync_now().await |
Wait for all pending WAL frames to be uploaded |
layer.force_snapshot().await |
Trigger an immediate snapshot upload |
layer.is_healthy().await |
true if replication is caught up |
layer.shutdown().await |
Graceful shutdown: checkpoint + final sync + release locks |
Error handling
match open.await
Architecture
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Your App │ │ FrameShipper │ │ S3 Bucket │
│ (writes SQL) │─────▶│ (WAL → S3) │─────▶│ (the backup) │
└─────────────────┘ ├──────────────────┤ ├─────────────────┤
│ SnapshotManager │ │ manifest.json │
│ (DB → S3) │─────▶│ writer.json │
└──────────────────┘ │ lock.json │
│ snapshots/ │
│ wal/ │
└─────────────────┘
One process, one DB, one bucket prefix. The bucket is a backup, not a replication bus.
If you need data on another server, use wal-backup restore (one-shot, read-only).
If you need multi-tenant access, wrap the library in an API server — see crates/wal-backup-daemon/.
CLI
# Restore a database from S3
# Verify bucket integrity
# Show manifest status
All flags support WAL_BACKUP_* and AWS_* environment variables:
Examples
| Example | Description |
|---|---|
crates/wal-backup-api/ |
Multi-tenant HTTP API (many DBs, one server) |
crates/wal-backup-daemon/ |
Single-tenant HTTP API demo |
examples/s3_cloud.rs |
Full lifecycle with real S3 |
examples/crash_writer.rs |
Kill -9 crash recovery testing |
examples/e2e_harness.rs |
Full E2E test suite against real S3 |
scripts/lifecycle_test.sh |
Start/stop/restore loop test |
Testing
# E2E against real S3 (requires .env.e2e)
&&
# Kill -9 crash recovery test
&
&&
License
MIT OR Apache-2.0