This topic describes how to restore the data of an ApsaraDB for MongoDB instance to user-created MongoDB databases by using logical backup. Data restoration uses the mongorestore command. You must have created a logical backup and downloaded the logical backup file to the server where you plan to run the mongorestore command.

Prerequisites

  • A replica set instance (three- or more-node) is used.
  • The ApsaraDB for MongoDB instance and the user-created MongoDB databases run the same database version.

Background information

Full logical backup uses the mongodump command to back up a database. During the backup process, you can still perform read/write operations on the database.

Note Full logical backup runs on the hidden node of the ApsaraDB for MongoDB instance. This does not affect the read/write performance of the primary and secondary nodes. Backing up a large volume of data may take a long time.

Procedure

  1. Log on to the ApsaraDB for MongoDB console.
  2. In the upper-left corner of the page, select the region where the source instance resides.
  3. In the left-side navigation pane, click Replica Set Instances.
  4. Find the source instance and click its ID.
  5. In the upper-right corner of the page, click Backup Instance.
    Back up an instance
  6. In the Backup Instance dialog box that appears, select the Logical Backup method.
  7. Click OK. Then, wait until the backup is complete.
  8. On the Backup and Recovery page, find the target logical backup file and choose More icon > Download in the Operation column.
  9. Copy the downloaded file to the server where you plan to run the mongorestore command.
  10. Run the following command to import the file to user-created MongoDB databases:
    mongorestore -h <hostname> --port <server port> -u <username> -p <password> --drop --gzip --archive=<backupfile> -vvvv --stopOnError

    Parameter description:

    • <hostname>: the address of the server where the user-created MongoDB databases reside. If you also run the mongorestore command on this server, enter 127.0.0.1.
    • <server port>: the port number of the user-created MongoDB databases.
    • <username>: the username you use to log on to the user-created MongoDB databases.
    • <password>: the password of the preceding account.
    • <backupfile>: the name of the logical backup file you downloaded.

    Example:

    mongorestore -h 127.0.0.1 --port 27017 -u root -p xxxxxxxx --drop --gzip --archive=hins1111_data_20190710.ar -vvvv --stopOnError