The mongorestore program is a data restoration tool that comes with MongoDB databases. You can restore data of an ApsaraDB for MongoDB replica set instance to a self-managed MongoDB database by using logical backup.

Prerequisites

  • The instance is a replica set instance that runs MongoDB 4.2 or earlier.
  • The version of the self-managed MongoDB database is the same as the database version of the ApsaraDB for MongoDB replica set instance. This ensures compatibility.

Preparations

Download a version of MongoDB that is the same as the database version of the ApsaraDB for MongoDB instance and install the MongoDB version on the client where the self-managed MongoDB database resides. The client can be an on-premise server or an Elastic Compute Service (ECS) instance. For more information about the installation method, see Install MongoDB.

Procedure

  1. Log on to the ApsaraDB for MongoDB console.
  2. In the upper-left corner of the page, select the resource group and the region of the target instance.
  3. In the left-side navigation pane, click Replica Set Instances.
  4. Find the target instance and click its ID.
  5. Back up a database.
    1. In the upper-right corner of the page, click Back up Instance.
    2. In the Back up Instance panel, set Backup Method to Logical Backup.
    3. Click OK. Then, wait for the backup to complete.
  6. Download the backup file. For more information about the download method, see Download the physical backup data of a replica set instance.
  7. Copy the downloaded backup file to the client where the self-managed MongoDB database resides. The client is equipped with the mongorestore program.
  8. Run the following command to import the backup data into the self-managed MongoDB database:
    mongorestore -h <hostname> --port <server port> -u <username> -p <password> --drop --gzip --archive=<backupfile> -vvvv --stopOnError
    Note
    • <hostname>: the address of the server where the self-managed MongoDB database resides. In this case, enter 127.0.0.1.
    • <server port>: the port used to connect to the self-managed MongoDB database.
    • <username>: the account used to log on to the self-managed MongoDB database.
    • <password>: the account password used to log on to the self-managed MongoDB database.
    • <backupfile>: the name of the downloaded logical backup file.

    Example:

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