0

Can anyone indicate the right way to backup a MongoDB database with mongodump?

I have tried:

mongodump --host "cluster0-shard-00-00-2djno.mongodb.net:27017,cluster0-shard-00-01-2djno.mongodb.net:27017,cluster0-shard-00-02-2djno.mongodb.net:27017" \
  --authenticationDatabase admin --ssl --username admin \
  --password mypassword -o /tmp

When I do that I get:

Failed: error connecting to db server: no reachable servers

Verifying connection to an individual node with both the ping and telnet commands such that these nodes are valid.

The mongodump version is 3.2.13.

migrated from stackoverflow.com Jun 11 '17 at 11:34

This question came from our site for professional and enthusiast programmers.

1

Yes, when you are connecting to replica set, you must give RS name at start of connection string. You are (here) connecting to replica set, not cluster (even your RS is named "Cluster0-shard-0). BUT, if you are really taking backup of cluster, you should use file system snapshots or if you want to use mongodump (the hard way), follow these instructions to get consistent backup.

AND you are missing one parameter.. You should add --oplog parameter or you cannot restore that RS as "consistent".

1

Upgrading to MongoDB 3.4 was necessary, since the cluster string did not appear to work with 3.2.

Also, based on the blog post for 'importing data', a small tweak to the host parameter seemed necessary, in the form of adding the 'Cluster0-shard-0/' prefix :

mongodump --host "Cluster0-shard-0/cluster0-shard-00-00-2djno.mongodb.net:27017,cluster0-shard-00-01-2djno.mongodb.net:27017,cluster0-shard-00-02-2djno.mongodb.net:27017" \
  --authenticationDatabase admin --ssl --username admin \
  --password mypassword --oplog -o /tmp

Edit: updated the response based on @jjussi's feedback. Also, we aren't trying to avoid using the mongo cloud backup, which is more convenient, it is that we just feel better having our own local copy, for various reasons.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.