Posted By

nate63179 on 11/03/09


Tagged

mysql rails ruby capistrano


Versions (?)

Capistrano: Synchronize local mysql database to remote mysql database


 / 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 :)

  1. namespace :db do
  2. task :sync_to_local, :roles => :web do
  3. sql_out = "#{environment_database}.sql"
  4. run "mysqldump --user #{dbuser} --password=#{dbpass} #{environment_database} > #{sql_out}"
  5. system "sftp #{user}@myhost.com:#{sql_out} /tmp/#{sql_out}"
  6. run "rm #{sql_out}"
  7. system "mysql -u #{dbuser} --password=#{dbpass} mydatabase_development < /tmp/#{sql_out}"
  8. system "rm /tmp/#{sql_out}"
  9. end
  10. end
  11.  
  12. # invoked: cap production db:sync_to_local

Report this snippet  

You need to login to post a comment.