Overview
Sometimes Litestream can be overkill for projects with a small database that do
not have high durability requirements. In these cases, it may be more
appropriate to simply back up your database daily or hourly. This approach can
also be used in conjunction with Litestream as a fallback. You can never have
too many backups!
❗️
Do not use `cp` to back up SQLite databases. It is not transactionally safe.
Backup & compress
The sqlite3
command line interface comes with a built-in .backup
command
which will safely backup your database to another file location. You can run
it directly from the command line:
sqlite3 /path/to/db '.backup /path/to/backup'
This will output your database to the file /path/to/backup
. B-tree databases
like SQLite compress well so it’s recommended to compress your database:
This will compress your database to a new file called /path/to/backup.gz
. You
can then upload this file to external storage.
External storage using S3
If you are using S3, you can use the AWS CLI to
copy the file to an S3 bucket:
aws s3 cp /path/to/backup.gz s3://mybucket/backup.gz
Rolling backups
You can also add the day or hour to your filename to create a rolling backup.
For example, adding the hour to your filename gives