SQLite Backup with Litestream
Overview
Section titled “Overview”When using Parako.ID with the SQLite storage adapter, Litestream provides continuous, real-time replication of your SQLite database to cloud object storage (S3, GCS, Azure Blob).
Why Litestream?
Section titled “Why Litestream?”SQLite is a single-file database — if the disk fails, you lose everything unless you have backups. Litestream streams WAL (Write-Ahead Log) changes to object storage in near-real-time, giving you:
- Continuous backup (not just periodic snapshots)
- Point-in-time recovery to any moment
- Zero application changes — works at the OS level
- Minimal overhead — only WAL deltas are shipped
Prerequisites
Section titled “Prerequisites”- SQLite adapter configured:
STORAGE_ADAPTER=sqlite - WAL mode enabled (Parako.ID sets
PRAGMA journal_mode = WALautomatically) - Litestream installed: https://litestream.io/install/
Configuration
Section titled “Configuration”Create litestream.yml in your project root:
dbs: - path: ./data/parako.db replicas: # S3-compatible storage (AWS S3, MinIO, Backblaze B2, etc.) - type: s3 bucket: your-backup-bucket path: parako/sqlite endpoint: https://s3.amazonaws.com # or MinIO/B2 endpoint access-key-id: ${LITESTREAM_ACCESS_KEY_ID} secret-access-key: ${LITESTREAM_SECRET_ACCESS_KEY} region: us-east-1 retention: 168h # 7 days of WAL segment retention sync-interval: 1s
# Google Cloud Storage (alternative) # - type: gcs # bucket: your-backup-bucket # path: parako/sqlite
# Azure Blob Storage (alternative) # - type: abs # account-name: your-storage-account # bucket: your-container # path: parako/sqliteRunning with Litestream
Section titled “Running with Litestream”Development
Section titled “Development”# Replicate in the background while running the applitestream replicate -config litestream.yml &yarn devProduction (with PM2)
Section titled “Production (with PM2)”Wrap the app process with Litestream so it starts replication before the app:
litestream replicate -config litestream.yml -exec "node dist/src/index.js"Or run Litestream as a separate systemd service:
[Unit]Description=Litestream SQLite ReplicationAfter=network.target
[Service]ExecStart=/usr/local/bin/litestream replicate -config /opt/parako/litestream.ymlRestart=alwaysUser=parakoGroup=parako
[Install]WantedBy=multi-user.targetDocker
Section titled “Docker”FROM litestream/litestream:latest AS litestreamFROM node:24-slim
COPY --from=litestream /usr/local/bin/litestream /usr/local/bin/litestreamCOPY litestream.yml /etc/litestream.yml
# Litestream wraps the app processCMD ["litestream", "replicate", "-config", "/etc/litestream.yml", "-exec", "node dist/src/index.js"]Restoring from Backup
Section titled “Restoring from Backup”# Restore to the original pathlitestream restore -config litestream.yml ./data/parako.db
# Or restore to a different pathlitestream restore -config litestream.yml -o /tmp/restored.db ./data/parako.dbImportant Notes
Section titled “Important Notes”- PM2_INSTANCES must be 1 when using SQLite — SQLite does not support concurrent writes from multiple processes.
- Litestream requires WAL mode (already configured by Parako.ID).
- The
cache_sizepragma (8MB) is set automatically for optimal read performance. - For multi-process deployments, use PostgreSQL or MongoDB instead of SQLite.
See also: Security — Key Management for JWKS configuration and rotation.