The YAML configuration file provides a way to list databases and replicas that Litestream should manage. In addition, there are global variables that can be applied to all replicas.
The default path for the configuration file is
By default, Litestream will perform environment variable expansion within the
config file before reading it. Any references to
variables will be replaced with their environment variable values. If no value
is set then it will be replaced with an empty string.
This can cause issues if you have a value in a configuration file which has a
dollar sign followed by characters—for example, a password. In this case, you
can set the
-no-expand-env flag on any
litestream command to disable
If you are using AWS S3 replication, it can be useful to specify your credentials in one place instead of for each replica:
access-key-id: AKIAxxxxxxxxxxxxxxxx secret-access-key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxx
Litestream produces a continuous stream of metrics that are exported as a Prometheus endpoint. These are disabled by default as it requires an HTTP server to start. You can enable it by setting a bind address in the config:
When you start Litestream with this setting enabled, you’ll see metrics at http://localhost:9090/metrics
Litestream can monitor one or more database files that are specified in the
configuration file. Database files are also referenced in
by their absolute path.
Each database accepts two options—its path and a list of replicas:
dbs: - path: /var/lib/db1 replicas: - url: s3://mybkt.litestream.io/db1 - path: /var/lib/db2 replicas: - path: /backup/db2 - url: s3://mybkt.litestream.io/db2
Litestream currently supports two types of replicas:
"s3"replicates a database to an S3 bucket.
"file"replicates a database to another local file path.
All replicas have unique name which is specified by the
"name" field. If a
name is not specified then the name defaults to the replica type. The name is
only needed when using multiple replicas of the same type on a database.
The following replica settings are also available for all replica types:
url—Short-hand form of specifying a replica location. Setting this field will apply changes to multiples fields including
retention—The amount of time that snapshot & WAL files will be kept. After the retention period, a new snapshot will be created and the old one will be removed. WAL files that exist before the oldest snapshot will also be removed. Defaults to
retention-check-interval—Specifies how often Litestream will check if retention needs to be enforced. Defaults to
snapshot-interval—Specifies how often new snapshots will be created. This is used to reduce the time to restore since newer snapshots will have fewer WAL frames to apply. Retention still applies to these snapshots. Not enabled by default.
validation-interval—When specified, Litestream will automatically restore and validate that the data on the replica matches the local copy. Disabled by default. Enabling this will significantly increase the cost of running Litestream as S3 services charge for downloads.
The easiest way to configure an S3 replica is to use the
dbs: - path: /var/lib/db replicas: - url: s3://mybkt.litestream.io/db
However, you can break this out into separate fields as well:
dbs: - path: /var/lib/db replicas: - type: s3 bucket: mybkt.litestream.io path: db
In addition, you can specify the region and AWS credentials per-replica:
dbs: - path: /var/lib/db replicas: - url: s3://mybkt.litestream.io/db region: us-east1 access-key-id: AKIAxxxxxxxxxxxxxxxx secret-access-key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxx
The following settings are specific to S3 replicas:
access-key-id—Replica-specific authentication key. If not specified, the global key or the
LITESTREAM_ACCESS_KEY_IDenvironment variable will be used instead. The
AWS_ACCESS_KEY_IDvariable can also be used.
secret-access-key——Replica-specific secret key. If not specified, the global secret or the
LITESTREAM_SECRET_ACCESS_KEYenvironment variable will be used instead. The
AWS_SECRET_ACCESS_KEYvariable can also be used.
bucket—Specifies the name of the remote bucket to replicate to.
path—Specifies the path to use within the bucket.
region—Specifies the bucket’s region. Only used for AWS S3 & Backblaze B2.
endpoint—Specifies the endpoint URL of the S3-compatible service. Only required for non-AWS services.
force-path-style—Uses the path style which is required by non-AWS services. This is automatically enabled if
skip-verify—Disables TLS verification. This is useful when testing against a local node such as MinIO and you are using self-signed certificates.
sync-interval—Frequency in which frames are pushed to S3. Defaults to
10swhen using the config but only
1swhen specifying the replica URL directly in the command line. Increasing frequency can affect costs significantly.
File replicas can be configured using the
dbs: - path: /var/lib/db replicas: - path: /backup/db
"type" field is specified and a
"url" is not used then
You can specify multiple replicas for a database, however, each one must have
a unique name. For example, this configuration below is for replicating to
AWS S3 & to DigitalOcean Spaces. Both of these use the “s3” replica type so
their default name would be “s3”. Instead, we can name them each unique names,
dbs: - path: /local/path/to/db replicas: - name: my_aws_replica url: s3://myawsbucket/db - name: my_do_replica url: s3://mybkt.nyc3.digitaloceanspaces.com/db
Replicas maintain a snapshot of the database as well as a contiguous sequence of SQLite WAL page updates. These updates take up space so new snapshots are created and old WAL files are dropped through a process called “retention”.
The default retention period is
24h. You can change that with the
field. Retention is enforced periodically and defaults to every
1h. This can
be changed with the
dbs: - path: /var/lib/db replicas: - url: s3://mybkt.litestream.io/db retention: 4h
Duration values can be specified using second (
s), minute (
m), or hour (
but days, weeks, & years are not supported.
Because Litestream performs physical replication, the resulting database files restored from replicas will match byte-for-byte. Litestream has an option to periodically validate replicas by restoring them and comparing their checksum to the primary database’s checksum.
Please note that frequently restoring from S3 can be expensive.
It can be enabled by setting the
dbs: - path: /var/lib/db replicas: - url: s3://mybkt.litestream.io/db validation-interval: 6h