In this lab, students are asked to back up the metadata of a MongoDB replica set. The cluster metadata includes all configuration information for the cluster, especially the mapping from chunks to shards. After completing this lab, students will have hands-on experience backing up the metadata of a MongoDB replica set.
Log in to the server labeled as Node0 using the credentials provided:
ssh cloud_user@<PUBLIC_IP_ADDRESS>
Connect to the cluster using the mongosh shell:
mongosh mongodb://10.0.0.101
Check the current balancer state:
sh.getBalancerState()
If the balancer is currently set to true, stop the. balancer:
sh.stopBalancer()
Check the current balancer state to ensure it was successfully stopped:
sh.getBalancerState()
Create a Full Copy of Config Instance
Switch to the admin database:
use admin
List the configuration of the sharded cluster:
db.runCommand("getShardMap")
After seeing our configuration servers are on the lab host server 10.0.0.102, connect to the configuration server (labeled as Node1 in the lab):
ssh 10.0.0.102
cloud_user@ip-10-0-0-101:~$ ssh 10.0.0.102
The authenticity of host '10.0.0.102 (10.0.0.102)' can't be established.
ECDSA key fingerprint is SHA256:TmfXo6jpyZ3q4NwwXwV7p1N8PMN4TVhEnAIE5LtEm4E.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added '10.0.0.102' (ECDSA) to the list of known hosts.
Password:
Welcome to Ubuntu 18.04.6 LTS (GNU/Linux 5.4.0-1096-aws x86_64)
When prompted, enter yes.
When prompted, enter the password associated with cloud_user on Node1.
Stop the mongod service:
sudo service mongod stop
When prompted, enter the password associated with cloud_user on Node1.
Check the status of the mongod service to ensure it was successfully stopped:
sudo service mongod status
Check the DB path of the configuration file:
grep dbPath /etc/mongod.conf
Back up the data files to the backup subdirectory of the home directory:
sudo cp -rv /var/lib/mongodb/ ~/backup/
Restart the mongod service:
sudo service mongod start
Check the status of the service to make sure it is up and running:
sudo service mongod status
Connect to the query router using the mongosh shell:
mongosh mongodb://10.0.0.101
Re-enable the balancer:
sh.startBalancer()
Check the status of the balancer to make sure it was successfully re-enabled:
sh.getBalancerState()