This article shows the steps to back up SQLite databases using Litestream.
Install Litestream
-
Check the latest release on GitHub.
-
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 -
Enable and start the service.
$ sudo systemctl enable litestream $ sudo systemctl start litestream
Configure Litestream
-
Locate the configuration file
$ sudo pico /etc/litestream.yml -
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 -
Save and restart service.
$ sudo systemctl restart litestream
Check Backups
-
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 -
Check your S3 bucket to see if the backup directory is established.
