10 ms·
I'm not very familiar with the details here. What are the problems with cp?
by ufo 9y ago
I'm not very familiar with the details here. What are the problems with cp?
- jstimpfle 9y agocp does not make atomic snapshots. It copies by reading (usually sequentially) chunk by chunk from the source file, and writing these chunks to the destination file. This takes time. If the database has writes at the time of backup, the backup might be invalid (it contains some old parts and some new parts). (Unless you use e.g. the --reflink option of GNU cp, in which case it makes atomic snapshots on filesystems that support it).
- candiodari 9y agoIsn’t one of the more important points of POSIX that reading sequentially results in an atomic copy ? As long as you keep the file handle open and the fs supports it.
- jstimpfle 9y agoI don't know which point you mean, but that would mean that any writer would be blocked indefinitely by any other reader. That amounts to a read lock. You don't get a read lock just by opening a file for reading. You can test that with a simple shell script { echo line1 echo line2 } > test.txt { read line echo got "$line" sleep 2 read line echo got "$line" } < test.txt & # concurrent write sleep 1; { echo line2 echo line1 } > test.txt wait This script does a concurrent write while the reader is in the "sleep 2" phase. The output should be got line1 got line1 (given that the sleeps do the expected thing). POSIX might contain something that requires aligned blocks of 512 bytes or so to be read or written atomically. But only if you do that in a single system call, of course.
- chamakits 9y agoYou can end up getting a corrupt copy of the database. See here: https://www.sqlite.org/howtocorrupt.html#_backup_or_restore_while_a_transaction_is_active https://www.sqlite.org/howtocorrupt.html#_backup_or_restore_...