Back up a SQLite site safely
This task is for administrators of sites on SQLite 3, the default database for a site served from one machine. At
the end you have a consistent copy of the database. A plain file copy of a database in use can be inconsistent; the
.backup command of the sqlite3 tool is safe (Operating a site, section 6).
Contents
Before you start
- The
sqlite3command-line tool on the server. - The database file name:
ls var/storage/sqlite3/(exponential.dbis the nameexp:installuses by default). - A target directory outside the installation, ideally on another volume.
Steps
sqlite3 var/storage/sqlite3/exponential.db ".backup '/backup/example/site-$(date +%F).db'"
tar czf /backup/example/files-$(date +%F).tgz var/storage settings/override settings/siteaccessThe database is several files (.db, -wal, -shm, .writer-lock); .backup reads it through SQLite and writes one
consistent file, so you do not copy the others.
Schedule it
A nightly crontab line as the site's user (adapt paths):
30 2 * * * cd /path/to/installation && sqlite3 var/storage/sqlite3/exponential.db ".backup '/backup/example/site-nightly.db'"Rotate the copies by your retention rule (Backup schedules and retention).
Check it worked
sqlite3 /backup/example/site-nightly.db "PRAGMA integrity_check;" # okThen restore it on a test server now and then (Restore last night's backup to a test server).
Related pages
- Take a backup before a change
- SQLite for hosts
- SQLite database support
- Backups per database engine
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.