Search code examples
mongodbreplicaset

How to backup mongodb replica set


I have a mongodb(replica set) and I want to dump this database, I know I can dump a mongodb with a simple cli command and It's working here. But I'm trying to use the same command to dump a replica set, Am I supposed to use the same command?

mongodump -h "example-shard01:27017,example-shard02:27017,example-shard03:27017" --username=myusername --password=mypass --out=/destination

Solution

  • You need to specify the replica set in connection string URI. Similar to this:

    "example-shard01:27017,example-shard02:27017,example-shard03:27017/?replicaSet=myRepl"
    

    Your hostnames are bit strange, they look more like a shards in a sharded cluster. Don't mix them.