Complete the following steps to restore the MongoDB data with the backup data if you encounter data loss or corruption during the upgrade process.

1.Log in to the Linux server as the root user.

2.Stop the MongoDB Service.

1)Run the service <mongodb service name> stop command to stop the MongoDB service.

2)Run the ps -ef|grep mongod command to verify whether the mongod process is stopped.

[root@localhost ~]# ps -ef| grep mongod
root     15136 14237  0 10:42 pts/2    00:00:00 grep --color=auto mongod

Note: If the mongod process is stopped, the result should only contain one entry as shown above.

Note: The default name of the MongoDB service varies by different NetworkBrain system versions. In v7.0b/b1 system, MongoDB service name is mongodnetbrain; starting from v7.1, MongoDB service name is mongod.

3.Restore the old data onto the MongoDB.

1)Run the cd /usr/lib/mongodb command to navigate to the /usr/lib/mongodb directory.

Note: The default directory to store all MongoDB data files is /usr/lib/mongodb. If you modified it during the MongoDB installation, you must replace the path (available in mongod.conf) accordingly.

2)Run the ls -al command to browse all directories and files under the /usr/lib/mongodb directory.

[root@localhost mongodb]# ls -al
total 142
drwxr-xr-x. 5 netbrain netbrain   146 Oct 19 15:02 .              
drwxr-xr-x. 4 root     root        42 Sep 19 14:41 ..                  
drwxr-xr-x. 4 root     root        42 Oct 19 15:03 data  
drwxr-xr-x. 4 root     root       100 Oct 19 15:03 log
-rwxr-xr-x. 2 netbrain netbrain  1004 Aug 25 17:26 mongodb-keyfile
-rwxr-xr-x. 1 netbrain netbrain  1076 Oct 19 15:02 mongod.conf

3)Run the rm -rf ./data command to delete the data directory.

4)Run the mv /etc/mongodb_databk/data command under the /usr/lib/mongodb directory to move the data directory to the /usr/lib/mongodb directory.

5)Run the ls -al command to browse all directories and files under the /usr/lib/mongodb directory.

[root@localhost mongodb]# ls -al
total 142
drwxr-xr-x. 5 netbrain netbrain   146 Oct 19 15:02 .              
drwxr-xr-x. 4 root     root        42 Sep 19 14:41 ..                   
drwxr-xr-x. 4 root     root     86016 Oct 19 15:03 data
drwxr-xr-x. 4 root     root       100 Oct 19 15:03 log
-rwxr-xr-x. 2 netbrain netbrain  1004 Aug 25 17:26 mongodb-keyfile
-rwxr-xr-x. 1 netbrain netbrain  1076 Oct 19 15:02 mongod.conf
-rwxr-xr-x. 1 netbrain netbrain  1147 Oct 19 14:51 mongod.conf2017|Oct|19|10:15:50

4.Run the service <mongodb service name> start command to restart the MongoDB service.

Note: The default name of the MongoDB service varies by different NetworkBrain system versions. In v7.0b/b1 system, MongoDB service name is mongodnetbrain; starting from v7.1, MongoDB service name is mongod.

5.Run the following commands to connect to the node:

For IEv7.x, run the mongo --host <IP or hostname of MongoDB Server:Port> -u <username> -p <password> --authenticationDatabase <database_name> command.

For IEv8.0, run the mongo --host <IP or hostname of MongoDB Server:Port> -u <username> -p <password> --authenticationDatabase <database_name> --authenticationMechanism SCRAM-SHA-256 command.

    Example:

[root@localhost upgrade_replica_set]# mongo --host 10.10.3.142:27017 -u mongodb -p mongodb --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-256
MongoDB shell version v4.0.6
connecting to: mongodb://10.10.3.142:27017/authMechanism=SCRAM-SHA-256&authSource=admin&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("0315bda2-73f3-4304-9166-c008b9b06ce3") }
MongoDB server version: 4.0.6
...
rsnetbrain:PRIMARY>

Tip: If SSL is enabled, run the following command:

- For IEv7.x, run the mongo --host <IP or hostname of MongoDB Server:Port> -u <username> -p <password> --authenticationDatabase <database_name> --ssl -sslAllowInvalidCertificates command.

- For IEv8.0, run the mongo --host <IP or hostname of MongoDB Server:Port> -u <username> -p <password> --authenticationDatabase <database_name> --ssl -sslAllowInvalidCertificates --authenticationMechanism SCRAM-SHA-256 command.