Skip to content

Instantly share code, notes, and snippets.

@addywaddy
Created November 6, 2014 16:14
Show Gist options
  • Save addywaddy/14baacff22aa93eaba84 to your computer and use it in GitHub Desktop.
Save addywaddy/14baacff22aa93eaba84 to your computer and use it in GitHub Desktop.
Tasks for importing and exporting DB dumps.
namespace :db do
task export: [:environment] do
conn = ActiveRecord::Base.connection_config
cmd = "PGPASSWORD=#{conn[:password]} pg_dump -Fc -h localhost -U #{conn[:username]} #{conn[:database]} > /tmp/#{conn[:database]}.sql"
puts cmd
system cmd
end
task :import => [:environment] do
conn = ActiveRecord::Base.connection_config
cmd = "PGPASSWORD=#{conn[:password]} pg_restore -h #{conn[:host]} -U #{conn[:username]} -d #{conn[:database]} #{ENV['DUMP']} &> /dev/null"
puts cmd
system cmd
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment