1 min read

Setting up Litestream for backing up SQLite to an AzureStorage blob

This is a quick guide to setting up Litestream on a Linux box to automatically replicate a SQLite  database to a Microsoft Azure blob table.

I used these as a reference:

Install SQLite

apt-get install sqlite3

Download and install Litestream

# download
wget https://github.com/benbjohnson/litestream/releases/download/v0.3.8/litestream-v0.3.8-linux-amd64.deb
# install
sudo dpkg -i litestream-v0.3.8-linux-amd64.deb

Install Litestream as a service

sudo systemctl enable litestream
sudo systemctl start litestream

Verify the service is running

sudo journalctl -u litestream -f

Set the database to backup in configuration. I'm using an Azure Blob. Edit the config file nano /etc/litestream.yml. Note that the account-key part does not have a dash in front.

dbs:
 - path: /path/to/db/file.db
   replicas:
     - url: abs://<StorageAccountName>@<ContainerNameAndPath>
       account-key: connectionKey

If we make changes, restart the service

sudo systemctl restart litestream

We can restore the backed replicated database to a local path using

litestream restore -o my.db abs://STORAGEACCOUNT@CONTAINERNAME/PATH