Restoring Replica Set Instance to a Local Self-Built Database
Scenarios
This section uses the Linux operating system as an example to describe how to restore the downloaded backup files of a replica set instance to your self-built databases. To download backup files, see Downloading Backup Files.
This method applies only to replica set instances.
Prerequisites
The client tool of version 3.4 has been installed on your local self-built MongoDB database.
Procedure
- Log in to the server on which self-built 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 indicates the IP address bound to the database.
- DB_USER indicates the username of the database account. The default value is rwuser.
- PASSWORD indicates the password of the database account, 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.
Last Article: Restoring Replica Set Database and Table to a Point in Time
Next Article: Restoring a Single Node Instance from a Backup
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.