Restoring from back up

cravaus wrote on Monday, May 11, 2015:

I am not using a typical Linux system. I am using a Synology NAS. I have two of them. One is being set up for back up. I barely know what I am doing. No backup is useful unless it works. So I am checking mine out.

First, I am trying to restore the backup of openemr on my second NAS using some modified instructions from

http://www.open-emr.org/wiki/index.php/Backing_Up_Using_the_Built_In_Tools

to get the dump to work I did the I created a backup directory in
/volume1/homes/[My User Name]/sqlbackup/

In PuTTY I ran the following:
DB_SAVE_PATH=/volume1/homes/[My User Name]/sqlbackup/
cd $DB_SAVE_PATH
mysqldump --opt --quote-names -u openemr -p openemr | gzip > openemr.sql.gz

To dump the file system I did the following:

tar -C /volume1/homes/[My User Name]/sqlbackup/ -zcf openemr.tar.gz ./

I moved these two files to my second NAS in their home directory:
/volume1/homes/[My User Name]/wwww/

I put the restore script from /openemr/contrib/util/ in the home directory and ran it in PuTTY. The result is an infinite loop of:
Extracting …
tar: option requires an argument – ‘f’
Try ‘tar --help’ or ‘tar --usage’ for more information.
Error: tar could not extract ‘’.

/volume1/homes/[My User Name]/www/restore: read line 163: illegal option -e

Any ideas what this is telling me?

MY ATTEMPT AT A WORK AROUND:
I assumed that part of the problem may be the goofy Synology DSM modification of Linux. I tried the following:

Manually install the openemr MySQL database with:

gunzip < /volume1/homes/[My User Name]/www/openemr.sql.gz | mysql -u root -p

This worked. I see the database in MySQL now. And I extracted the openemr.tar.gz to home at /volume1/homes/[My User Name]/www/openemr/.

But then when I start openemr it looks like I am doing a fresh build. I tell it I am using an existing database but it asks for new administrator credentials etc. So, any tips would be helpful.

Craig

fsgl wrote on Monday, May 11, 2015:

  1. Are you able to run the backup utility? See attachments.

  2. Are you able to restore with these instructions?

cravaus wrote on Monday, May 11, 2015:

I tried to use that but I get this error:
Dumping OpenEMR database…
“C:/xampp/mysql/bin/mysqldump -u ‘openemr’ -p’qnI6@RiMUNx’ -h’localhost’ --port=‘3306’ --opt --quote-names -r /var/services/tmp/openemr_web_backup/emr_backup/openemr.sql ‘openemr’” returned 127:

I thought that was odd. Why xampp? I am not in windows. So I gave up on that. Perhaps I have missed something in settings?

cravaus wrote on Monday, May 11, 2015:

The restore instructions you site are the ones I am trying to get to work. The result of running the restore script is an infinite loop of:
Extracting …
tar: option requires an argument – ‘f’
Try ‘tar --help’ or ‘tar --usage’ for more information.
Error: tar could not extract ‘’.
/volume1/homes/[My User Name]/www/restore: read line 163: illegal option -e

So, that is where I am stuck.

fsgl wrote on Monday, May 11, 2015:

Are you able to do the following:

  1. install 4.2.0 in second NAS,
  2. restore mysql dump to it,
  3. replace new web directory with old web directory while not replacing sqlconf.php of the install,
  4. login with old credentials?

yehster wrote on Monday, May 11, 2015:

Once you’ve restored the MySQL database, edit the sqlconf.php file with the appropriate settings.

In particular, this line despite the warning not to touch it, needs to be 1 rather than 0 (one) indicating that the installer doesn’t need to be run.

This will by pass all the prompts for new admin user etc…

cravaus wrote on Monday, May 11, 2015:

Great. Thanks for the tips. This is the solution for a Synology NAS:

Create a backup directory in both NASs such as:
/volume1/homes/[USER]/backups/

BACKUPS in NAS A
Dump MySQL Database
mysqldump --opt --quote-names -u root -pROOTPASSWORD openemr | gzip > /volume1/homes/[USER]/backups/openemr.sql.gz

Dump File System
tar -C /volume1/homes/[USER]/backups/ -zcf openemr.tar.gz ./

Both of these files need to be moved to
/volume1/homes/[USER]/backups/
in NAS B

RESTORE in NAS B
First there must be a working OpenEMR instance and database in MySQL
gunzip < /volume1/homes/[USER]/backups/openemr.sql.gz | mysql -u root -pROOTPASSWORD openemr

cravaus wrote on Monday, May 11, 2015:

For every day:
I added these lines to /etc/crontab on my primary NAS and they are backed to the secondary NAS with Backup & Replication

0 2 * * * root find “/volume1/homes/[USER]/backups/” -type f -mtime +7 -exec rm -rf {} ;
15 2 * * * root mysqldump --opt --quote-names -uroot --all-databases - pROOTPASSORD | gzip -2 > /volume1/homes/[USER]/backups/date '+%m-%d-%Y'_openemr.sql.gz

This should keep backups for the last 7 days. Edit mtime + to change number of days back to keep.

fsgl wrote on Tuesday, May 12, 2015:

Because the underlying problem was not having a copy of OpenEMR in NAS #2 to begin with, you may wish to test the backup utility & restore script again.

The web directory needs backing up as well or, at a minimum, the sites/default folder. The backup utility handles both the database & web directory very efficiently, making recovery more streamline.

If backup/restore is successful, then automating backup would be the next step.

cravaus wrote on Tuesday, May 12, 2015:

Yes. Thank you fsgl. I did create a new instance of OpenEMR on the second NAS and I do have it running with the backup file loaded. I have tried again restoring to OpenEMR on the second NAS this morning with last nights back up and all is well. The file system for the NAS is completely backed up and easy to restore.

Using the utility in OpenEMR on both machines is producing this error:

“C:/xampp/mysql/bin/mysqldump -u ‘openemr’ -p’qnI6@RiMUNx’ -h’localhost’ --port=‘3306’ --opt --quote-names -r /var/services/tmp/openemr_web_backup/emr_backup/openemr.sql ‘openemr’” returned 127:

The xampp path is confusing. It may be a hold over from when I was running in Windows. I am not sure how to correct this. The password, which is not usually a good thing to post, is not one that I am using on the system anymore so I think I need to change something someware to make it know I am in the world of Linux. Any ideas?

fsgl wrote on Tuesday, May 12, 2015:

My best guess is that your device is trying to send the dump file from Windows to Linux. Anything in error logs?

If you have no problem with the restore script in NAS #2, there is the option of doing nothing at present.

Because backup is so vital, no user wants to be confronted suddenly with a backup failure.

If you want to be proactive, you may wish to wipe the hard drive clean to get rid of all traces of Windows & do a re-install of OS & OpenEMR in NAS #1. It is a lot of work, but it may prevent a bout of Coronary Arterial Spasm down the road.

cravaus wrote on Wednesday, May 13, 2015:

For MySQL Replication:

We need to modify the my.cf file on both NASs first to allow for replication. The default my.cnf file is for a much smaller NAS than my DS214+ wich has 1 gig of sdram. The default is missing necessary commands that make replication possible. There are replacement templates on the NAS for larger units and that contain the replication commands. The my-huge.cnf template is for NASs with 1-2 gig of sdram. To update, log in to PuTTY for both NASs and paste the following script:

cp /usr/share/mysql/my-huge.cnf /etc/mysql/my.cnf

On both NASs open /etc/mysql/my.cnf to edit
Add the following under – socket =
user = root

Add a hash tag to- server-id = 1 i.e. #server-id = 1

Make sure that the two entries for the binary log [log-bin=mysql-bin] are hash tagged: #log-bin=mysql-bin

Edit max_allowed_packet = 1M to:
max_allowed_packet = 16M

Save the file.

For the rest, I followed the instructions here:
http://lewiscarr.co.uk/2013/07/moodle-m … hpmyadmin/

This works well.

With all of the above I have full database replication in real time and nightly back ups of MySQL on both NAS’s

cravaus wrote on Wednesday, May 13, 2015:

I found where the old xampp information was stored: Administration>Globals Miscellaneous Tab.

I am not sure where the old password is stored. So, It appears that it is in the MySQL database and just doing a re-installation will not necessarily rid me of the problem. So, now I am looking for where these variables are stored in the database. I am using the search in phpMyAdmin and coming up with nothing. I may not be using the search propperly.

cravaus wrote on Thursday, May 14, 2015:

I have updated the variables on my Primary NAS with information found in a fresh install without updating the database on the secondary NAS. Now when I run the backup, all seems to run ok. But I get an error at the end:

“Firefox can’t find the file at” and “/openemr/interface/main/backup.php.”

I looked in the PHP error log and I see:

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 190476288 bytes) in
/volume1/homes/[USER]/www/openemr/interface/main/backup.php on line 93, referer: http://www.[mydomain].com/~[USER]/openemr/interface/main/backup.php

In line 93 I see
readfile($TAR_FILE_PATH);

Which leads to:
$TAR_FILE_PATH = $TMP_BASE . DIRECTORY_SEPARATOR . $backup_file_prefix . $backup_file_suffix;

Which leads to:
$backup_file_prefix = “emr_backup”;
$backup_file_suffix = “.tar”;
$TMP_BASE = $GLOBALS[‘temporary_files_dir’] . “/openemr_web_backup”;
$BACKUP_DIR = $TMP_BASE . “/emr_backup”;
$TAR_FILE_PATH = $TMP_BASE . DIRECTORY_SEPARATOR . $backup_file_prefix . $backup_file_suffix;

Then when I look in file system, I see the following is created: /var/services/tmp/openemr_web_backup/
And I see these files
/var/services/tmp/openemr_web_backup/emr_backup/openemr.sql.gz
/var/services/tmp/openemr_web_backup/emr_backup/openemr.tar.gz

So it appears to be working. I am not sure why the error screen?
Perhaps there is another step that is missing?, however, all appears to be ok.
Should a download to the PC happen automatically?

fsgl wrote on Thursday, May 14, 2015:

The zipped file, emr_backup.tar, which contains the dump of both the web directory & database, normally appears in the Downloads folder.

Change the php.ini settings to these. Memory limit is too small. As a result the backup file ends up in the Temporary folder instead of Downloads.

If this file is copied to the home folder of NAS #2 & the restore script is used; recovery should proceed according to the Wiki article.

cravaus wrote on Friday, May 15, 2015:

The php.ini settings did the trick. The emr_backup.tar file downloads. However running the restore script still results in an infinite loop of:
Extracting …
tar: option requires an argument – ‘f’
Try ‘tar --help’ or ‘tar --usage’ for more information.
Error: tar could not extract ‘’.
/volume1/homes/[My User Name]/www/restore: read line 163: illegal option -e

fsgl wrote on Friday, May 15, 2015:

Have a look at the restore script itself, see attachment.

Either the script does not “know” the path to emr_backup.tar or where to place the extracted files.

Try putting emr_backup.tar in /volume1/homes/[My User Name], then specify the path as /volume1/homes/[My User Name]/emr_backup.tar. Copy the restore script to the same location, so that the zipped backup file & restore script are sitting side-by-side in the same folder.

The web directory normally resides in var/www, but if it sits in var/www/html or elsewhere; the restore script may stop because of this dislocation.

cravaus wrote on Friday, May 15, 2015:

It looks like the script is executed correctly through line 141. I see that the Temp Directory has been created in /tmp/emr_backup.

However, I am not getting “Now you will be asked for the backup file.”

The looping error is:
Extracting …
tar: option requires an argument – ‘f’
Try ‘tar --help’ or ‘tar --usage’ for more information.
Error: tar could not extract ‘’.
/volume1/homes/[My User Name]/www/restore: read line 163: illegal option -e

So I guess this makes since given that it is in a While loop.

I see that --f is looking for my file. I am wondering about option -e. Tar Help does not show it as an option on my Synology system.
I also do not find it here http://linuxcommand.org/man_pages/tar1.html
What is option -e?

I find option -e at line 71, 99, 117 then some after 163 but I do not think they would be in play where my error is concerned.

Argument --f and option -e are both in:

dlg_fselect()

I am not understanding this function.

If I focus my attention on lines 145 to 163, clearly I am not getting proper $RESULT information. I am supposing this should be the path to my tar file.

I Changed
TARFILE=$RESULT
to
TARFILE=/volume1/homes/[USER]/www/emr_backup.tar

I have also changed line 175 to my path.

OEDIR=var/www/openemr
to
OEDIR=/volume1/homes/Craig/www/openemr

This produces:

WARNING: This script is experimental.
It may have serious bugs or omissions.
Use it at your own risk!
sh: 0: unknown operand
Now you will be asked for the backup file.
By default this is named emr_backup.tar, although you may have saved it as something else.

/volume1/homes/[USER]/www/restore: read: line 163: illegal option -e

Extracting /volume1/homes/[USER]/www/emr_backup.tar …
tar: Substituting `.’ for empty member name
Extracting /tmp/emr_backup/openemr.tar.gz …

/volume1/homes/[USER]/www/restore: read: line 231: illegal option -e

If you have a particular requirement for the UTF-8 collation to use,
then please specify it here. Hit Enter to accept the default ‘utf8_general_ci’.
Enter ‘none’ if you do not want UTF-8.

/volume1/homes/[USER]/www/restore: read: line 363: illegal option -e

Your Site ID will be ‘default’.
I will install a new OpenEMR web directory ‘/volume1/homes/[USER]/www/openemr’ fr om the backup.
I will restore the OpenEMR database backup to the MySQL database ‘openemr’.
The OpenEMR database user will be ‘openemr’ with password ‘ROOTPASSWORD’ .
MySQL will use its default character set and collation.

Please check the above very carefully!
Any existing databases and directories matching these names will be DESTROYED.
/volume1/homes/[USER]/www/restore: read: line 1: illegal option -e

Option -e is still a issue. Progress?

cravaus wrote on Friday, May 15, 2015:

I think I know the problem. I have not bootstrapped the secondary system yet. That should add some functionality that is not there yet. So, that will be my next step.

cravaus wrote on Friday, May 15, 2015:

No, bootstrapping did not fix it.