Created
May 26, 2016 02:43
-
-
Save jcsky/6fdc538642fc41bdfa95b4759eeec0e5 to your computer and use it in GitHub Desktop.
dump staging/production db and restore to local db, just use rake:db_pull
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
namespace :db do | |
desc 'Pull staging db to development' | |
task :pull => [:dump, :restore] | |
task :dump do | |
dumpfile = "#{Rails.root}/tmp/latest.dump" | |
puts 'PG_DUMP on staging database...' | |
staging = Rails.application.config.database_configuration['staging'] | |
system "ssh user@server 'PGPASSWORD=\"#{staging['password']}\" pg_dump -U postgres #{staging['database']} -h #{staging['host']} -F t' > #{dumpfile}" | |
puts 'Done!' | |
end | |
task :restore do | |
dev = Rails.application.config.database_configuration['development'] | |
dumpfile = "#{Rails.root}/tmp/latest.dump" | |
puts 'PG_RESTORE on development database...' | |
system "pg_restore --verbose --clean --no-acl --no-owner -h 127.0.0.1 -U #{dev['username']} -d #{dev['database']} #{dumpfile}" | |
puts 'Done!' | |
end | |
end | |
# source https://martinschurig.com/posts/2015/02/pulling-production-database-to-local-machine-rails-task/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment