百度智能云

All Product Document

          Cloud Database MONGODB

          Best Practices for MongoDB Backup and Recovery

          Database Backups and Restoration

          Recommend you to use the mongodump for database backup and the mongorestore for restoring the backup state of the database at a certain time. Thus, it is possible to avoid the data security threat caused by the misoperation in the creation and deletion process of the DocDB for MongoDB. This backup is an off-line backup. In the backup and restoration process, the database stops providing read/write services. So, recommend you to operate at a lower peak of the business.

          • Backup command

              #mongodump --host <hostname> --port <port> --authenticationDatabase <admin>
              -u <user> -p <passwd> -o <dst_dir>
          • Restoration command

              #mongorestore --host <hostname> --port <port> --authenticationDatabase <admin> 
              -u <user> -p <passwd>  <dst_dir>

          In the command above, the parameters are as follows::

          Parameter Description
          --host Means the CVM Server to which the service connects
          --port Port number is 27017 in general
          -- authenticationDatabase User authorization to operate the database
          -u The user name that connects to the DocDB for MongoDB service
          -p The password that connects to the DocDB for MongoDB service
          -o Target path for data backup/restoration without the “-o” parameter

          Practical Operation

          Create a DocDB for MongoDB Instance

          Create a DocDB for MongoDB instance with a replica set architecture in the availability zone B. For the creation process, see the Enable Service .

          image.png

          Enter the instance and view the connection information.

          image.png

          Create/log in to the BCC Instance

          Create a BCC in the availability zone B under the same VPC as the DocDB for MongoDB instance, and log in to the public network IP of the BCC remotely by shell. For the process of creating a BCC, see Create BCC Instance.

          Connect to the DocDB for MongoDB service remotely from the BCC machine. For the connection method, see Connection Instance.

          image.png

          Create a db/collection

          Using the DocDB for MongoDB service to remotely create the databases mydb and youdb, and create the common collection mycollection and capped type collection capcollection under mydb, and write the document data in the collection respectively. The results after operation are as follows:

          image.png

          Backups/Restore All Database

          It can directly back up all the database with one key and directly restore the database. The corresponding operation is as follows:

          image.png

          image.png

          Backups/Restore Single Database

          You can select a database in the service for backup and restore operations. Operations are as follows:

          image.png

          image.png

          Backups/Restore Single Collection

          Select a collection from a database in the service for backup/recovery.

          • Operations targeting at common collection are as follows:

          image.png image.png

          • Operations targeting at capped type are as follows:

          image.png image.png

          FAQs

          How To Remotely Connect to the DocDB for MongoDB Service

          For details, see FAQs.

          Remote Connection to Cloud Database DocDB for MongoDB Failed

          For details, see FAQs.

          All Mongodump Backups DB Error

          For details, see FAQs.

          Do I Need to Use Mongodump for Data Backup?

          For details, see FAQs.

          Where is the Backup File Be Saved When Using Mongodump for Data Backup?

          For details, see FAQs.

          The data is backed up by mongodump. If you want to restore the cloud database, can you directly roll back the original DocDB for MongoDB data by data backup?

          For details, see FAQs.

          Does The Process of Backup or Restoration Interrupts When Using the Mongodump For Data Backups? How to Deal with Broken? Does the Use of the Mongodump for Data Backup Affect Business?

          For details, see FAQs.

          Does the Use of Mongodump for Data Backup Affect Business?

          For details, see FAQs.

          Previous
          Best Practices for MongoDB Monitoring and Alarm
          Next
          Best Practices for MongoDB Data Migration