Created
January 21, 2009 20:52
-
-
Save stevebartholomew/50180 to your computer and use it in GitHub Desktop.
Simple database backup rake task for Rails using mysqldump
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
namespace :backup do | |
desc "Backup database" | |
task :db do | |
RAILS_ENV = "development" if !defined?(RAILS_ENV) | |
app_root = File.join(File.dirname(__FILE__), "..", "..") | |
settings = YAML.load(File.read(File.join(app_root, "config", "database.yml")))[RAILS_ENV] | |
output_file = File.join(app_root, "..", "backup", "#{settings['database']}-#{Time.now.strftime('%Y%M%d')}.sql") | |
system("/usr/bin/env mysqldump -u #{settings['username']} -p#{settings['password']} #{settings['database']} > #{output_file}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
But there is Command Injection