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 (127.0.0.1)
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
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
# Copy the AppData folder
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
#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 follow thse steps:
Start the server:
java -jar openmrs-standalone.jar
Import the last backup database into the MySQL server installation:
mysql -u[user] -p[password] --port=[MySQLport] --host=[@IP] openmrs < openmrs_bkup_’date’.sql
Stop the server.
- Restore the appdata directory. Remove the current one and replace it with the 'backupped' one.
- Start the server again. It will be started in maintenance mode:
Log in with your user and password (by default, User: admin Password:Admin123). Now, a new screen will be opened. In this screen there will be the concepts and databases to be updated. Just click in the green arrow at the bottom on the page and wait for it to finish.
That is all you ned to make periodically backups and database restorations.
Backup and Restoration of the Shared Health Record