19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/mysql_db_tool/backup.rb', line 19
def perform
verify_tools_exist
id=@options[:id] || "0"
use_gzip=@options[:gzip]
limit_days=@options[:limit_days] || 3
gzip_suffix = @options[:gzip_suffix] || '.gz'
Array(@db_info[:database]).flat_map.each_with_index do |database, index |
default_options="--column-statistics=0 #{mysql_default_options(@db_info, database)}"
backup_dir=backup_dir_name(id, "#{index}_#{database}")
commands = []
if File.exist? backup_dir
puts "[skip - directory exists] #{backup_dir}"
return commands
end
commands.push "mkdir -p #{backup_dir}"
backup_file="#{backup_dir}/#{DateTime.now.strftime("%Y-%m-%d")}_#{id}"
where_date=(Date.today - limit_days).strftime("%Y-%m-%d 00:00:00")
options=ENV['DUMP_OPTIONS'] || "--single-transaction --skip-lock-tables --no-tablespaces"
puts "backupFile=#{backup_file}"
ignore_tables_option = @ignore_tables.map { |e| "--ignore-table=#{e.include?('.') ? e : "#{database}.#{e}"}" }.join(' ')
commands.push gzip_command("mysqldump --no-data #{ignore_tables_option} #{options} #{default_options}", use_gzip, "#{backup_file}-schema.sql", gzip_suffix)
backup_tables = []
@data_tables.each {|table|
where = table[:where].empty? ? "" : "--where=\"#{table[:where]} >= '#{where_date}'\""
if where.empty?
backup_tables.push(table[:name])
next
else
commands.push(gzip_command("mysqldump --no-create-info #{options} #{where} #{default_options} #{table[:name]}", use_gzip, "#{backup_file}-#{table[:name]}.sql", gzip_suffix))
end
}
commands.push(gzip_command("mysqldump --no-create-info #{ignore_tables_option} #{options} #{default_options} #{backup_tables.join(' ')}", use_gzip, "#{backup_file}-all-other-tables.sql", gzip_suffix))
commands
end
end
|