Created
March 23, 2017 15:35
-
-
Save sbounmy/e81cdebcf3e840ebdf61fb8e8a5e126b to your computer and use it in GitHub Desktop.
Rake task to import production database from heroku mongodb
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
namespace :db do | |
desc "Import from production env" | |
task import: :environment do | |
raise 'this should be run in dev mode !!' unless Rails.env == 'development' | |
uri = Mongo::URI.new(`heroku config:get MONGODB_URI`.chomp) | |
tmp = Dir::Tmpname.make_tmpname('/tmp/', 'hh-dump') | |
puts "Dumping #{uri.servers[0]} to #{tmp}..." | |
`mongodump -h #{uri.servers[0]} -d #{uri.database} -u #{uri.credentials[:user]} -p #{uri.credentials[:password]} -o #{tmp}` | |
dev = Mongoid.clients['default'] | |
`mongorestore --host #{dev['hosts'][0]} --drop -d #{dev['database']} #{tmp}/#{uri.database}` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment