12

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?

Community
  • 1
  • 1
Michael McC
  • 689
  • 7
  • 17
  • What OS are you using? If you run `which mongodump` on the command line, does it print anything for you? – David Weldon Mar 04 '14 at 17:05
  • OSX. And no, 'which mongodump' does not print anything when I try it. – Michael McC Mar 04 '14 at 17:17
  • Then either you don't have the mongodb client binaries installed on your computer, or they have not been added to your path. See answers like [this one](http://stackoverflow.com/questions/18123771/using-mongodump-mongodump-command-not-found). – David Weldon Mar 04 '14 at 17:20
  • Updated question above to give updated info. – Michael McC Mar 04 '14 at 18:43
  • While your project is running, try doing: `ps aux | grep mongo`. Look for the port it's running on with the text `--port`. Mine is running on 3001. Maybe that's the issue. – David Weldon Mar 04 '14 at 18:50
  • OK, it turns out that the localhost is now 3001, instead of 3002, so if you change that number, then it works. I will post my accumulated knowledge about this process as answer when I see the Answer button come back! – Michael McC Mar 04 '14 at 18:50
  • Voting to close as off-topic, as this is a DBA task, hence it belongs to http://dba.stackexchange.com – Markus W Mahlberg May 01 '15 at 23:23

3 Answers3

32

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.

Michael McC
  • 689
  • 7
  • 17
  • If one wants to mongodump from a server created with meteor-up, then just use `mongodump --db ` – krivar Aug 30 '14 at 12:00
  • 3
    If you just want to drop all collections, add `--drop` to the command, like `mongorestore -h 127.0.0.1 --port 3001 -d meteor --drop dump/meteor` – Inserve Jul 26 '15 at 14:47
2

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

Community
  • 1
  • 1
Bolo
  • 61
  • 1
  • 5
0

If you are restoring to a mup'ed meteor app, the command would be:

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

If you forgot the name of your app, you can see it by going into the mongo shell and listing all databases.

Xauxatz
  • 143
  • 2
  • 9