IdolHands.com :: Days in the Life of an Alpha Geek
At SEO Logic, we're getting ready to deploy the latest version of our search-engine-optimized content management system, SiteLogic. Aside from a new user interface, the biggest change to the SEO CMS is a shiny new MongoDB database backend. We're deploying to Heroku, which uses MongoHQ to provide database hosting.
One of the challenges we faced with the cloud-based production environment was keeping our development databases in sync with the production database. Back in our MySQL days, we had a capistrano task to pull down a dump of the database and update our local copies; with MongoDB, it's a little more complex, but we found a solution.
Back in September I wrote a brief article on how to accomplish this in a traditional hosting environment (where capistrano has SSH access to a shell on the server), but with Heroku, there's no shell. So here is a revised approach to doing this remotely.
We created a new rake task in /lib/tasks/database that does the trick:
namespace :database do desc "Copy production database to local" task :sync => :environment do system 'mongodump -h flame.mongohq.com:27053 -d YOUR_HEROKU_APP_NAME -u heroku -p HEROKU_PASSWORD -o db/backups/' system 'mongorestore -h localhost --drop -d DEV_DATABASE_NAME db/backups/YOUR_HEROKU_APP_NAME/' end end
Be sure to replace the placeholders with the appropriate names, login, and password for your configuration. You can get these values from your local command line using:
The Heroku and MongoHQ combination is turning out to be a great choice for us. I strongly encourage you to explore this option for your next MongoDB-based Rails deployment.
Comments