Personal tools

Windows OpenEMR Backup and Recovery

From OpenEMR Project Wiki

Jump to: navigation, search

Backup & Recovery In Windows Using Batch Routine Files – Protecting Your Data

The internal Backup in OpenEMR (Admin – Backup) has problems in Windows, so avoid using it. This is intended as a preferred method of providing backup for your OpenEMR data. You can expand it and simplify it to backup your complete Windows install, albeit at the cost of time and added disk space.

The fundamental issue is to make copy(s) of your real data which could be used to restore if your disk drive crashes. So, although there can be advantages to having a backup copy on the same physical drive, it is more important to have them on multiple different physical servers and at different physical locations for protection from fire, flood, etc., so long as they can be secure at those locations. For example, you might backup to a LAN mapped drive location called X:\oemr-backup\mon\ which will contain subfolders openemr, documents, edi, era and letter_templates which were saved on Monday morning. Similar storage protocol could allow saving up to seven days worth as you will see below.

So let us examine the restore process first. You would install a new Xampp and OpenEMR on another machine, and successfully login to that setup. If you were previously using the “Services” type configuration for Apache and MySQL, you should do that again, otherwise, you must turn off the Apache and MySQL manually to do the restore, then start them back up again once you were finished and ready to start using OpenEMR again. You will replace the various folders in the new install with those you had saved with a prior backup. The batch file which would do that in a normal Windows install from a backup storage location X:/oemr-backup/mon/ for example looks like: (Replace “mon” with whichever day you need):

del c:\xampp\mysql\data\openemr /y
del c:\xampp\htdocs\openemr\documents /y
del c:\xampp\htdocs\openemr\edi /y
del c:\xampp\htdocs\openemr\era /y
del c:\xampp\htdocs\openemr\custom\letter_templates /y
copy x:\oemr-backup\mon\openemr c:\xampp\mysql\data\
copy x:\oemr_backup\mon\documents c:\xampp\htdocs\openemr\
copy x:\oemr_backup\mon\edi c:\xampp\htdocs\openemr\
copy x:\oemr_backup\mon\era c:\xampp\htdocs\openemr\
copy x:\oemr_backup\mon\custom\letter_templates c:\xampp\htdocs\openemr\custom\

At that point all your prior logins and data should be operable.

After verifying any restore or new install, always save a copy of c:\xampp\htdocs\openemr\library\sqlconf.php to someplace safe. It contains your database login and password data which is essential, and not found elsewhere.

Backing up databases has some issues to consider. These methods are not strictly adhering to MySQL protocol. But as long as ALL your databases backup between writes to ANY databases, all will be properly operable as a group. That means you must prevent access to the databases during the backups. For a small clinic which does not operate 24/7, that is simple – schedule the backup for when they are not working. But for a hospital, that may not be sufficient. In that case, you must temporarily shutdown the databases, make the backup, then re-start the database. In that case, You are STRONGLY advised to use ONLY the “services” configuration for Apache and MySQL, ie they will be services which automatically start with Windows, and can be accessed via the Windows Ctrl-Panel – Admin – Services, where they can be started and stopped, rather than the manual Xampp control. The services can be stopped and started then by the batch program to assure safe backups with minimal interference with normal operations.

We use Xcopy because it only copies files changed since the last backup to that location, saving bandwidth and time. And you can make a separate backup batch program for each day, and schedule them using the Windows scheduler, by changing the “mon” below to “tue”, etc. Batch program backup without need for the services shutdown (you can leave the manual Xampp controlled Apache and MySQL running so long as nobody can write to the databases during the backup) looks like (check.bat is a blank batch file in the root directory to prevent network delays):

cmd /c cd x:\               rem  This line connects the X drive if it is available.
if exist x:\check.bat xcopy c:\xampp\mysql\data\openemr\*.* x:\oemr-backup\mon\openemr\ /d /e /c /i /f /h /k /y
if exist x:\check.bat xcopy c:\xampp\htdocs\openemr\documents\*.* x:\oemr-backup\mon\documents\ /d /e /c /i /f /h /k /y
if exist x:\check.bat xcopy c:\xampp\htdocs\openemr\edi\*.* x:\oemr-backup\mon\edi\ /d /e /c /i /f /h /k /y
if exist x:\check.bat xcopy c:\xampp\htdocs\openemr\era\*.* x:\oemr-backup\mon\era\ /d /e /c /i /f /h /k /y
if exist x:\check.bat xcopy c:\xampp\htdocs\openemr\custom\letter_templates\*.* x:\oemr-backup\mon\letter_templates\ /d /e /c /i /f /h /k /y

If you use the OpenEMR continuously, you would need to stop the MySQL service, which would prevent writes while you backed up, then re-start it which would allow normal operation, once the backup had occurred. You should generally backup to at least two different locations, ideally separated physically as well. An offsite storage location is advised also, as is at least daily backups. To stop the MySQL service, place the following before the first line in the batch program above:

net stop “mysql”   rem  Note the quote marks and the order shown
net stop “apache2.2”  rem  Note the version number may be different for you, but use the full name

and to restart, place the following after the last line in the batch program above:

net start “apache2.2”
net start “mysql”

That should be a robust backup and restore system for Windows users.

If you have the manual Xampp for Apache and MySQL and you want to instead use the services, you can run the following (go to each and double-click on the file in the order shown, then follow prompts). It need only be run a single time unless you run the uninstall batch files found at the same locations:


Note that you could simplify by xcopying everything in c:\xampp to a backup folder, with the trailing configuration letters (arguments) as shown, and then copy it all back over a new install to restore AFTER you first made a copy of the sqlconf.php file as noted above from the new install, as you might need to restore that separately once all the other copying has been done.

Restore from your previously backed-up file (emr_backup.tar)

Instructions can be found at Windows OpenEMR Restore using emr_backup.tar.

Instructions Author

Joe Holzer