Rails: Backup a mysql database script


/ Published in: Rails
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.