Backups per database engine
This page is for database administrators and operations teams in public bodies who back up the database half of an Exponential site. It gives the backup and restore command of each supported engine, how to check the copy, and how the engine's tools fit into an organization's existing backup system. The complete hosting page is Database backups per engine.
Supported databases (Exponential 6.0.x), in order of preference: 1. SQLite 3 (the default) · 2. PostgreSQL · 3. MongoDB · 4. MariaDB · 5. Oracle · 6. MySQL · 7. Microsoft SQL Server and Azure SQL (more databases from 6.0.15: Choosing a database).
Contents
- At a glance
- SQLite needs care
- Server engines
- Fitting your backup system
- Passwords on the command line
- Checklist
At a glance
| Database | Backup | Restore |
|---|---|---|
| 1. SQLite 3 | sqlite3 <db file> ".backup '/backup/exponential.db'" | sqlite3 <db file> ".restore '/backup/exponential.db'" |
| 2. PostgreSQL | pg_dump -U USER -Fc DATABASE > site.dump | pg_restore -U USER -d DATABASE --clean site.dump |
| 3. MongoDB | mongodump --uri="mongodb://USER@HOST:27017/DATABASE" --out=/backup/site | mongorestore --uri="..." --drop /backup/site |
| 4. MariaDB | mariadb-dump --single-transaction -u USER -p DATABASE > site.sql | mariadb -u USER -p DATABASE < site.sql |
| 5. Oracle | php bin/php/console ext:ezoracle:datapump (see its --help), or Oracle's expdp | Oracle's impdp |
| 6. MySQL | mysqldump --single-transaction -u USER -p DATABASE > site.sql | mysql -u USER -p DATABASE < site.sql |
Find which engine a site uses with grep -rn "DatabaseImplementation" settings/override settings/siteaccess/*/site.ini.append.php.
SQLite needs care
The whole database is one file under var/storage/sqlite3/ (exponential.db is the default name; ls var/storage/sqlite3/ shows yours), with -wal and -shm files next to it. "Never copy a database file that is in
use" (9.2 SQLite backup and restore). Use the online
backup and check the copy:
sqlite3 var/storage/sqlite3/exponential.db ".backup '/backup/exponential-$(date +%F).db'"
sqlite3 /backup/exponential-<date>.db "PRAGMA integrity_check" # prints okA file-level backup agent that copies var/ while the site runs does not make a usable SQLite backup on its own.
Run the .backup command first, into a directory the agent then copies. Keep free disk for "the database twice over".
Server engines
- PostgreSQL:
pg_dumptakes a consistent snapshot while the site runs; PostgreSQL has replication and point-in-time recovery of its own if your recovery point needs more than nightly dumps. After a restore into a fresh database, check the sequences named<table>_<column>_seq(9.4). - MariaDB and MySQL:
--single-transactiongives a consistent dump of InnoDB tables without locking them; restore into a database created inutf8mb4. - MongoDB: after a restore into a new server, create the indexes from
bin/mongodb/create_indexes.js. - Oracle:
ext:ezoracle:datapumpor your DBA's Data Pump jobs.
Fitting your backup system
Most public bodies have an enterprise backup system and a database team with its own procedures. Practical points:
| Point | Advice |
|---|---|
| Who owns the database backup | the database team for server engines; the application team for SQLite, which has no server |
| Same moment as the files | schedule the dump and the file backup in the same window (What to back up) |
| Retention | agree it with records management (Backup schedules and retention) |
| Proof | a restore test per engine, not only a successful job log (Restore testing) |
| Before risky changes | an extra dump before upgrades, engine changes and restores |
Passwords on the command line
-p makes the MySQL and MariaDB clients ask for the password; never write the password itself on the command line,
where it lands in the shell history and the process list (Operating a site).
For scheduled jobs use the client's option file or your secrets store, readable by the backup user only.
Checklist
- To do: The backup command of the site's engine is scheduled and owned by a named team.
- To do: SQLite is backed up with
.backup, never by copying the live file. - To do: The copy is checked (
PRAGMA integrity_check, a test restore). - To do: No password appears on a command line or in a crontab.
- To do: The dump and the file backup are taken in the same window.
Related pages
- Backups and recovery index of this folder
- Choosing a database in the official order
- Database support, backup and restore
- 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.