This page covers how to backup and restore OpenClinica data on the PostgreSQL database. OpenClinica keeps data needed to run the system in two locations, the actual database and the openclinica.data folder. Note: If changes to either of the variables below (which reference other folders) where made in the datainfo.properties configuration file you will need to backup these folders in your configured location in order to have a complete backup.

  • attached_file_location
  • exportFilePath 

Backup OpenClinica

A full backup of OpenClinica data can be accomplished by the following steps:

  1. Backup the DB
  2. Backup the openclinica.data folder

Backup the DB

Here are the steps for backing up your DB for both Linux and Windows:

Linux

Before you backup the DB stop Tomcat. Once Tomcat has stopped, take a backup of the DB using the “pg_dump” command from PostgreSQL. To accomplish this run the following commands:

  • /etc/init.d/tomcat stop (Confirm Tomcat is stopped before continuing.)
  • /opt/PostgreSQL/8.4/bin/pg_dump -F c -U postgres openclinica > openclinica.backup (When prompted for a password enter your “postgres” DB superusers password.)

You now have a complete backup of your OpenClinica DB. 

In case you need it, here is some pg_dump reference material.

Windows

Before you backup the DB stop Tomcat. Once stopped we will take a backup using the “pg_dump” command from PostgreSQL. To accomplish this run the following commands:

  • Open a command prompt and type “net stop tomcat6” and hit “enter” to stop tomcat.
  • C:Program Files (x86)PostgreSQL8.4binpg_dump.exe -F c -U postgres openclinica > openclinica.backup (When prompted for a password enter your “postgres” db superusers password)
    • On 32-Bit editions of windows the path will be the following for pg_dump.exe C:Program FilesPostgreSQL8.4binpg_dump.exe

You now have a complete backup of your OpenClinica DB.

In case you need it, here is some pg_dump reference material.

Backup the openclinica.data folder

Here are the steps to backup the openclinica.data folder in Linux or Windows:

Linux

The following will create a backup of your openclinica.data folder into the current directory:

  • cp -rf /usr/local/tomcat/openclinica.data .

Windows

The following illustrates how to get a backup of your openclinica.data folder on Windows:

  • Open “My Computer” or “Explorer”
  • Navigate to “c:octomcat”
  • Copy the folder labeled “openclinica.data” within”c:octomcat” to your backup location.

Restore OpenClinica

Restoring OpenClinica is quite simple. The recommended method is simply follow the OpenClinica installation guide for your OS. Once you have a blank OpenClinica instance ready, use the following steps to restore your data. By installing a blank OpenClinica instance first you can more easily rule out potential problems which may be caused by configuration issues.

The basic steps to restore your data into OpenClinica are:

  1. Install a new blank OpenClinica instance.
  2. Restore the OpenClinica DB from backup.
  3. Restore the openclinica.data folder from backup.

Step 1: Install a new blank OpenClinica instance

Linux

  • Please follow this guide to install a new OpenClinica instance on Linux.

Once you see the OpenClinica login screen you are ready to proceed to Step 2.

Windows

  • Please follow this guide to install a new OpenClinica instance.

Once you see the OpenClinica login screen you are ready to proceed to Step 2.

Step 2: Restore the OpenClinica DB

To restore the OpenClinica DB:

  • Stop Tomcat
  • Drop the current DB
  • Create a new DB
  • Restore your database backup file into the DB

The following describes how to do this for both Linux and Windows:

Linux

Run the following commands:

  • /etc/init.d/tomcat stop (Confirm tomcat is stopped before continuing)
  • /opt/PostgreSQL/8.4/bin/dropdb -U postgres openclinica (When prompted for a password enter your “postgres” db superusers password)
  • /opt/PostgreSQL/8.4/bin/psql -U postgres -c “CREATE DATABASE openclinica WITH ENCODING=’UTF8′ OWNER=clinica” (When prompted for a password enter your “postgres” db superusers password)
  • “cd” to change directory to where your backup DB file is located.
  • /opt/PostgreSQL/8.4/bin/pg_restore -U postgres -d openclinica < $DBBACKUPFILE  (When prompted for a password enter your “postgres” db superusers password)

The backup of your DB has now been restored.

dropdb – Reference Material

pg_restore – Reference Material

