Skip to content

Add Litestream SQLite backup to R2#27

Merged
swalkinshaw merged 1 commit intomainfrom
litestream-db-backup
Mar 19, 2026
Merged

Add Litestream SQLite backup to R2#27
swalkinshaw merged 1 commit intomainfrom
litestream-db-backup

Conversation

@swalkinshaw
Copy link
Member

@swalkinshaw swalkinshaw commented Mar 18, 2026

Continuously replicate the SQLite database to R2 via Litestream for production resilience and fast local dev setup. In production, Litestream wraps wpcomposer serve as a sidecar, streaming WAL changes to R2.

  • Add db restore CLI command to pull production snapshots locally
  • Add Ansible tasks to install Litestream and deploy its config
  • Wrap systemd ExecStart with litestream replicate -exec
  • Add make db-restore target
  • Add LitestreamConfig to app config (LITESTREAM_BUCKET, LITESTREAM_PATH)

Before mergin

  • setup separate R2 bucket for backups

Cost Estimate

  • R2 pricing: $0.015/GB/month storage, free egress, Class A ops $4.50/million, Class B $0.36/million.
  • Storage: Litestream keeps snapshots (default: every 24h) + WAL segments. With a ~162MB DB and daily snapshots with retention, expect ~500MB–1GB total.
  • Cost: ~$0.01–0.02/month
  • Operations: WAL segments upload continuously on writes. Pipeline runs every 5 min + HTTP telemetry writes. Estimate ~5,000–10,000 PUT operations/day.
  • Cost: ~$0.70/month
  • Restores: Free egress from R2, minimal Class B reads. Cost: effectively $0

Total estimate: ~$1/month or less

@swalkinshaw swalkinshaw force-pushed the litestream-db-backup branch from 265e2a9 to b613e0e Compare March 18, 2026 23:21
@swalkinshaw swalkinshaw marked this pull request as ready for review March 18, 2026 23:23
@swalkinshaw swalkinshaw force-pushed the litestream-db-backup branch from b613e0e to d9d1d35 Compare March 19, 2026 03:01
Continuously replicate the SQLite database to R2 via Litestream for
production resilience and fast local dev setup. In production, Litestream
wraps `wpcomposer serve` as a sidecar, streaming WAL changes to R2.

- Add `db restore` CLI command to pull production snapshots locally
- Add Ansible tasks to install Litestream and deploy its config
- Wrap systemd ExecStart with `litestream replicate -exec`
- Add `make db-restore` target
- Add LitestreamConfig to app config (LITESTREAM_BUCKET, LITESTREAM_PATH)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@swalkinshaw swalkinshaw force-pushed the litestream-db-backup branch from d9d1d35 to 6ed97de Compare March 19, 2026 03:10
@swalkinshaw swalkinshaw merged commit e759618 into main Mar 19, 2026
6 checks passed
@swalkinshaw swalkinshaw deleted the litestream-db-backup branch March 19, 2026 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants