百度智能云

All Product Document

          Cloud Database MONGODB

          Restore Physical Backup to Self-built Database

          Users can download the physical backup data of the MongoDB database through the console. After the download is complete, the backup data can be restored to the self-built MongoDB database.

          Prerequisites

          The instance type is the replica cluster instance.

          Download and Unzip the Physical Backup File

          1. Log in to MongoDB Management Console.
          2. In the upper left corner of the page, select the region where the instance is located.
          3. In the left navigation bar, click Replica Cluster Instance List.
          4. Find the target instance, and click the instance ID to enter the instance feature page.
          5. Click Backup on the left navbar.
          6. Click Manual backup button and select the Physics backup.

          physical_backup.png

          1. After completing the above parameter configuration, click OK and wait a while to complete the backup.
          2. On the backup list page, select the target backup record and click the download option on the right. The download pop-up window is shown below:

          image.png

          1. Use the backup download link to download the physical backup file. Also, you can download the file by the wget command.
          2. Copy the downloaded MongoDB physical backup file into the /path/to/mongo/data/ directory.
          3. Unzip the physical backup file. The physical backup file is a compressed archive file with a suffix .tar.gz. You can unzip the file by the following method:
          cd /path/to/mongo/data/
          tar xzvf backup-o4epnp_20200905111735.tar.gz

          The decompression result is shown in the figure below:

          image.png

          Restore the MongoDB Physical Backup Data in a Single-node Mode

          1. Create a configuration file mongod.conf in the /path/to/mongo folder.
          2. Modify the mongod.conf configuration file to meet the configuration requirements for the single-point mode startup. The configuration file template in a single-point mode is as follows:
          systemLog:
             destination: file
             path: /path/to/mongo/mongod.log
             logAppend: true
          security:
             authorization: enabled
          storage:
             dbPath: /path/to/mongo/data
             directoryPerDB: true
          net:
             port: 27017
          processManagement:
             fork: true
             pidFilePath: /path/to/mongo/mongod.pid
          1. Specify the new configuration file mongod.conf to start MongoDB.
          /usr/bin/mongod -f /path/to/mongo/mongod.conf
          1. After the startup is complete, you can log in to the MongoDB database through the server's mongo shell.
          mongo --host 127.0.0.1 -u <username> -p <password> --authenticationDatabase admin

          Descriptions:

          • username: The database account of the MongoDB instance, which is root by default.
          • password: The password corresponding to this database account.

          Start the MongoDB Database in a Replica Cluster Mode

          The physical backup of the cloud database MongoDB comes with the replica cluster configuration of the original instance by default, which cannot be directly started in the replica cluster mode. During the startup, you need to start in the replica cluster mode after the initiation of the data restoration in a single-node mode. The startup steps are as follows:

          1. Log in to the MongoDB database via the server's mongo shell.
          2. Remove the original replica cluster configuration:
          ?use local
          db.system.replset.remove({})
          1. Disable the MongoDB service:
          use admin
          db.shutdownServer()
          1. Modify the configuration file mongod.conf in the /path/to/mongo/ directory, and then add the replication-related configurations. For the details about the use of the command, refer to the MongoDB’s official documentation to deploy Replica Cluster.
          2. Specify the new configuration file mongod.conf to start MongoDB.
            /usr/bin/mongod -f /path/to/mongo/mongod.conf
          3. Add members to the replica cluster and initialize the replica cluster.

          Description This step is to use the rs.initiate() command for operation. For details about the use of the command, refer to the MongoDB’s official documentation Introduction of rs.initiate() Command Introductions.

          Previous
          Restore Logic Backup to Selt-built Database
          Next
          Data Security