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"
isGzip=@options[:gzip]
limitDays=@options[:limit_days] || 3
gzipSuffix = @options[:gzip_suffix] || '.gz'
Array(@db_info[:database]).flat_map.each_with_index do |database, index |
defaultOptions="--column-statistics=0 #{mysqlDefaultOptions(@db_info, database)}"
backupDir=backupDirName(id, "#{index}_#{database}")
commands = []
if File.exist? backupDir
puts "[skip - directory exists] #{backupDir}"
return commands
end
commands.push "mkdir -p #{backupDir}"
backupFile="#{backupDir}/#{DateTime.now.strftime("%Y-%m-%d")}_#{id}"
whereDate=(Date.today - limitDays).strftime("%Y-%m-%d 00:00:00")
options=ENV['DUMP_OPTIONS'] || "--single-transaction --skip-lock-tables"
puts "backupFile=#{backupFile}"
ignoreTablesOption = @ignore_tables.map { |e| "--ignore-table=#{e.include?('.') ? e : "#{database}.#{e}"}" }.join(' ')
commands.push gzipCommand("mysqldump --no-data #{ignoreTablesOption} #{defaultOptions}", isGzip, "#{backupFile}-schema.sql", gzipSuffix)
backupTables = []
@data_tables.each {|table|
where = table[:where].empty? ? "" : "--where=\"#{table[:where]} >= '#{whereDate}'\""
if where.empty?
backupTables.push(table[:name])
next
else
commands.push(gzipCommand("mysqldump --no-create-info #{options} #{where} #{defaultOptions} #{table[:name]}", isGzip, "#{backupFile}-#{table[:name]}.sql", gzipSuffix))
end
}
commands.push(gzipCommand("mysqldump --no-create-info #{ignoreTablesOption} #{options} #{defaultOptions} #{backupTables.join(' ')}", isGzip, "#{backupFile}-all-other-tables.sql", gzipSuffix))
commands
end
end
|