Database Backup and Restore Commands

Last modified by Eleni Cojocariu on 2026/08/20 10:14

Reference

The command that dumps and restores an XWiki database is the database's own, and it differs for each of the supported databases. The examples below use the default database name xwiki.

DatabaseDumpRestore
MariaDB and MySQL
mysqldump -u root -p --add-drop-database --databases xwiki > xwiki.sql
mysql -u root -p < xwiki.sql
PostgreSQL
pg_dump -U xwiki xwiki > xwiki.sql
psql -U xwiki -d xwiki -f xwiki.sql
Oracle
expdp xwiki@ORCL schemas=xwiki directory=DATA_PUMP_DIR dumpfile=xwiki.dmp
impdp xwiki@ORCL schemas=xwiki directory=DATA_PUMP_DIR dumpfile=xwiki.dmp
HSQLDB

No command: the database is the database sub-directory of the permanent directory, and is copied with it.

No command, for the same reason.

Why the MariaDB and MySQL dump drops the database

Warning

Dump with the option that adds the statement dropping the database, as the table above does. A restore has to remove the tables that exist in the target and not in the dump, because a data migration may have created some. Left in place, they make the migration fail the next time it runs, and the database cannot be brought back to the state the dump holds.

The same option makes the dump recreate the database with the character set and collation XWiki needs, so the restore needs no CREATE DATABASE of its own, which is why the restore command above names no database.

Dumping every wiki of a farm

On MariaDB and MySQL each wiki of a farm is a database of its own, so dumping xwiki backs up the main wiki alone. Dump them all instead:

mysqldump -u root -p --add-drop-database --all-databases > xwiki.sql

On PostgreSQL every wiki is a schema of the single xwiki database, so the command in the table already covers the whole farm. Use pg_dumpall when you want the server's roles as well, and restore it with psql -d postgres -f xwiki.sql.

The database user after a restore

Restoring onto a new database server leaves the instance without the user hibernate.cfg.xml connects as. Recreate it with the privileges the database installation gives it, and set its password to the one that file holds:

pass=$(sed -n 's|.*<property name="hibernate.connection.password">\(.*\)</property>.*|\1|p' \
  /etc/xwiki/hibernate.cfg.xml)
mysql -u root -p -e "ALTER USER 'xwiki'@'localhost' IDENTIFIED BY '$pass';"

Running the commands from a graphical client

pgAdmin performs both operations on a selected PostgreSQL database, as "Backup" and "Restore" in its context menu.

FAQ

Are the attachments in the database dump?

Only on an instance configured to store them in the database. By default they are files of the permanent directory, and the dump holds their metadata alone.

Which databases can XWiki run on?

Check the Database Support Strategy.

Related

Get Connected