Last active
December 3, 2018 07:17
-
-
Save nicolai86/5524034 to your computer and use it in GitHub Desktop.
sync down the content of a mysql database used by a ruby on rails application using mina.
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
RYAML = <<-BASH | |
function ryaml { | |
ruby -ryaml -e 'puts ARGV[1..-1].inject(YAML.load(File.read(ARGV[0]))) {|acc, key| acc[key] }' "$@" | |
}; | |
BASH | |
namespace :sync do | |
task :db do | |
isolate do | |
invoke :environment | |
queue RYAML | |
queue "USERNAME=$(ryaml #{deploy_to}/shared/config/database.yml #{rails_env} username)" | |
queue "PASSWORD=$(ryaml #{deploy_to}/shared/config/database.yml #{rails_env} password)" | |
queue "DATABASE=$(ryaml #{deploy_to}/shared/config/database.yml #{rails_env} database)" | |
queue "mysqldump $DATABASE --user=$USERNAME --password=$PASSWORD > #{deploy_to}/dump.sql" | |
queue "gzip -f #{deploy_to}/dump.sql" | |
mina_cleanup! | |
end | |
%x[scp #{user}@#{domain}:#{deploy_to}/dump.sql.gz .] | |
%x[gunzip -f dump.sql.gz] | |
%x[#{RYAML} mysql --verbose --user=$(ryaml config/database.yml development username) --password=$(ryaml config/database.yml development password) $(ryaml config/database.yml development database) < dump.sql] | |
%x[rm dump.sql] | |
end | |
end |
Thank you for the script ! I fork and update it for my own use (push local db to prod). This is not perfect but It works. ;-)
thanks! I only had to remove the ;
from the RYAML
block in order to make it work
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this script. I found the RYAML part particularly useful.