Backup SQLite databases with litestream

This article shows the steps to back up SQLite databases using Litestream.


Install Litestream

1) Check the latest release on GitHub.

2) Pick and install the one that matches your machine architecture.

$ wget https://github.com/benbjohnson/litestream/releases/download/v0.3.13/litestream-v0.3.13-linux-arm64.deb
$ sudo dpkg -i litestream-v0.3.13-linux-arm64.deb

3) Enable and start the service.

$ sudo systemctl enable litestream
$ sudo systemctl start litestream

Configure Litestream

1) Locate the configuration file

$ sudo pico /etc/litestream.yml

2) Configure local or S3 replicas based on your needs. Refer here.

access-key-id: AKxxx
secret-access-key: xxxxxx
region: xxxxxx

dbs:
  - path: path/to/your.sqlite3
    replicas:
      - url:  s3://bucket-name
        sync-interval: 30s
        retention: 24h

3) Save and restart service.

$ sudo systemctl restart litestream

Check Backups

1) Check the journal to see if the backup process is started.

$ sudo systemctl restart litestream

time=2024-12-08T11:55:50.759+08:00 level=INFO msg="write snapshot" db=
time=2024-12-08T11:55:50.872+08:00 level=INFO msg="snapshot written" db=  elapsed=xxxms sz=xxxx
time=2024-12-08T11:55:50.890+08:00 level=INFO msg="write wal segment" db=
time=2024-12-08T11:55:50.908+08:00 level=INFO msg="wal segment written" db= elapsed=xxxms sz=xxxx

2) Check your S3 bucket to see if the backup directory is established.

 


AI Summary
gpt-4o-2024-08-06 2024-12-08 23:02:33
This article provides a comprehensive guide on backing up SQLite databases using Litestream. It includes steps for installing, configuring, and starting Litestream services on your machine. Additionally, it outlines how to configure backups locally or to S3, and verify the backup process through system logs and S3 bucket checks.
Chrome On-device AI 2025-01-20 09:31:50

Share Article