Last modified by Vincent Massol on 2024/04/18

It's crucial that you define a backup strategy for your wiki so that you don't lose any data in case of a problem with your wiki installation or in case you have issues upgrading your XWiki instance to a newer version.

There are several parts that need to be backed up:

Backup your database

If you've installed XWiki using your own database then you'll need a backup tool for that database to back it up and to restore it. Moreover, if you're backing up a huge amount of data, we advise that you compress the dump files to save disk space (for example with 7-zip).

  • MySQL:

    Backup: mysqldump --add-drop-database --databases xwiki > xwiki.sql backs up the xwiki schema (use the option --all-databases instead of --databases xwiki if you want to backup the whole XWiki istance with all its subwikis).

    It's important that the backup is done with --add-drop-database since when you restore it it's important that tables that might have been created are removed. For example database migrations can create extra tables. If you want to cancel the migration and go back to your clean dump you'll need to have those tables removed as otherwise when you run the migration again later on you might have errors.

  • PostgreSQL: You can use pg_dump xwiki > xwiki.sql to backup the PostgreSQL database. In case of backing up the whole instance, use the binary pg_dumpall instead.
  • Oracle: Use exp to export data.
  • HSQLDB: Simply backup the HSQLDB directory. For the XWiki standalone packaging it's the data/ directory.

Backup the XWiki WAR

