Litestream continuously replicates SQLite databases to S3, GCS, or Azure Blob Storage. It runs as a sidecar process — your app uses SQLite normally, Litestream handles backup and replication automatically.
Why Litestream?
- Zero code changes — your app just uses SQLite normally
- Continuous replication — streams WAL changes to S3/GCS/Azure
- Sub-second RPO — recovery point objective under 1 second
- Free — open source, S3 costs pennies for small databases
- Restore anywhere — pull latest replica and run
Install
# Debian/Ubuntu
wget https://github.com/benbjohnson/litestream/releases/latest/download/litestream-linux-amd64.deb
sudo dpkg -i litestream-linux-amd64.deb
# macOS
brew install litestream
# Docker
docker pull litestream/litestream
Quick Start
# litestream.yml
dbs:
- path: /data/myapp.db
replicas:
- type: s3
bucket: my-backup-bucket
path: myapp
region: us-east-1
# Start replication
litestream replicate -config litestream.yml
# Or specify directly
litestream replicate /data/myapp.db s3://my-bucket/myapp
Restore
# Restore from S3
litestream restore -config litestream.yml /data/myapp.db
# Restore to specific point in time
litestream restore -timestamp 2026-03-29T10:00:00Z /data/myapp.db
# Restore and run app
litestream restore -if-db-not-exists -config litestream.yml /data/myapp.db
litestream replicate -exec "python app.py" -config litestream.yml
Docker Compose
version: '3'
services:
app:
build: .
volumes:
- data:/data
- ./litestream.yml:/etc/litestream.yml
environment:
- AWS_ACCESS_KEY_ID=xxx
- AWS_SECRET_ACCESS_KEY=xxx
entrypoint: litestream replicate -exec "node server.js" -config /etc/litestream.yml
volumes:
data:
Multiple Replicas
dbs:
- path: /data/myapp.db
replicas:
# Primary: S3
- type: s3
bucket: primary-backup
region: us-east-1
# Secondary: different region
- type: s3
bucket: secondary-backup
region: eu-west-1
# Local backup too
- type: file
path: /backups/myapp
Fly.io + Litestream (Common Pattern)
FROM litestream/litestream:latest AS litestream
FROM python:3.12-slim
COPY --from=litestream /usr/local/bin/litestream /usr/local/bin/litestream
COPY litestream.yml /etc/litestream.yml
COPY . /app
CMD litestream replicate -exec "python /app/server.py" -config /etc/litestream.yml
CLI Commands
# List replicas
litestream replicas /data/myapp.db
# List snapshots
litestream snapshots /data/myapp.db
# List WAL segments
litestream wal /data/myapp.db
# Validate replica
litestream validate -config litestream.yml
Key Features
| Feature | Details |
|---|---|
| Replication | Continuous WAL streaming |
| Destinations | S3, GCS, Azure, SFTP, file |
| RPO | Sub-second |
| Restore | Point-in-time recovery |
| Overhead | <1% CPU, minimal memory |
| Integration | Sidecar or -exec mode |
Resources
Working with data and databases? Check my Apify actors or email spinov001@gmail.com.
Top comments (0)