The [backup API](https://www.sqlite.org/backup.html) would circumvent your race concern. Of course, due to the same uncertainties leading to that concern, there would still be a question as to what version of the database would be replaced by the created backup.