Posted By

nate63179 on 11/03/09


Tagged

mysql database rails


Versions (?)

Rails: Backup a mysql database script


 / Published in: Rails
 

  1. #!/usr/bin/env ruby
  2. require File.dirname(__FILE__) + '/../config/boot'
  3. require 'erb'
  4. require 'yaml'
  5.  
  6. unless config = YAML::load(ERB.new(IO.read(RAILS_ROOT + "/config/database.yml")).result)[RAILS_ENV]
  7. abort "No database is configured for the environment '#{RAILS_ENV}'"
  8. end
  9.  
  10. db_out_path = File.join(RAILS_ROOT, 'tmp', "dbdump_#{RAILS_ENV}.sql")
  11. system "mysqldump -u #{config['username']} --password=#{config['password']} #{config['database']} > #{db_out_path}"

Report this snippet  

You need to login to post a comment.