Skip to content
litestream logo

Litestream

litestream

SQLite disaster recovery and streaming replication to cloud storage (S3, GCS, Azure, SFTP, NATS). Use this skill for configuring Litestream, deploying to cloud platforms, troubleshooting WAL replication issues, implementing point-in-time recovery, and setting up VFS read replicas.

SKILL.md

Full skill instructions

Litestream

Litestream is a disaster recovery tool for SQLite that runs as a background process, continuously replicating database changes to cloud storage. It monitors the SQLite Write-Ahead Log (WAL), converts changes to immutable LTX files, and uploads them to your chosen storage backend.

Key Concepts

  • WAL Monitoring: Watches SQLite Write-Ahead Log for changes at configurable intervals (default 1s)
  • LTX Files: Immutable files containing database page changes, never modified after creation
  • Level-Based Compaction: Multi-level system (L0-L9) that merges LTX files to reduce storage overhead
  • Point-in-Time Recovery: Restore to any transaction using TXID or timestamp
  • VFS Support: Read replicas directly from cloud storage without local database copy
  • MCP Server: AI tool integration for automated database management

Quick Start

Installation

# macOS
brew install litestream

# Linux (Debian/​Ubuntu)
wget https://github.com/​benbjohnson/​litestream/​releases/​download/​v0.5.5/​litestream-v0.5.5-linux-amd64.deb
sudo dpkg -i litestream-v0.5.5-linux-amd64.deb

# Docker
docker pull litestream/​litestream:0.5

Basic Replication

# Command line (single database)
litestream replicate /​path/​to/​db.sqlite s3://bucket/​db

# With config file
litestream replicate -config /​etc/​litestream.yml

Restore Database

# Restore latest backup
litestream restore -o /​path/​to/​restored.db s3://bucket/​db

# Point-in-time recovery
litestream restore -timestamp 2024-01-15T10:30:00Z -o /​tmp/​db s3://bucket/​db

# Restore to specific transaction
litestream restore -txid 1000 -o /​tmp/​db s3://bucket/​db

Check Status

# View all databases and their replication status
litestream status

# List available LTX files
litestream ltx /​path/​to/​db.sqlite

Critical Rules

These rules are essential for correct Litestream operation:

  1. Lock Page at 1GB: SQLite reserves the page at offset 0x40000000 (1GB). This page must always be skipped during replication and compaction. The page number varies by page size:

    • 4KB pages: page 262145
    • 8KB pages: page 131073
    • 16KB pages: page 65537
  2. LTX Files are Immutable: Once created, LTX files are never modified. New changes create new files.

  3. Single Replica per Database: Each database can only replicate to one destination. Use multiple Litestream instances for multiple destinations.

  4. WAL Mode Required: SQLite must be in WAL mode (PRAGMA journal_mode=WAL;)

  5. Use litestream ltx: The litestream wal command is deprecated.

Storage Backends

BackendURL SchemeExample
AWS S3s3://s3://bucket/​path
S3-Compatible (R2, Tigris, MinIO)s3://s3://bucket/​path?endpoint=host:port
Google Cloud Storagegs://gs://bucket/​path
Azure Blob Storageabs://abs://container@account/​path
SFTPsftp://sftp://user@host:22/​path
NATS JetStreamnats://nats://host:4222/​bucket
WebDAVwebdav://webdav://host/​path
Alibaba OSSoss://oss://bucket/​path
Local File(path)/​var/​backups/​db

Configuration File Example

dbs:
  - path: /​data/​app.db
    replica:
      url: s3://my-bucket/​app-backup
      access-key-id: ${AWS_ACCESS_KEY_ID}
      secret-access-key: ${AWS_SECRET_ACCESS_KEY}
      region: us-east-1
      sync-interval: 1s

When to Use This Skill

