IdolHands.com :: Days in the Life of an Alpha Geek
After deploying my first project using mongoDB, I had a need to synchronize my local database with the database on our production environment for some testing. This comes up pretty often, so we had previously developed Capistrano tasks for doing this with the MySQL database. So I rolled up my sleeves and created a similar cap task for the MongoDB database.
It's fairly trivial, but may be of use to some of you out there:
set :application, 'www.yourapplication.com' set :user, 'your_ssh_username' set :mongodbname_prod, 'your_production_mongodb_database_name' set :mongodbname_dev, 'your_local_mongodb_database_name' namespace :sync do desc 'Synchronize local MongoDB with production.' task :mongodb, :hosts => "#{application}" do run "cd" run "mongodump --host localhost -d #{mongodbname}" system "scp -Cr #{user}@#{application}:~/dump/#{mongodbname_prod}/ db/backups/" system "mongorestore -h localhost --drop -d #{mongodbname_dev} db/backups/mongodb/" end end
Comments