Created
April 13, 2010 05:05
-
-
Save ryan-allen/364335 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
%w(rubygems hpricot).each { |lib| require(lib) } | |
if ARGV.length < 2 | |
puts "Usage: './backup-databases /path/to/backups label databases,to,ignore'" | |
puts "Example: './backup-databases /tmp/db-backups weekly mysql,information_schema,test'" | |
else | |
output_path = ARGV[0] | |
label = ARGV[1] | |
ignore = ARGV[2] ? ARGV[2].split(',') : [] | |
databases = (Hpricot(`mysql -u root -e "show databases" -X`)/'resultset'/'row'/'field').collect { |row| row.inner_html } | |
`mkdir -p #{output_path}` | |
(databases-ignore).each do |database| | |
`mysqldump -u root #{database} > #{output_path}/#{database}.#{label}.sql` | |
print('.'); $stdout.flush() | |
end | |
puts '' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment