panel.jpg Follow us on Twitter and Facebook

/// Blog

June 4, 2013
Category: Development Written by: Tagged: aws ec2 hat-tip mongodb

Moving MongoDB database from one server to another

This month, I noticed the our AWS bills were running quite high for the past year. I had setup an EC2 instance a while back which was running batch jobs every day. However, there was no reason for me to dedicate an entire machine to run those jobs.

Hence, I decided to move them to a different server (that would work out much cheaper!)

The batch job scripts and the MongoDB database was all that I had to transfer from one server to another. I followed the below steps ….

1) Moving the scrips was as simple as moving the files.

2) Moving the database involved the following commands. My database is called pinterestjs

Create a temporary folder using mkdir -p ~/tmp/pinterestjsdump

Dump the existing database using mongodump -d pinterestjs -o ~/tmp/pinterestjsdump

Next to transfer files, I use s3cmd

Create a bucket (if not already existing) s3cmd mb s3://tempbin

Zip the files using zip -r pinterestjs.zip tmp/pinterestjsdump

PUT transfer using s3cmd with s3cmd put pinterestjs.zip s3://tempbin


On the NEW machine …

GET the file using s3cmd with s3cmd get s3://tempbin/pinterestjs.zip

Unzip the file using unzip pinterestjs.zip

Restore the MongoDB database using mongorestore -d pinterestjs tmp/pinterestjsdump/pinterestjs


Works just fine! Saved some money!

/// Our Twitter Feed

Find out what's happening, right now, with the people and organizations you care about.

Twitter
Copyright 2012 MyPad.in