tfstated/doc/Backup.md
Julien Dessaux 34fbde1f81
All checks were successful
main / main (push) Successful in 1m48s
main / deploy (push) Has been skipped
main / publish (push) Has been skipped
doc(tfstated): import documentation file from the forgejo wiki
2025-04-23 09:36:29 +02:00

39 lines
1.5 KiB
Markdown

# 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:
``` sql
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](./Example-Backup-With-Borg)).
Another option is to output this backup file
directly to a remote storage mounted on your server.
## Litestream
[Litestream](https://litestream.io/) 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.