Windows

  • Open a command prompt and type “net stop tomcat6” to stop tomcat.
  • In the command prompt “cd” to the following directory “C:Program Files (x86)PostgreSQL8.4bin”
    • On 32-Bit editions of windows the path will be the following C:Program FilesPostgreSQL8.4bin
  • In the command prompt now run the following commands.
    • dropdb -U postgres openclinica (When prompted for a password enter your “postgres” db superusers password)
    • psql -U postgres -c “CREATE DATABASE openclinica WITH ENCODING=’UTF8′ OWNER=clinica” (When prompted for a password enter your “postgres” db superusers password)
    • pg_restore -U postgres -d openclinica < $DBBACKUPFILE  (When prompted for a password enter your “postgres” db superusers password)

The backup of your DB has now been restored. This can also be done via PGAdminIII.

dropdb – Reference Material

pg_restore – Reference Material

Restore the openclinica.data folder

Restoring the openclinica.data folder is quite simple–just copy the folder to your new installation location after deleting the current default folder. Below list the steps to accomplish this for Linux and Windows.

Linux

  • Issue the following command to go to the root folder of the openclinica.data directory “cd /usr/local/tomcat”
  • Issue “rm -rf openclinica.data” to remove the current default installations openclinica.data folder.
  • Issue “cp -rf $OPENCLINICA.DATAFOLDER BACKUP /usr/local/tomcat/” to restore your openclinica.data folder.
  • Next issue a “chown -R tomcat /usr/loca/tomcat/*”. This ensures your permissions are setup correctly for OpenClinica to access the folder.

Your openclinica.data folder is now restored.

Windows

  • Open “My Computer” or “Explorer”
  • Navigate to “c:octomcat”
  • Delete the current “openclinica.data” folder within “c:octomcat”
  • Copy the openclinica.data folder you backed up to “c:octomcat”

Your openclinica.data folder is now restored.

Current Community Contributed Content

http://en.wikibooks.org/wiki/OpenClinica_User_Manual/BackupAndRestore

Other Useful Links

http://www.postgresql.org/docs/8.4/static/backup.html

http://www.cyberciti.biz/tips/howto-backup-postgresql-databases.html

http://archives.postgresql.org/pgsql-admin/2001-03/msg00143.php

http://wiki.postgresql.org/wiki/Automated_Backup_on_Windows

http://www.wisdombay.com/articles/article000013.htm

Other Ideas or Suggestions

If you would like to submit any new configuration examples or troubleshooting tips based on your own experience, we would be more then happy to post them on this page. To submit new configurations or tips please post to the users email list with a Subject of “DOCS SITE:Backup and Restore” and we will add them to this page. Thanks!

 

8.3.1 Community Contributed Backup Scripts

You will need to have 7zip installed for this method to work.

You may download the files reference in this article here

Dear All,

I would like to share my OC daily backup script and OC daily archive backup script to the community, both of them should works with both OC 3.0.x and OC 3.1.x (please note that both of scripts are for OC installed on Windows only).

Please see the description of individual script file below:

 1.       OC_Daily_Backup.txt (please rename its extension to .cmd after copied to OC server)

Description:

–          Configurable OC backup related parameters

–          Expect to scheduled execute on daily basis

–          Steps are VACUUM DB (db maintenance), OC DB backup, OC configuration file backup, and OC data directory backup

–          After successfully executed, it will create single zip file with the following name format OC_Daily_[Year]-[Month]-[Date]-[Date Init]–[Hour]-[Min].zip 

(i.e. OC_Daily_2012-02-29-Wed–001-49.zip) in configured OC backup path

–          The script also perform zip self test and generate test results file with the following name format OC_Daily_[Year]-[Month]-[Date]-[Date Init]–[Hour]-[Min]_Zip_Status.txt

(i.e. OC_Daily_2012-02-29-Wed–001-49_Zip_Status.txt) in configured OC backup path, sample of file is in attached.

2.       OC_Daily_Backup_Archive.txt (please rename its extension to .cmd after copied to OC server)

 

Description:

–          Configurable OC backup archive related parameters

–          Expect to scheduled execute on periodically basis (every xx days)

–          Steps are added all existing OC daily backup zip files and OC daily backup zip status files into single archive file with the following name format OC_Archive_[Year]-[Month]-[Date]- –[Hour]-[Min].zip

(i.e. OC_Archive_2012-02-29–01-48.zip) in configured OC backup archive path

–          After successfully executed, it will delete all existing daily backup zip file(s) and zip status file(s)

–          The script also perform zip self test and generate test results file with the following name format OC_Archive_[Year]-[Month]-[Date]- –[Hour]-[Min]_Zip_Status.txt

(i.e. OC_Archive_2012-02-29–01-48_Zip_Status.txt) in configured OC backup archive path, sample of file is in attached.

 

Please feel free to edit/modify them according to your environment or your need, any comment/feedback are welcome J

Hope it helps & cheers,

Montri