News for hackers. Stuff that matters.
Re:Cron-based backup for SQLite by charcircuit on Sunday May 15, 2022 @08:33AM (#31387179)
>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.

Re:Cron-based backup for SQLite by kijin on Sunday May 15, 2022 @08:46AM (#31387227)
`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.

Re:Cron-based backup for SQLite by fmajid on Sunday May 15, 2022 @09:29AM (#31387430)
No, 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.
Re:Cron-based backup for SQLite by charcircuit on Sunday May 15, 2022 @08:44PM (#31392650)
Would cp --reflink=always work too?
Re:Cron-based backup for SQLite by amcvitty on Sunday May 15, 2022 @08:39AM (#31387203)
Not 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
Re:Cron-based backup for SQLite by benbjohnson on Sunday May 15, 2022 @09:36AM (#31387483)
I 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