Title / Description
Code namespace :db do # Declare some variables timestamp = Time.now.strftime("%Y-%m-%d") backup_dir = "#{RAILS_ROOT}/db" namespace :backup do desc 'Backup all the local databases defined in config/database.yml' task :all => :environment do ActiveRecord::Base.configurations.each_value do |config| system "mysqldump -u #{config['username']} -p#{config['password']} \ #{config['database']} > \ #{backup_dir}/#{config['database']}_#{timestamp}.sql" end end end desc 'Backup the database for the current RAILS_ENV' task :backup => :environment do config = ActiveRecord::Base.configurations[RAILS_ENV] system "mysqldump -u #{config['username']} -p#{config['password']} \ #{config['database']} > \ #{backup_dir}/#{config['database']}_#{timestamp}.sql" end end
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code