You shouldn't backup sqlite with cp while the application is running because you can get a torn backup that is corrupted. You can do it while you are holding a database lock (BEGIN IMMEDIATE), or you can stop the application or you can use the sqlite backup API. This advice applies for non-WAL databases and I can't tell you how WAL changes it.
Of course it is safe to take a backup while the application is only reading from the database.
Right, I'm pretty sure the backup API works alright for WAL databases, too.
My point here is more that it's literally one file, as compared to something like pg_dump/pg_restore or mysqldump. You can take the resulting file and query it directly with the sqlite3 binary, because it's just a full copy of the DB.
28
u/MaleficentFig7578 Sep 11 '24
You shouldn't backup sqlite with cp while the application is running because you can get a torn backup that is corrupted. You can do it while you are holding a database lock (
BEGIN IMMEDIATE), or you can stop the application or you can use the sqlite backup API. This advice applies for non-WAL databases and I can't tell you how WAL changes it.Of course it is safe to take a backup while the application is only reading from the database.