NIHVIVO-46 Re-load the MySQL database from a dump file, instead of leaving it empty for VIVO to re-populate (takes much less time).

This commit is contained in:
jeb228 2010-03-26 19:13:26 +00:00
parent 67d69210a7
commit cdb6fb83de
3 changed files with 358 additions and 5 deletions

View file

@ -1,8 +1,8 @@
=begin =begin
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
Stop the Vitro application, delete all MySQL tables from the Vitro database, and Stop the Vitro application, delete all MySQL tables from the Vitro database,
start the application again. reload them from the mysqldump file, and start the application again.
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -21,6 +21,8 @@ Parameters:
A user account that has authority to drop the Vitro database in MySQL. A user account that has authority to drop the Vitro database in MySQL.
mysql_password mysql_password
The password for mysql_username. The password for mysql_username.
mysql_dump_file
The path to a file that contains a mysqldump of the test data model.
database_name database_name
The name of the Vitro database in MySQL. The name of the Vitro database in MySQL.
@ -45,6 +47,7 @@ class DatabaseCleanser
raise("Properties file must contain a value for 'website_url'") if @website_url == nil raise("Properties file must contain a value for 'website_url'") if @website_url == nil
raise("Properties file must contain a value for 'mysql_username'") if @mysql_username == nil raise("Properties file must contain a value for 'mysql_username'") if @mysql_username == nil
raise("Properties file must contain a value for 'mysql_password'") if @mysql_password == nil raise("Properties file must contain a value for 'mysql_password'") if @mysql_password == nil
raise("Properties file must contain a value for 'mysql_dump_file'") if @mysql_dump_file == nil
raise("Properties file must contain a value for 'database_name'") if @database_name == nil raise("Properties file must contain a value for 'database_name'") if @database_name == nil
# Check that we can connect to the MySQL database. # Check that we can connect to the MySQL database.
@ -57,6 +60,17 @@ class DatabaseCleanser
raise("Can't find the 'mysql' command!") if result == nil raise("Can't find the 'mysql' command!") if result == nil
raise("Can't connect to MySQL database.") if !result raise("Can't connect to MySQL database.") if !result
raise("Error connecting to MySQL database.") if $?.exitstatus != 0 raise("Error connecting to MySQL database.") if $?.exitstatus != 0
# Check that the mysqldump file exists and is readable
if !File.exist?(@mysql_dump_file)
raise "MySQL dump file '#{@mysql_dump_file}' does not exist."
end
if !File.file?(@mysql_dump_file)
raise "MySQL dump file '#{@mysql_dump_file}' is not a file."
end
if !File.readable?(@mysql_dump_file)
raise "MySQL dump file '#{@mysql_dump_file}' is not readable."
end
end end
# Issue the Tomcat stop command and pause for it to take effect. # Issue the Tomcat stop command and pause for it to take effect.
@ -78,7 +92,7 @@ class DatabaseCleanser
puts " Waiting #{@tomcat_start_delay} seconds..." puts " Waiting #{@tomcat_start_delay} seconds..."
sleep(@tomcat_start_delay) sleep(@tomcat_start_delay)
begin begin
open(@website_url){|f|} open(@website_url){|f|}
rescue Timeout::Error rescue Timeout::Error
puts ">>> HTTP request timed out!" puts ">>> HTTP request timed out!"
raise raise
@ -86,7 +100,7 @@ class DatabaseCleanser
puts " ... started." puts " ... started."
end end
# Tell MySQL to drop the database and re-create it. # Tell MySQL to re-create the database and load from the dump file.
# #
def drop_database_and_create_again() def drop_database_and_create_again()
args = [] args = []
@ -96,8 +110,20 @@ class DatabaseCleanser
args << "--execute=drop database #{@database_name}; create database #{@database_name} character set utf8;" args << "--execute=drop database #{@database_name}; create database #{@database_name} character set utf8;"
result = system("mysql", *args) result = system("mysql", *args)
raise("Can't find the 'mysql' command!") if result == nil raise("Can't find the 'mysql' command!") if result == nil
raise("Can't clean the MySQL database: command was 'mysql' #{args}") if !result raise("Can't drop the MySQL database: command was 'mysql' #{args}") if !result
raise("Error code from MySQL: #{$?.exitstatus}, command was 'mysql' #{args}") if $?.exitstatus != 0 raise("Error code from MySQL: #{$?.exitstatus}, command was 'mysql' #{args}") if $?.exitstatus != 0
puts " Re-created the database."
args = []
args << "--user=#{@mysql_username}"
args << "--password=#{@mysql_password}"
args << "--database=#{@database_name}"
args << "--execute=source #{File.expand_path(@mysql_dump_file)};"
result = system("mysql", *args)
raise("Can't find the 'mysql' command!") if result == nil
raise("Can't load the MySQL dump file: command was 'mysql' #{args}") if !result
raise("Error code from MySQL: #{$?.exitstatus}, command was 'mysql' #{args}") if $?.exitstatus != 0
puts " Loaded the databse from the dump file."
end end
# ------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------
@ -114,6 +140,7 @@ class DatabaseCleanser
@website_url = properties['website_url'] @website_url = properties['website_url']
@mysql_username = properties['mysql_username'] @mysql_username = properties['mysql_username']
@mysql_password = properties['mysql_password'] @mysql_password = properties['mysql_password']
@mysql_dump_file = properties['mysql_dump_file']
@database_name = properties['database_name'] @database_name = properties['database_name']
sanity_checks_on_parameters() sanity_checks_on_parameters()

File diff suppressed because one or more lines are too long