Class: DBGet::Loaders::MySql
Constant Summary
Constants included
from Constants
Constants::CONFIG_PATH, Constants::MONGO_FILE_EXT, Constants::MONGO_INDEX_FILE
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Binaries
find_cmd, get_binary, mongorestore_cmd, mysql_cmd, tar_cmd
Constructor Details
#initialize(dump, config) ⇒ MySql
Returns a new instance of MySql.
11
12
13
14
15
16
|
# File 'lib/dbget/loaders/mysql.rb', line 11
def initialize(dump, config)
@dump = dump
@config = config
@date = @dump.date
@dump_command = form_dump_command
end
|
Class Method Details
.boot(dump, config) ⇒ Object
7
8
9
|
# File 'lib/dbget/loaders/mysql.rb', line 7
def self.boot(dump, config)
self.new(dump, config)
end
|
Instance Method Details
#clean_dump ⇒ Object
38
39
40
41
|
# File 'lib/dbget/loaders/mysql.rb', line 38
def clean_dump
puts "Dropping database..."
system "echo \"DROP DATABASE IF EXISTS #{@dump.target_db}\" | #{@dump_command}"
end
|
#create_db_if_not_exist ⇒ Object
43
44
45
|
# File 'lib/dbget/loaders/mysql.rb', line 43
def create_db_if_not_exist
system "echo \"CREATE DATABASE IF NOT EXISTS #{@dump.target_db}\" | #{@dump_command}"
end
|
#dump_mysql ⇒ Object
47
48
49
50
51
52
|
# File 'lib/dbget/loaders/mysql.rb', line 47
def dump_mysql
@dump_command += " #{@dump.target_db} "
out = system("#{@dump_command}< #{@dump.decrypted_dump}")
exit 1 unless out
end
|
25
26
27
28
29
30
31
32
|
# File 'lib/dbget/loaders/mysql.rb', line 25
def form_dump_command
@dump_command = "#{Binaries.mysql_cmd} "
@dump_command += "-h#{@config['mysql']['host']} "
@dump_command += "-P#{@config['mysql']['port']} "
@dump_command += "-u#{@config['mysql']['username']} "
@dump_command += "-p#{@config['mysql']['password']} " if @config['mysql']['password']
@dump_command
end
|
#get_converted_date ⇒ Object
34
35
36
|
# File 'lib/dbget/loaders/mysql.rb', line 34
def get_converted_date
@dump.date.to_s.delete('-')
end
|
#load! ⇒ Object
18
19
20
21
22
23
|
# File 'lib/dbget/loaders/mysql.rb', line 18
def load!
@dump.form_db_name
clean_dump if @dump.clean?
create_db_if_not_exist
dump_mysql
end
|