Class: EY::Backup::MysqlEngine
- Inherits:
-
Engine
show all
- Defined in:
- lib/ey_backup/engines/mysql_engine.rb
Constant Summary
Constants included
from Spawner
Spawner::CHUNK_SIZE
Instance Attribute Summary
Attributes inherited from Engine
#host, #key_id, #password, #username
Instance Method Summary
collapse
Methods inherited from Engine
descendants, #gpg?, inherited, #initialize, label, lookup, register
Methods included from Spawner
#ioify, #run, #runs?, #spawn
Methods inherited from Base
#logger
Instance Method Details
#db_has_myisam?(database_name) ⇒ Boolean
60
61
62
63
64
|
# File 'lib/ey_backup/engines/mysql_engine.rb', line 60
def db_has_myisam?(database_name)
query, stdout = "SELECT 1 FROM information_schema.tables WHERE table_schema='#{database_name}' AND engine='MyISAM' LIMIT 1;", StringIO.new
spawn(%Q{mysql #{username_option} #{password_option} #{host_option} -N -e"#{query}"}, stdout)
stdout.string.strip == '1'
end
|
#dump(database_name, basename) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/ey_backup/engines/mysql_engine.rb', line 6
def dump(database_name, basename)
file = basename + '.sql'
command = "mysqldump #{username_option} #{host_option} #{password_option} #{single_transaction_option(database_name)} #{routines_option} #{database_name}"
if gpg?
command << " | " << GPGEncryptor.command_for(key_id)
file << GPGEncryptor.extension
else
command << " | " << GZipper.gzip
file << GZipper.extension
end
command << " > #{file}"
run(command)
file
end
|
#host_option ⇒ Object
48
49
50
|
# File 'lib/ey_backup/engines/mysql_engine.rb', line 48
def host_option
"-h#{host}"
end
|
#load(database_name, file) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/ey_backup/engines/mysql_engine.rb', line 26
def load(database_name, file)
command = "cat #{file}"
if gpg?
raise "Cannot load a GPG backup"
else
command << " | " << GZipper.gunzip
end
command << " | mysql #{username_option} #{host_option} #{password_option} #{database_name}"
run(command)
end
|
#password_option ⇒ Object
44
45
46
|
# File 'lib/ey_backup/engines/mysql_engine.rb', line 44
def password_option
"-p'#{password}'" unless password.nil? || password.empty?
end
|
#routines_option ⇒ Object
40
41
42
|
# File 'lib/ey_backup/engines/mysql_engine.rb', line 40
def routines_option
"--routines"
end
|
#single_transaction_option(database_name) ⇒ Object
56
57
58
|
# File 'lib/ey_backup/engines/mysql_engine.rb', line 56
def single_transaction_option(database_name)
'--single-transaction' unless db_has_myisam?(database_name)
end
|
#suffix ⇒ Object
66
67
68
|
# File 'lib/ey_backup/engines/mysql_engine.rb', line 66
def suffix
/sql\.(gz|gpz)$/
end
|
#username_option ⇒ Object
52
53
54
|
# File 'lib/ey_backup/engines/mysql_engine.rb', line 52
def username_option
"-u#{username}"
end
|