-
-
Save zudochkin/1ad1ce8d589efdba3d2f to your computer and use it in GitHub Desktop.
sync down the content of a postgresql database used by a rails application using mina.
This file contains hidden or 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 "PGPASSWORD=$PASSWORD pg_dump -U $USERNAME $DATABASE -c -f #{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} psql -d $(ryaml config/database.yml development database) -f dump.sql] | |
%x[rm dump.sql] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment