Skip to content

Instantly share code, notes, and snippets.

@guange2015
Created September 17, 2013 08:11
Show Gist options
  • Select an option

  • Save guange2015/6591403 to your computer and use it in GitHub Desktop.

Select an option

Save guange2015/6591403 to your computer and use it in GitHub Desktop.
mysql备份
#!/usr/bin/env ruby
require 'date'
DBS = %w( depot_development )
USER = "root" # Username with rights to all those databases, might be root
PW = "123456" # Password for that username
today_s = Date.today().to_s
yesterday_s = (Date.today()-(2)).to_s
DBS.each do |db|
system "mysqldump --user=#{USER} --password=#{PW} --add-drop-database --opt -icC #{db} > /tmp/#{today_s}-#{db}.sql"
if File.exist?("/tmp/#{yesterday_s}-#{db}.sql")
File.unlink("/tmp/#{yesterday_s}-#{db}.sql")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment