Created
October 1, 2012 19:47
-
-
Save ryw/3814014 to your computer and use it in GitHub Desktop.
Restore production Mongo data to dev & staging
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 | |
namespace :sync do | |
desc "Copy production database to local" | |
task :dev => :environment do | |
puts "Dumping production..." | |
system "mongodump -h #{ENV['PRODUCTION_MONGOHQ_DOMAIN']}:#{ENV['PRODUCTION_MONGOHQ_PORT']} -d #{ENV['PRODUCTION_MONGOHQ_DATABASE']} -u #{ENV['PRODUCTION_MONGOHQ_USER']} -p#{ENV['PRODUCTION_MONGOHQ_PASSWORD']} -o db/backups/" | |
puts "Restoring production to development..." | |
system "mongorestore -h localhost --drop -d crowdhall_web_v1_development db/backups/#{ENV['PRODUCTION_MONGOHQ_DATABASE']}/" | |
puts "Deleting temporary files..." | |
system "rm -r db/backups/" | |
end | |
desc "Copy production database to staging" | |
task :staging => :environment do | |
puts "Dumping production..." | |
system "mongodump -h #{ENV['PRODUCTION_MONGOHQ_DOMAIN']}:#{ENV['PRODUCTION_MONGOHQ_PORT']} -d #{ENV['PRODUCTION_MONGOHQ_DATABASE']} -u #{ENV['PRODUCTION_MONGOHQ_USER']} -p#{ENV['PRODUCTION_MONGOHQ_PASSWORD']} -o db/backups/" | |
puts "Restoring production to staging..." | |
system "mongorestore -h #{ENV['STAGING_MONGOHQ_DOMAIN']}:#{ENV['STAGING_MONGOHQ_PORT']} --drop -d crowdhall_v1_staging db/backups/#{ENV['PRODUCTION_MONGOHQ_DATABASE']}/" | |
puts "Deleting temporary files..." | |
system "rm -r db/backups/" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment