Skip to content

Instantly share code, notes, and snippets.

@ryw
Created October 1, 2012 19:47
Show Gist options
  • Save ryw/3814014 to your computer and use it in GitHub Desktop.
Save ryw/3814014 to your computer and use it in GitHub Desktop.
Restore production Mongo data to dev & staging
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