Migrate mongodb database from localhost to remote servers

Praveen Singh Yadav picture Praveen Singh Yadav · Jan 23, 2014 · Viewed 53.3k times · Source

I created a database on my local ubuntu machine.

How can I transfer it to my remote server (ec2 Ubuntu)

Answer

Stennie picture Stennie · Jan 24, 2014

TL;DR

Use mongodump and mongorestore to take (and restore) a full binary backup of your MongoDB database. Compress the backup dump directory to make it faster to copy to your Amazon instance (BSON tends to compress very well).

Best practices

Rather than following adhoc instructions, I would strongly recommend reading the standard Backup and Restore with MongoDB Tools tutorial in the MongoDB manual.

You can also use a Filesystem snapshot, but mongodump and mongorestore only export the data so your backup will be smaller (i.e. your remote server will not inherit any excessive storage allocation due to preallocation).