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
- Log on to the ApsaraDB for MongoDB console.
- In the upper-left corner of the page, select the resource group and region to which
the instance belongs.
- In the left-side navigation pane, click Replica set instances.
- On the page that appears, find the instance that you want to manage and click its
ID.
- Back up a database.
- In the upper-right corner of the page, click Back up Instance.
- In the Back up Instance panel, set Backup Method to Logical Backup.
- Click OK. Then, wait for the backup to complete.
- Download the backup file. For more information about the download method, see Download a backup file.
- Copy the downloaded backup file to the client where the self-managed MongoDB database
resides. The client is equipped with the mongorestore program.
- 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