Skip to content

Instantly share code, notes, and snippets.

@ryan-allen
Created April 13, 2010 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryan-allen/364335 to your computer and use it in GitHub Desktop.
Save ryan-allen/364335 to your computer and use it in GitHub Desktop.
#!/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