Uploading a backup of a mysql database
Submitted by Guest on Mon, 11/08/2014 - 00:15
Guys,
I have been taking regular backups of OPV using the mysqldump command (on a linux server). I would like to test one of these backups by uploading to a "dummy" opv server for testing.
What is the correct command to upload the "backup.sql" file into the mysql database, replacing all existing info in the database?
Cheers, Cahir.
Re: Uploading a backup of a mysql database
Use:
This will prompt for a password.
The database must exist.
It is recommended to restore the backup to a different server. This:
Ideally, this would be done automatically for each backup.
Re: Uploading a backup of a mysql database
Just out of interest - whenever the new sql database is uploaded, how long should Tomcat take to recognize it? I have run a mysql upload, but I get a "requested resource is not available" error in Tomcat for at least an hour afterwards. This seems to go away after a few hours, but I'm not sure why?
(The actual upload of a 50MB sql file to the database seems to take only 5 seconds).
Re: Uploading a backup of a mysql database
Cahir - I have never thought of doing this. When I play with MySQL I always stop Tomcat, and restart it when the maintenance is complete. I suspect that this is a better approach. Regards, Tim G
Re: Uploading a backup of a mysql database
Tim,
Thanks for your response. I think you are correct - better to stop Tomcat7 first. I appear to have killed the openvpms webapp though. I ran a full mysql database drop, and recreated the database as instructed in the OPV installation docs, then ran the "backup.sql" upload command. Then...nothing. The webapp is still unavailable. Tomcat is running fine, but OPV will not start, even from the Tomcat web manager.
Not really sure why changing the mysql would screw up the webapp. Any thoughts?
Re: Uploading a backup of a mysql database
Check the logs to determine why its not starting.
If you are running 1.7, OpenVPMS will log to <TOMCAT_HOME>/logs/openvpms-full.log.
Earlier releases log to openvpms-full.log in the directory you started Tomcat.
Re: Uploading a backup of a mysql database
Thanks for your response.
Here is the output of my log:
I'm not too sure what it means to be honest.
A separate question - when using the mysql dump command to restore a database, must the new database structure be empty, or can it contain info that is simply wiped by the new data?
Cahir
Re: Uploading a backup of a mysql database
As far as the startup error goes... are there any more?
the key error is Constructor threw exception; nested exception is org.openvpms.component.business.service.archetype.ArchetypeServiceException: Failed to execute query: {0}
Which means for some reason it couldnt execute a query against the mysql database.
As far as database restoration you wouldnt use msyql dump to do the restoration you would simply use the sql file it generated piped into a mysql session.
Use:
This will prompt for a password.
The database must exist.
As far as existing data goes it depends how you created the dump. You can create a dump file that starts by dropping all the tables and then recreating them - which is preferable.
using --add-drop-table as a option when running the command. There are another couple of options you should use when creating such as --add-locks alternatively just use --opts for a nice set of options that does both of these and more for you.
Ben
Re: Uploading a backup of a mysql database
The root cause of the problem is not displayed in that log. There should be additional messages that indicate the problem.
I suspect that OpenVPMS is unable to connect to the database. Unless you've changed the defaults, OpenVPMS will try and connect to mysql running on localhost, port 3306, to a database named openvpms, using username openvpms and password openvpms.
Verify that you can connect with:
mysql -u openvpms --password=openvpms openvpms
If not, and the database exists, make sure that the openvpms user has access to it. e.g.:
GRANT ALL PRIVILEGES ON openvpms.* TO 'openvpms'@'localhost'
IDENTIFIED BY 'openvpms' WITH GRANT OPTION;
When you restore the database using:
mysql ... < dump.sql
you don't need to drop existing tables. This is done for you.
Re: Uploading a backup of a mysql database
Guys,
Thanks for your replies.
I tested to see if openvpms could login to the mysql as a user, which it can.
Tomcat is running fine. Just for some reason the OPV webapp cannot get up and running. To correct myself, I did not use mysqldump to restore the database, just the instruction "mysql -u user -p openvpms < backup.sql"
So no joy. I will retrace my steps and use a fresh mysqldump to see if that makes any difference over my compressed regular backups.
As an addition from the log - anyone know what this means?:
Caused by: org.openvpms.component.business.dao.hibernate.im.query.QueryBuilderException: Could not find any matching archetypes for short names {lookup.macroReport}
Re: Uploading a backup of a mysql database
Another bit of info: when I setup OPV on the backup server, it can load fine. When you login there is just an empty installation with no client details etc. I presume this is what is supposed to happen?
Re: Uploading a backup of a mysql database
The lookup.macroReport archetype was introduced in OpenVPMS 1.7. Are your backup server and production server running the same versions of OpenVPMS?
Re: Uploading a backup of a mysql database
Err no. The backup server runs a more recent version of OPV than the production server. I didn't think that this would be a problem (because its just the MySQL database I upload), but I guess it is?
Re: Uploading a backup of a mysql database
You'll need to migrate the database after restoring it, and before starting Tomcat.
See section 2.8 "Upgrading from older releases of OpenVPMS" of readme.txt, included in the release distribution.
Re: Uploading a backup of a mysql database
You were correct. I guess I should "RTFM" a bit more closely on upgrade. Just to help anyone else - here is what I did to install my MySQL dump into a more recent version of OPV:
1. Stop tomcat, then upload the MySQL database into new OPV installation with mysql -u openvpms -p openvpms < backup.sql
2. Run MySQL converstion script found in OPV update folder of download
3. Load latest archetypes (found in OPV update folder)
4. Restart Tomcat.