SQLite Forum

Hot backup database in WAL mode by coping
Thanks for your clarification, very much appriciated!

> Your "historical" method will work just fine

It is not my method, that is a quote from the [Documentation about the Backup API](https://www.sqlite.org/backup.html) :)

> 1. Process 1 is used solely for the purpose stated and nothing else.

So process 1 is a Python process and uses the database before and after. Before the Backup start it would execute `BEGIN IMMEDIATE` and hold that connection open while Process 2 is backing up the files. Process 2 continues to query the database during the backup.

> "5." No "frikking about" is undertaken against the database files (which must consist of at least the main database file and any log files) such as deleting the log.

Database file and `-wal` get stored straight into a tar file, and, if restored, both are placed back to the original place. Restoring is only done while Process 1 is shutdown.

My second concern: Does executing `PRAGMA wal_checkpoint(TRUNCATE); BEGIN IMMEDIATE;` in a single statement make sure that the `-wal` file is fully committed, restarted and truncated when taking the backup? My concern are threads: While we use the database in Serialized mode, I am not sure if the internals of SQLite guarantee that the above two commands are executed in sequence or if they potentially could be separated (e.g. by another statement from another thread).