Creating a backup of a sharded cluster
In this recipe, we will be looking at how to take a backup of a sharded MongoDB cluster. We will be looking at how to backup the config server and the relevant shards which contain the actual data.
Getting ready
You will need a sharded MongoDB cluster, with a minimum of a config server replica set (CSRS) and one shard. Refer to the recipe Setting up and configuring a sharded cluster in Chapter 5, High Scalability with Sharding, on how to create a sharded cluster.
How to do it...
- Connect to the mongos server and stop the balancer:
use config sh.stopBalancer()
- Take a backup of the config server:
mongodump -h localhost -p 27019 -d config --out /backups/configbkp
- Take backup from the shard:
mongodump -h localhost -p 27027 -d myShardedDB --out /backups/shard1bkp
- Connect back to the mongos server and enable the balancer:
use config sh.startBalancer()
How it works...
Taking backups of a sharded cluster is a bit nuanced, as it involves ensuring certain steps are considered...