Back to lessons

Hosting Operations

Back Up a SQLite Database File

You need to create a SQLite backup through sqlite3 instead of a raw file copy.

Command

sqlite3 app.db ".backup backup/app.db"

What changed

SQLite writes a backup copy to backup/app.db.

Danger

caution

When to use it

Use before risky data work, migrations, or manual inspection on a SQLite-backed app.

When not to use it

Do not use it as your only production backup plan; automate and verify backups separately.

Undo or recovery

Remove the backup file with rm backup/app.db if it was created only for a temporary check.

Expected output

The sqlite3 backup command is quiet on success; verify with ls afterward.

demo script

Disposable terminal steps

  1. ls -lh app.db
  2. sqlite3 app.db ".backup backup/app.db"
  3. ls -lh backup/app.db

simulated output

What it looks like

disposable vessel
::fixture-ready::
$ ls -lh app.db
-rw-r--r-- 1 root root 16 Jun 25 13:19 app.db
::exit-code::0
$ sqlite3 app.db ".backup backup/app.db"
::exit-code::0
$ ls -lh backup/app.db
-rw-r--r-- 1 root root 16 Jun 25 13:19 backup/app.db
::exit-code::0

YouTube Short

Back up SQLite safely.

Use SQLite's backup command before manual data work, then verify the backup file exists.

LinkedIn hook

Copying a live SQLite file blindly can produce a bad backup.

Question: Do you use SQLite .backup before manual database fixes?

experiments

A/B tests to run

Metric: save_rate

A: Before risky data work.

B: Use .backup, then verify.