Have you implemented OpenMRS? Please participate in the Implementation Site Survey. If you already have, thank you!
Page tree
Skip to end of metadata
Go to start of metadata


Here there are the commands for copying and restoring the database of an OpenMRS Standalone 2.8.0 server.

All this procedure can also be done remotely following same steps.

First of all, do a dump of the MySQL database:

mysqldump -u [user] -p[password] -e --single-transaction -q  --port=[port] --host=[@IP] openmrs >openmrs_bkup_`date +%y%m%d`.sql

  • [user] --> The user name of the embedded MySQL server (by default it is openmrs)
  • [port] --> The port used by the MySQL server
  • [@IP] --> The @IP of the server. If you are on a local installation, use loopback address (

For more info referring to the backup process, please check MySQL backup page.

Now copy the /appdata directory:

cp -r /referenceapplication-standalone-2.8.0/appdata /dir/temp-backup

More info about appdata directory can be found in Application Data Directory page.

And that’s all! There is a script which automatizes all this procedure.

In this script, there is also a log of the back up routine, which is sent to another machine via scp.

# Dump the data from OpenMRS to a file

mysqldump -u openmrs -p[password] -e --single-transaction -q 
--port=[MySQLport] --host=[@host] openmrs >openmrs_bkup_`date +%y%m%d`.sql
2> /dir/error_log.txt

# Copy the AppData folder 

mkdir /dir/temp-backup 
cp -r /referenceapplication-standalone-2.8.0/appdata /dir/temp-backup 2>>

# Zip up the backup files

zip -r openmrs_`date +%y%m%d` openmrs_bkup.sql /dir/temp-backup/appdata
2>> /dir/error_log.txt

#Remove temporal directory

rm -r /dir/temp-backup

#Display new file

echo "created backup file : " openmrs_`date +%y%m%d` 

#Send the file into the remote server

sshpass -p "[PasswordForTheSession]" scp -r [user]@[@IP]:/dir/error_log.log

Making backups periodically

For making new backups periodically we use cron.

Execute crontab -e

A sample command to execute the script file at 5:00 am once a week would be:

0 5 * * 1 /dir/scriptBackup.sh


For the restoration procedure first of all, import the last backup database into the MySQL server installation:

mysql -u[user] -p[password] --port=[MySQLport] --host=[@IP] openmrs < openmrs_bkup_’date’.sql

Now, copy the appdata folder into the new installation.

Run the server and follow the steps seen in screen.


Backup and Restoration of the Shared Health Record


  • No labels