Expand description
§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.
§Architecture
Your App → DurabilityLayer → SQLite DB (local, fast)
└→ S3 Bucket (backup, source of truth)One process, one DB, one bucket prefix. Always. The bucket is a backup, not a replication bus.
§Quick Start
ⓘ
use std::sync::Arc;
use wal_backup::{Config, DurabilityLayer, ObjectStoreBucket, SyncMode};
let store = wal_backup::build_s3_store_from_env("my-bucket")?;
let bucket = Arc::new(
ObjectStoreBucket::new(store, "my-app".to_string())?
.with_writer_id("server-1"),
);
let config = Config::new("/data/my.db")
.with_sync_mode(SyncMode::Immediate);
let layer = DurabilityLayer::open(config, bucket).await?;
// Write SQL — WAL frames ship to S3 automatically
layer.with_conn(|conn| {
conn.execute("INSERT INTO users (name) VALUES (?)", ["Alice"])
}).await?;
// Graceful shutdown: checkpoint + final sync + release locks
layer.shutdown().await?;§Multi-writer protection
Two processes writing to the same bucket prefix = silent data corruption. wal-backup prevents this at three levels:
- flock (
.db.lock): Two processes, same machine, same DB →Error::DatabaseLocked - lock.json (bucket): Two processes, anywhere, same prefix →
Error::ReplicaLocked - writer.json (bucket): Wrong server opening the wrong prefix →
Error::WrongWriter
§Error handling
ⓘ
match DurabilityLayer::open(config, bucket).await {
Err(e) if e.is_database_locked() => { /* another process on this machine */ }
Err(e) if e.is_replica_locked() => { /* another process anywhere */ }
Err(e) if e.is_wrong_writer() => { /* wrong bucket prefix */ }
Err(e) => return Err(e.into()),
Ok(layer) => { /* use it */ }
}Re-exports§
pub use config::Config;pub use config::RestoreBehavior;pub use config::SyncMode;pub use connection::DurabilityLayer;pub use connection::HealthReport;pub use error::Error;pub use error::Result;pub use storage::compressed::CompressedBucketStore;pub use storage::encrypted::EncryptedBucketStore;pub use storage::object_store_util::build_s3_store;pub use storage::object_store_util::build_s3_store_from_env;pub use storage::BucketStore;pub use storage::ObjectStoreBucket;pub use metrics::noop_metrics;pub use metrics::Metrics;pub use metrics::NoopMetrics;pub use replication::manifest::L1File;pub use replication::manifest::Manifest;pub use util::compute_sha256_file;pub use wal::WalFile;pub use wal::WalFrame;pub use wal::WalHeader;
Modules§
- config
- Configuration for the WAL replication layer.
- connection
- error
- metrics
- replication
- restore
- storage
- util
- wal