Restoring a Replica Set Backup to an On-Premises Database
To restore a DB instance backup file to an on-premises database, you can only use databases on Linux.
This section uses the Linux operating system as an example to describe how to restore the downloaded backup file of a replica set instance to your on-premises databases. For details about how to download backup files, see Downloading Backup Files.
Precautions
- MongoDB client 3.4 has been installed on your on-premises MongoDB database.
- Only DDS 3.4 and 4.0 instances can be restored in this method. DDS 4.2 does not support this method.
Procedure
- Log in to the server on which the on-premises databases are deployed.
Assume that /path/to/mongo is the directory for restoration, and /path/to/mongo/data is the directory for storing the backup file.
- Before the restoration, ensure that the /path/to/mongo/data directory is empty.
cd /path/to/mongo/data/
rm -rf *
- Copy and paste the downloaded backup file package to /path/to/mongo/data/ and decompress it.
lz4 -d xxx_.tar.gz |tar -xC /path/to/mongo/data/
- Create the mongod.conf configuration file in /path/to/mongo.
touch mongod.conf
- Start the database in single-node mode.
- Modify the mongod.conf file to meet the backup startup configuration requirements.
The following is a configuration template for backup startup:
systemLog: destination: file path: /path/to/mongo/mongod.log logAppend: true security: authorization: enabled storage: dbPath: /path/to/mongo/data directoryPerDB: true engine: wiredTiger wiredTiger: collectionConfig: {blockCompressor: snappy} engineConfig: {directoryForIndexes: true, journalCompressor: snappy} indexConfig: {prefixCompression: true} net: http: enabled: false port: 27017 bindIp: xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx unixDomainSocket: enabled: false processManagement: fork: true pidFilePath: /path/to/mongo/mongod.pid
bindIp indicates the IP address bound to the database. This field is optional. If it is not specified, your local IP address is bound by default.
- Run the mongod.conf command to start the database.
/usr/bin/mongod -f /path/to/mongo/mongod.conf
/usr/bin/ is the directory that stores the mongod file of the installed MongoDB client.
- After the database is started, log in to the database using mongo shell to verify the restoration result.
mongo --host <DB_HOST> -u <DB_USER> -p <PASSWORD> --authenticationDatabase admin
- DB_HOST is the IP address bound to the database.
- DB_USER is the database user. The default value is rwuser.
- PASSWORD is the password for the database user, which is the password used for backing up the DB instance.
- Modify the mongod.conf file to meet the backup startup configuration requirements.
Starting the Database in Replica Set Mode
By default, the physical backup of the DDS DB instance contains the replica set configuration of the original DB instance. You need to start the database in single-node mode. Otherwise, the database cannot be accessed.
If you want to start the database in replica set mode, perform step 5 and then perform the following steps:
- Log in to the database using mongo shell.
- Remove the original replica set configuration.
use local
db.system.replset.remove({})
- Stop the database process.
use admin
db.shutdownServer()
- Add the replication configuration in the mongod.conf file in the /path/to/mongo/ directory. For details about the command usage, see Deploy a Replica Set.
- Run the mongod.conf command to start the database.
/usr/bin/mongod -f /path/to/mongo/mongod.conf
/usr/bin/ is the directory that stores the mongod file of the installed MongoDB client.
- Add the replica set members and initialize the replica set.
Use the rs.initiate() command to perform the preceding step. For details, see rs.initiate().
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.