Django Sqlite Backup

Published on May 29, 2023 | Tags: Django python sqlite AWS

SQLite is a great database. It is embeddable, very portable and great for read-only applications. However, since it is stored in a single file, it can be hard to manage it in production environments with ephemeral file systems as you will need another process to back it up for you. Sometimes, you do not have access to the file system directly, see Heroku or Render, for example.

So, one of the first things I thought when I had this idea is that this was already done: Litestream. However, this is great and all if you can arbitrarily install binaries and run them along with your main web process, such as containers. But this makes deployment a bit complicated and can be tricky to do so when you are trying to deploy your application.

More often than not, you will have an application that it is mostly read-only, but will want to add things occasionally. One strategy could be to create a SQLite database from scratch and re-deploy your application for every change. I used to do that. However, if you do lots of typos, or want to quickly edit something you find yourself that you have to be in front of your computer and cannot quickly edit from your phone. Despite all this, running an application with a SQLite database could still be a very good option as you do not need a database server like Postgres running, which can usually incur extra costs.

This Django application tries to solve this very problem. It provides a web/HTTP and a CLI interface to back up and restore SQLite databases. It allows you to expose an endpoint to back up your database on S3, for example. This way, you can have all the benefits of SQLite, and work around the limitations of it.

Check out the code in GitHub:

Ferran Jovell