Use Litestream skill when:

  • Configuring SQLite database replication to cloud storage
  • Setting up disaster recovery for SQLite applications
  • Troubleshooting replication issues (WAL growth, sync failures)
  • Implementing point-in-time recovery procedures
  • Deploying Litestream with Docker, Fly.io, Kubernetes, or systemd
  • Understanding WAL-based replication concepts

Skill Contents

  • concepts/ - Architecture, replication mechanics, LTX format, SQLite WAL, VFS support, compaction
  • configuration/ - Storage backend configurations (S3, GCS, Azure, SFTP, NATS, OSS, WebDAV, File)
  • commands/ - CLI command reference (replicate, restore, status, ltx, databases)
  • operations/ - Monitoring, troubleshooting, recovery, and heartbeat monitoring
  • deployment/ - Docker, Fly.io, Kubernetes, and systemd deployment guides
  • integrations/ - MCP server integration for AI tools
  • scripts/ - Validation and diagnostic helper scripts

Common Issues

WAL Growing Too Large

  • Check sync interval (default 1s may be too slow for write-heavy workloads)
  • Verify storage backend connectivity
  • Check for checkpoint blocking (long-running transactions)

Replication Lag

  • Monitor with litestream status
  • Check network connectivity to storage backend
  • Review sync interval configuration

Restore Failures

  • Verify backup exists: litestream ltx /​path/​to/​db
  • Check storage backend credentials
  • Ensure target directory is writable

Links

More DevOps & CI/CD skills

Project scaffolding, deployment configuration, and CI/CD setup for Google ADK agents.

6K 472.6K
View

Set up tracing, logging, and monitoring for deployed ADK agents across Cloud Trace, BigQuery, and third-party platforms.

6K 472.6K
View

Enterprise Azure infrastructure architect generating Bicep or Terraform from workload descriptions.

1.5K 454.3K
View
azure-kubernetes logo
DevOps & CI/CD

azure-kubernetes

Plan and configure production-ready Azure Kubernetes Service clusters with Day-0 and Day-1 best practices.

1.5K 447.1K
View

Raw mechanical interfaces fusing Swiss typographic print with military terminal aesthetics. Rigid grids, extreme type scale contrast, utilitarian color, analog degradation effects. For data-heavy dashboards, portfolios, or editorial sites that need to feel like declassified blueprints.

92.7K 354.9K
View
just-scrape logo
DevOps & CI/CD

just-scrape

Web search, scraping, extraction, crawling, and monitoring via ScrapeGraph AI CLI.

69 245K
View

Skill for working with Firebase Hosting (Classic). Use this when you want to deploy static web apps, Single Page Apps (SPAs), or simple microservices. Do NOT use for Firebase App Hosting.

462 159.7K
View

Deploy and manage web apps with Firebase App Hosting. Use this skill when deploying Next.js/Angular apps with backends.

462 159.1K
View
deploy-to-vercel logo
DevOps & CI/CD

deploy-to-vercel

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

31.9K 146.6K
View
programmatic-seo logo
DevOps & CI/CD

programmatic-seo

Build SEO-optimized pages at scale using templates, data, and proven playbook patterns.

53.3K 140.1K
View

Design and build isolated, reusable Convex backend components with clear boundaries and app-facing wrappers.

63 123.5K
View

Deploy and manage projects on Vercel using token-based authentication. Use when working with Vercel CLI using access tokens rather than interactive login — e.g. "deploy to vercel", "set up vercel", "add environment variables to vercel".

31.9K 116.1K
View

Coding & apps AI tools

Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View
I
Coding & apps

Imagica

Build a no-code AI app in minutes.

Freemium
View
E
Coding & apps

Emergent.sh

An IDE for code migration from legacy to modern frameworks through coding agents.

Freemium
View
Wonder Dynamics logo
Coding & apps

Wonder Dynamics

Automate CGI animation in live-action scenes

Paid
View
M
Coding & apps

Mixo

Launch a website in seconds with AI.

Paid
View
AI Code Convert logo
Coding & apps

AI Code Convert

Streamline Your Coding Experience with AI Code Helper

Free
View