3 ms·
>Do not use `cp` to back up SQLite databases. It is not transactionally safe. I've read that this is true, but it has always confused me because I would expect
by charcircuit 5y ago
>Do not use `cp` to back up SQLite databases. It is not transactionally safe.
I've read that this is true, but it has always confused me because I would expect that using cp would be equivalent to if the application had crashed / you lost power.
- amcvitty 5y agoNot an expert but the transaction log is in another file and you’d need both to be in line with each other and backed up, so perhaps that’s a factor
- benbjohnson 5y agoI wrote up a bit longer explanation of the failure modes (which depend on your journaling mode) in this comment: https://news.ycombinator.com/item?id=31387447 https://news.ycombinator.com/item?id=31387447
- kijin 5y ago`cp` is not instantaneous. Unless you lock the entire file, one block can change while you're reading another block. You end up with a Frankenstein of a file, compared with a consistent snapshot if you had simply lost power. If your filesystem supports snapshotting, it would be safe to create a snapshot and `cp` the database off of that snapshot.
- fmajid 5y agoNo, because cp takes a non-zero amount of time and so by the time it has completed the first blocks may have been rewritten, thus the backup is inconsistent. If you take something like a ZFS snapshot, then, yes, that would be a consistent backup.
- charcircuit 5y agoWould cp --reflink=always work too?