To be on the safe side you can and should backup the whole XWiki WAR file (that's the file that was expanded and deployed in your Servlet Container when XWiki was installed).

More specifically the WAR contains mostly static files that are not changed. However it also contains some configuration files for XWiki and you really want to backup those, as explained below.

Configuration files

There are several configuration files you'll need to backup:

  • WEB-INF/hibernate.cfg.xml (Hibernate configuration)
  • WEB-INF/xwiki.cfg (old XWiki configuration file but still used)
  • WEB-INF/ (new XWiki Configuration file)
  • WEB-INF/classes/logback.xml (Logging configuration)
  • WEB-INF/observation/* (Cluster configuration)

To restore them simply copy them at the same location where you backed them up from.

In addition you may want to also backup any extra files you'll have installed in your XWiki installation such as JDBC drivers, extra plugins, etc.

Custom filesystem Skins

If you have a custom skin that is stored on the filesystem, make sure you backup the corresponding folder located in the webapps/xwiki/skins/ directory.

Backup Permanent Data

XWiki generates & saves data in the permanent directory of XWiki and it's important that you back it up.


  • The cache directory can be removed and does not necessarily need to be backed up. However if you don't back it up, XWiki will need to regenerate its content (e.g. the Solr seach indexes) and that can take a lot of time. It's thus recommended to back it up too.

Backup Log files

XWiki generates logs in the console by default and these will go where your Servlet container has been defined to save them. For Tomcat for example this usually goes in the TOMCAT_HOME/logs/catalina.out file.

However this is fully configurable and you may have configured XWiki to output log files elsewhere. If you want to keep those logs, don't forget to save them. Those logs are not needed by XWiki but you may want to save them to review them later on to diagnose issues that happened for example.

Using the XWiki Export feature

Since most XWiki data is saved in wiki pages one solution to backup a XWiki instance is to export all its pages using XWiki's Import/Export feature. However note that this is quite a resource hungry operation and depending on the size of your wiki you may need a lot of memory. As a consequence the recommended backup strategy is to backup the databases. It's much better to use a specialized backup tool that'll backup the database, perform incremental backups, verify backup integrity, etc.

In addition you should know that currently the following information is not located in wiki pages and is thus not saved in a wiki export:

  • Event stream data
  • Statistics data
  • Feed plugin data (if you use it)
  • Deleted documents/attachments data
  • XWiki Instance Id
  • Mail Statuses
  • User Notifications & user notification settings
  • Page Likes
  • Unprocessed mentions(waiting in the queue to be processed)
  • The unique identifier of the XWiki instance in a cluster

Moreover this won't save configuration data or other Permanent Data mentioned above such as installed Extensions, Lucene/SOLR index files and Logs.

In practice the Import/Export feature should be reserved for the following use cases:

  • move data across XWiki instances, including sharing of applications between separate instances
  • move data to another wiki
  • convert from one database to another

Restore your data

  • MySQL: Assuming you have your xwiki.sql file handy (obtained running mysqldump as explained above), run the following from the command line (or a script). Examples below are for the Linux shell.
    • Disable constraints check first: mysql -e "SET FOREIGN_KEY_CHECKS=0;" (restoring may fail with some cryptic error code, leaving the database in an inconsistent state, if you omit this step)
    • Delete the existing xwiki database if any: mysql -e "DROP DATABASE xwiki;" (better to start fresh)
    • Recreate the xwiki database: mysql -e "CREATE DATABASE IF NOT EXISTS xwiki DEFAULT CHARACTER SET utf8;".
    • Restore data from the dump file: mysql xwiki --user=root -p < xwiki.sql. Alternatively, you can omit the -p by adding a section [mysqldump] in your .my.cnf file (with a user and password line, same as for [mysql]).
    • Re-enable constraints checks: mysql -e "SET FOREIGN_KEY_CHECKS=1;"

    That is not all, now you need to restore the xwiki user rights (assuming the xwiki user exists in MySQL).

    • Update the xwiki user password from the (previously restored) hibernate configuration file
      pass=$(cat /etc/xwiki/hibernate.cfg.xml | grep passw| head -1 | sed -e 's/^.*<prop.*password">//' | sed -e 's|</property>.*||')
      mysql -e "SET PASSWORD FOR 'xwiki'@'localhost' = PASSWORD('$pass');"

    Finally, restart you container, for example in Linux: service tomcat7 restart

  • PostgreSQL: psql -d xwiki -f xwiki.sql to restore your previously saved data. In full instance backup mode, use psql -d postgres -f xwiki.sql instead.
  • Oracle: Use imp.

Tips in case you are using nginx

Assuming you have a nginx configuration with a server_name entry that needs updating, the following script might be useful.

# The following line works for Amazon EC2 instances. Change accordingly to find this host's IP dynamically.
thisip=$(curl -s http://instance-data/latest/meta-data/public-ipv4)
if [ ! -f $configfile ]; then
 echo "Missing file: $configfile"
 exit 1
echo backing-up $configfile
cp $configfile $configfile-old

echo Setting nginx server_name to $thisip
old=$(cat $configfile | grep '^\ *server_name' | awk '{print $2}' | sed -e 's/;//' | grep "$thipip" | head -1)
if [ $? -eq 0 ] ; then
 echo Fixing server_name
  cat $configfile | sed -e "s/$old/$thisip/" > $configfile-new
  mv $configfile-new $configfile

echo Done. New config file:
cat $configfile

echo restarting nginx
service nginx restart

Sample Backup Script


#Space Separated List of Databases to Dump
#DATABASE="xwiki d1 d3"

#XWIKI data folder
#Where is the webapps folder for your tomcat installation
# SLES 11 is located /srv/tomcat6/webapps
#What context (dir) does your application deploy to

DATE=$(date '+%Y-%m-%d')
mkdir ./${DATE}

#backup mysql
echo "Backing up Mysql"
mysqldump -h -u ${DBUSER} --password=${DBPASS} --max_allowed_packet=512m --add-drop-database --databases ${DATABASE} | /bin/gzip  > ./${DATE}/${DATABASE}.sql.gz

echo "Backing up Data"
#Backup Exteral Data Storage
/bin/tar -C ${DATAFOLDER}/../ -zcf ./${DATE}/data.tar.gz data

#Backing Java Keystore
/bin/cp /srv/tomcat6/.keystore ./${DATE}/.keystore

echo "Backing up xwiki configuration"
/bin/cp ${DEPLOYDIR}/WEB-INF/hibernate.cfg.xml ./${DATE}/hibernate.cfg.xml
/bin/cp ${DEPLOYDIR}/WEB-INF/xwiki.cfg ./${DATE}/xwiki.cfg
/bin/cp ${DEPLOYDIR}/WEB-INF/ ./${DATE}/

#Backup Deploy Context
echo "Backing UP deploy Context"
/bin/tar -C ${DEPLOYDIR}/../ -zcf ./${DATE}/ROOT.tar.gz ROOT

echo "DONE"

Get Connected