Before upgrading NetworkBrain Integrated Edition, it is highly recommended to back up all MongoDB data in case of any data loss or corruption during the upgrade process. The backup data will be used to restore data after MongoDB is reinstalled. See Restoring MongoDB Data for more details.

In case that you don’t want to stop the service of MongoDB or the volume of the MongoDB data is small, see Dumping MongoDB Data for another way to back up the data, and see Restoring Dumped MongoDB Data to restore the data.

The following section introduces how to use the cp command to copy underlying MongoDB data files directly for backup.

Notes:

– Make sure you have stopped all relevant services before backing up data.

– The backup data can only be used to restore the database on the same server. If you have set up a MongoDB replica set for high availability, repeat the steps below on each MongoDB node except for the arbiter node.

1.Log in to the Linux server where the MongoDB node is installed as the root user.

2.Ensure the service of MongoDB is stopped. If not, stop the 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.Run the following command to create a directory under the /etc directory to save the backup data.

Note: Ensure the backup directory (/etc/mongodb_databk in this example) has sufficient space to store the backup data.

[root@localhost ~]# mkdir /etc/mongodb_databk

4.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.

5.Run the du -hs data command under the /usr/lib/mongodb directory to check the total size of MongoDB backup data.

6.Run the cp -a data /etc/mongodb_databk command under the /usr/lib/mongodb directory to copy all MongoDB data files from the data directory to the /etc/mongodb_databk directory.

[root@localhost mongodb]# cp -a data /etc/mongodb_databk

7.Run the cd /etc/mongodb_databk command to navigate to the /etc/mongodb_databk directory.

8.Run the ls -al command under the /etc/mongodb_databk directory to browse the backup data.

[root@localhost mongodb_databk]# ls -al
total 136
drwxr-xr-x.  3 root root         18 Jun 6 22:49 .
drwxr-xr-x.  6 root root         79 Jun 6 22:48 ..
drwxr-xr-x.  4 netbrain netbrain 106496 Jun 6 22:49 data

9.Run the service <mongodb service name> start command to start 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.