3 ms·
In terms of restoring from backups: "Be sure to stop your application before copying the database into place" This intuitively feels right to me, but I'd be in
by simonw 5y ago
In terms of restoring from backups: "Be sure to stop your application before copying the database into place"
This intuitively feels right to me, but I'd be interested to understand the mechanics behind it. What can go wrong if you ignore this advice and use "mv" to atomically switch out the SQLite file from underneath your application?
My hunch is that this relates to journal and WAL files - I imagine bad things can happen if those no longer match the main database file.
But how about if your database file is opened in read-only or immutable mode and doesn't have an accompanying journal/WAL?
- zekica 5y agoOn Linux at least, if you switch the file, the old file (even if deleted) will still be used until the file descriptor is closed.
- deleted 5y ago[deleted]
- yencabulator 5y agoIf your app is running, it will already have the database file open, and with `mv` the app will keep using the old file. With SQLite and WAL, you need to replace both the main file and the WAL (/delete the WAL at the time you move the backup in place). A simple `mv` won't do that.