mastodon.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
The original server operated by the Mastodon gGmbH non-profit

Administered by:

Server stats:

348K
active users

aaron

How do you back up container data that includes an SQLite database? Is stopping the container the only safe option?

@aaronk6 Should you not mount the storage outside of the container?

@obrhoff Yes, that’s how I do it, but my understanding is that the database file might be inconsistent when I copy or snapshot it while the application running in the container is using it.

@aaronk6
As far as I understand SQLite it's pretty robust. I'd think of restoring it after back-up as a minor risk.

Edit: correction! Back-up-during-write is explicitly listed as a way to corrupt an SQLite database.

Use a file for the volume with the database that allows taking a snapshot maybe? E.g., ZFS?

sqlite.org/howtocorrupt.html

@obrhoff

www.sqlite.orgHow To Corrupt An SQLite Database File

@tg9541 @aaronk6 @obrhoff isn't ZFS snapshot during write going to lead to corrupted database in the same way as a regular backup?

@kiraso @tg9541 @obrhoff Yeah, that’s how I understand it.

@aaronk6 @tg9541 @obrhoff I'd just stop containers. Well, it depends on your goals of potential data loss vs uptime. I do live snapshots daily, and offline snapshots weekly

@kiraso @tg9541 @obrhoff In my home setup, stopping the containers would of course be a viable solution. It’s more out of curiosity.

@kiraso No - please refer to the SQLite docs above:

The corruption may happen when a transaction gets written while a backup is stored, and both the before and the after end up in the same backup file.

A filesystem snapshot with, e.g., ZFS, BTRFS or a block-device snapshot with LVM act at one point in time, before, during or after a transaction.

@aaronk6 @obrhoff

@tg9541
That's an interesting point.

I'm considering online ZFS snapshot of a database similar to DB process crash, which may stop transactions in the middle, leave some temporary data around, but file system itself remains consistent. If database is expected to survive this, so be it. SQLite seems to be resilient enough.

@aaronk6 @obrhoff

@tg9541

I wish there was a standard way for #backup software to tell applications, “hey, stop what you're doing and flush to disk for a sec so I can back this up.”

@aaronk6 @obrhoff

@tg9541 The document (love the title, by the way) mentions three safe backup methods that supposedly also work on live databases. sqlite3_rsync sounds particularly interesting. @obrhoff

@aaronk6 @tg9541 @obrhoff
I also missed it on the first reading. It is in section 1.2.
What this means for containers, probably you want to mount another volume just for the latest snapshot, look for a script that implements one of the recommended methods, then use that snapshot file as your backup.
I’d be surprised if there isn’t already a SQLite container image that has this option but I admit I haven’t looked around much