logoalt Hacker News

infamialast Saturday at 5:55 PM4 repliesview on HN

SQLite has a ".backup" command that you should always use to backup a SQLite DB. You're risking data loss/corruption using "cp" to backup your database as prescribed in the article.

https://sqlite.org/cli.html#special_commands_to_sqlite3_dot_...


Replies

rogerbinnstoday at 4:51 PM

Related, there is also sqlite3_rsync that lets you copy a live database to another (optionally) live database, where either can be on the network, accessed via ssh. A snapshot of the origin is used so writes can continue happening while the sqlite3_rsync is running. Only the differences are copied. The documentation is thorough:

https://sqlite.org/rsync.html

qingcharlestoday at 4:41 PM

"I know about the .backup command, there's no way I'm using cp to backup the SQLite db from production."

Oh.

Guess I know what I'm fixing before lunch. Thank you :)

show 1 reply
anonzzziestoday at 2:37 PM

Yeah, using cp to backup sqlite is a very bad idea. And yet, unless you know this, this is what Claude etc will implement for you. Every friggin' time.

show 2 replies
BartjeDtoday at 3:17 PM

The bottom part of the article mentions they use .backup - did they add that later or did you miss it?

show 1 reply