A replica set instance has only one copy of data, while each shard of a sharding cluster has one copy of data. Please restore your data according to your business needs. This document describes how to restore a single copy of data.
cp -r * /data/27017/
./mongod --dbpath /data/27017 --port 27017 --logpath /var/log/mongodb/27017.log --fork
As a physical backup retains the configuration of the original instance by default, the original configuration needs to be removed first; otherwise, the data may become inaccessible.
./mongod --replSet mymongo --dbpath /data/27017 --port 27017 --logpath /var/log/mongodb/27017.log --fork
rs.slaveOk()
use local
db.system.replset.remove({})
rs.initiate({"_id":"mymongo","members":[{"_id":0,"host":"127.0.0.1:27017"},{"_id":1, "host":"127.0.0.1:27018"},{"_id":2, "host":"127.0.0.1:27019"}]})
For more information on the rs.initiate()
command, see MongoDB Manual.Data cannot be restored to a sharding cluster. As the route of physical backup is missing in a sharding cluster, mongos can only read the data of the master shard even if the data of each shard is restored to the self-built replica set (each shard of the sharding cluster).
config
directory manually and then run the mongorestore
command to restore the data of each shard as shown below: c_10
table is in the ycsb
directory in the database and contains data files from c_10.bson.gz.chunk-64
to c_10.bson.gz.chunk-127
. The merge command is cat c_10.bson.gz.chunk-* > ./c_10.bson.gz
.Note:
In some use cases, TencentDB for MongoDB v3.2 may have chunks.
Run the mongorestore
command to restore the data, where the -h
parameter specifies the self-built database address, --dir
specifies the directory of the data file, and --gzip
must be specified to decompress the backup file. The command is as follows:
./mongorestore --gzip --drop -h127.0.0.1:27017 --dir ./1544517027220146694
Was this page helpful?