Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Back up meteor database with mongodump?

Tags:

mongodb

meteor

This post is about backing up your meteor database

I am trying to back up my meteor database and I understand what this post is telling me to do, but I must not be in the right directory when I run the mongodump command, b/c I keep getting 'Command not found'. Or do I need to export a path?


[EDIT]

OK, now I have the binaries installed but when I run 'mongodump', I get:

couldn't connect to [127.0.0.1] couldn't connect to server 127.0.0.1:27017

... and when I run 'mongodump --host localhost:3002', I get:

couldn't connect to [localhost:3002] couldn't connect to server localhost:3002

Now what?

like image 1000
Michael McC Avatar asked Mar 04 '14 17:03

Michael McC


People also ask

Does Mongodump lock the database?

Mongdump does not lock the db. It means other read and write operations will continue normally. Actually, both mongodump and mongorestore are non-blocking. So if you want to mongodump mongorestore a db then its your responsibility to make sure that it is really a desired snapshot backup/restore.


2 Answers

OK, thanks to @David Weldon, I can provide a fairly complete answer to this issue:

Backing up and restoring your local MongoDB for Meteor users (OSX)

Backup:

1) Your app must be running, so start up your Meteor server.

2) In a terminal window (NOT in the meteor mongo shell), enter: mongodump -h 127.0.0.1 --port 3001 -d meteor

This will create a 'dump' directory inside your home folder (your name under Users).

3) If you get a 'command not found' message, you probably just installed Mongo as a part of Meteor, meaning you don't have the mongo command line tools. Use a package like Homebrew to reinstall Mongo and you will have the command line tools. This will also add the correct PATH information to your system, so that it can find the tools.

Restoring:

1) From MiniMongo shell (run ‘meteor mongo’ inside your Meteor project dir), enter:

db.[collectionName].drop(); //repeat for all collections you wish to restore

2) Then, from a terminal window, enter:

mongorestore -h 127.0.0.1 --port 3001 -d meteor dump/meteor

Caveats:

The individual documents will not necessarily be in the same order after they are restored. So you need some way to sort documents that need to be presented in a certain order.

like image 76
Michael McC Avatar answered Sep 20 '22 16:09

Michael McC


Caveats:

The individual documents will not necessarily be in the same order after they are restored. So you need some way to sort documents that need to be presented in a certain order.

There is a flag for this mongorestore --maintainInsertionOrder

like image 21
Bolo Avatar answered Sep 20 '22 16:09

Bolo