Skip to content

Instantly share code, notes, and snippets.

@bragboy
Created November 21, 2015 15:12
Show Gist options
  • Save bragboy/2b7a4eff9d22da08b88e to your computer and use it in GitHub Desktop.
Save bragboy/2b7a4eff9d22da08b88e to your computer and use it in GitHub Desktop.
#Usage: cap production db:load_from_remote
namespace :db do
desc "Clones the dump from Production and loads to local database"
task :load_from_remote do
on roles(:app) do
within current_path do
with rails_env: fetch(:rails_env) do
execute 'pg_dump --format=c mydb_production > /var/apps/my_project/shared/prod_db.dump'
end
end
structure_file = "#{shared_path}/prod_db.dump"
download!(structure_file, "/tmp", via: :scp, recursive: false)
end
system! 'pg_restore --verbose --clean --no-acl --no-owner -h localhost -U bragadeeshj -d mydb_development /tmp/prod_db.dump'
end
def system!(cmd)
puts "Executing locally : #{cmd}"
system(cmd) or raise "Failed to run: #{cmd}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment