Backing up OpenCms
For a complete backup of an OpenCms installation you will need to backup:
- Configuration files
- The the servlet container
- The OpenCms database
Configuring OpenCms properly for production use can be a tricky and time consuming. Make sure you adequately document the process particular to your hosting environment and make backups of any relevant configuration files (eg the Apache mod_proxy config, the Tomcat server.xml, etc).
Backing up the servlet container is a straight forward file system backup.
Backing up the database is more complex. This procedure is specific to each database product and version number.
Contents |
OpenCms 6.x + MySQL 4.x on Linux
Option 1: mysqldump
The recommended way of backing up a MySQL database is to use the mysqldump command. This produces a SQL output which can then be restored using the mysql client.
The following command creates a compressed database backup, with a unique name:
mysqldump -v --flush-logs -u USERNAME --password=PASSWORD DATABASE_NAME | bzip2 >db_`date +%Y-%0m-%0d_%0H#%0M#%0S`.sql.bz2
USERNAME, PASSWORD and DATABASE_NAME have to be replaced with the name of your database user, that user's password and the name of your database.
Such a backup can later be restored by using the command
cat BACKUP-FILE.sql.bz2 | bunzip2 | mysql -u USERNAME --password=PASSWORD DATABASE_NAME
- Important Notice: for the restore to work, mysql has to accept very large database packets. Otherwise a 'max_packet_length exceeded error' is reported during the restore operation. If you allow large database packets, the memory of your server machine should not be too limited. If you cannot set your mysql to accept large packets, then you should not use this way of backing up your database.
The configuration file my.cnf has a setting called max_allowed_packet. You can, for example set this to
max_allowed_packet=128M
On Linux/Unix system, the configuration file resides under /etc/my.cnf
Option 2: mysqlhotcopy
You can also use the mysqlhotcopy script which makes a safe copy of the underlying MySQL data files.
mysqlhotcopy --user=root opencms /var/tmp
To restore the backup simply place the directory which is created in the example above into the /var/lib/mysql directory. Make sure the correct file ownership and permissions are applied.
See http://dev.mysql.com/doc/refman/4.1/en/backup.html
Backing up using Database Export
It is also possible to backup an OpenCms site using the Administration -> Database Management -> Export Database tool. However there is a memory leak bug in OpenCms 6.0 in the import part of the process which can limit the size of the site which can be re-imported this way. (Is this fixed in 6.2.x?)