Backing up OpenCms

From OpenCms Wiki
Revision as of 18:12, 21 October 2008 by 217.12.16.56 (Talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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 mysql configuration is called my.cnf. On Linux/Unix system, it resides under /etc/my.cnf. In this file there is a parameter called max_allowed_packet. If, for example, you want to accept packets of up to 128 Megabytes in size, then you have to write

max_allowed_packet=128M


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?)

The exported zip file can be found at [location of tomcat]/webapps/opencms/WEB_INF/packages/[name of your export file].

Backing up using the OpenCms shell

OpenCms Shell offers a way to execute administrative tasks through commands, without using the workplace and therefore in a manner that can be automated with the use of scripts.

As to what "Backing up OpenCms" actually means, it really depends on your particular installation. You may want to export all your VFS, just the folders that contain your web/intranet or a certain group of modules.

So first you need to determine what you want to backup based on your actual needs.

If you want to do the backup interactively, you should just use the shell as described in CMS Shell and look for the right commands (usually "exportResources" or "exportModule").

To create a script you can somehow schedule for automatic execution, you have to create a script file like this sample one:

echo on
login "Admin" "password"
setCurrentProject Offline
exportResources "targetFile.zip" "path_to_resource_or_folder_1;path_to_resource_or_folder_2"
exit

To execute this script, you have to run the CmsShell java class with the script argument pointing to the path of the script file. That is:

java -Djava.ext.dirs=./lib/ org.opencms.main.CmsShell -script=path_to_script_file

This sentence would work executed from the WEB-INF folder of OpenCms considering the ./lib folder means /WEB-INF/lib/ and therefore has all classes needed to execute OpenCms correctly. You may need to change this path to suit your needs.

With the script file and this sentence you just have to automatize the execution of this command based on your operating system, be it through crontab on Linux or some other way in different OS.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox