1 Backup
Julien Dessaux edited this page 2025-04-22 22:14:47 +02:00

Backup

All TfStated data is stored in its SQLite database. Backing up this database can be achieved through different means.

VACUUM INTO

SQLite has a VACUUM command that is used to optimize the structure of the database. It also has the side effect of shrinking its size by reclaiming disk space that is no longer used by table data.

VACUUM INTO is a variant that runs this process without interfering with other writes and also outputs a perfect working copy of your database at the point in time you run this command. Everything is kept as is, including the PRAGMA and indexes. You can then backup this output file. Example:

umask 077
echo -n "VACUUM INTO '/tmp/tfstated.db';" | sqlite3 /var/lib/tfstated/tfstated.db

This is the recommended way to backup your TfStated database as you can pair it up with the backup software of your choice (for example borg).

Another option is to output this backup file directly to a remote storage mounted on your server.

Litestream

Litestream is a background service that continuously monitors and replicates an SQLite database to an S3 compatible object storage.

Litestream is a good backup solution that has the advantage of providing point in time recovery. The downsides are that it is another service to manage and that it requires a write lock on the database when its checkpointing occurs.

Since Litestream is more complex to operate, the TfStated project recommends to pair this solution with a VACUUM INTO style backup.