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.
