Class: Outback::MysqlSource
Instance Attribute Summary
Attributes inherited from Source
#backup_name
Instance Method Summary
collapse
Methods inherited from Source
#create_archive, #initialize
Methods included from Logging
#logger
#attr_setter, included
Instance Method Details
#create_archives(timestamp, tmpdir) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/outback/mysql_source.rb', line 25
def create_archives(timestamp, tmpdir)
mysql_host = host || 'localhost'
mysql_port = (port || 3306) unless socket
if databases.empty?
mysql = Mysql.connect(mysql_host, user, password, nil, mysql_port, socket)
@databases = mysql.list_dbs - excludes
mysql.close
end
archives = databases.collect do |database|
archive_name = Pathname.new(tmpdir).join("#{backup_name}_#{timestamp}_#{database}.sql.gz")
mysql_conf_file = Pathname.new(tmpdir).join('outback_my.cnf')
File.open(mysql_conf_file, 'w') { |f| f << "[client]\npassword=#{password}\n" }
FileUtils.chmod 0600, mysql_conf_file
logger.debug "MysqlSource: dumping database '#{database}'"
commandline = "mysqldump --defaults-extra-file=#{mysql_conf_file} --opt --user=#{user} --host=#{mysql_host} --port=#{mysql_port} #{database} | gzip > #{archive_name}"
result = `#{commandline}`.strip
logger.debug(result) unless result.blank?
logger.info "Archived database #{database}"
SourceArchive.new(archive_name).tap { |archive| logger.debug "dumped #{archive.filename.basename} with #{archive.size} bytes" }
end
end
|
#database(*names) ⇒ Object
13
14
15
|
# File 'lib/outback/mysql_source.rb', line 13
def database(*names)
databases.concat(names.map(&:to_s)).uniq!
end
|
#databases ⇒ Object
5
6
7
|
# File 'lib/outback/mysql_source.rb', line 5
def databases
@databases ||= []
end
|
#exclude(*names) ⇒ Object
17
18
19
|
# File 'lib/outback/mysql_source.rb', line 17
def exclude(*names)
excludes.concat(names.map(&:to_s)).uniq!
end
|
9
10
11
|
# File 'lib/outback/mysql_source.rb', line 9
def excludes
@excludes ||= ['mysql', 'performance_schema', 'information_schema']
end
|
#valid? ⇒ Boolean
21
22
23
|
# File 'lib/outback/mysql_source.rb', line 21
def valid?
user && password
end
|