Created
November 6, 2014 16:14
-
-
Save addywaddy/14baacff22aa93eaba84 to your computer and use it in GitHub Desktop.
Tasks for importing and exporting DB dumps.
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 | |
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