/ Published in: Rails
This could be further abstracted to work with other db's. Also, it really should be using Ruby's Tempfile class instead of assuming the local machine is *NIX based, but it works :)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
namespace :db do task :sync_to_local, :roles => :web do sql_out = "#{environment_database}.sql" run "mysqldump --user #{dbuser} --password=#{dbpass} #{environment_database} > #{sql_out}" system "sftp #{user}@myhost.com:#{sql_out} /tmp/#{sql_out}" run "rm #{sql_out}" system "mysql -u #{dbuser} --password=#{dbpass} mydatabase_development < /tmp/#{sql_out}" system "rm /tmp/#{sql_out}" end end # invoked: cap production db:sync_to_local