Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrate mongodb database from localhost to remote servers

I created a database on my local ubuntu machine.

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

like image 793
Praveen Singh Yadav Avatar asked Jan 23 '14 08:01

Praveen Singh Yadav


People also ask

How do I export an entire MongoDB database?

So, to export data from the MongoDB database, MongoDB provides a command-line tool known as mongoexport. Using this tool you can exports data of a collection in JSON or CSV(comma-separated value) format. Moreover, we can also use features like limit and sort on a collection while exporting the data.


1 Answers

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).

like image 122
Stennie Avatar answered Sep 23 '22 00:09

Stennie