1. 副本集的搭建
2.物理备份文件
直接备份目录即可
/data/mongodb/rs1
3.在新的机器恢复
3.1 启动节点
/home/mongodb/mongodb/bin/mongod --replSet rs --dbpath /data/mongodb/rs1 --port 27017 --fork --logpath /data/mongodb/rs1/mongod.log --bind_ip_all
/home/mongodb/bin/mongo
3.2 查看状态
由于在新的环境ip发生的变化,会出现下面的报错
> rs.status()
{
"ok" : 0,
"errmsg" : "Our replica set config is invalid or we are not a member of it",
"code" : 93,
"codeName" : "InvalidReplicaSetConfig"
}
3.3 进行配置
rs.reconfig({_id: "rs",version: 1,members: [{ _id: 0, host : "localhost:27017" }]},{force:true})
3.4 验证元数据的正确性
> rs.reconfig({_id: "rs",version: 1,members: [{ _id: 0, host : "localhost:27017" }]},{force:true})
{ "ok" : 1 }
rs:SECONDARY> rs.status()
{
"set" : "rs",
"date" : ISODate("2023-01-06T08:19:59.590Z"),
"myState" : 1,
"term" : NumberLong(6),
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"majorityVoteCount" : 1,
"writeMajorityCount" : 1,
"votingMembersCount" : 1,
"writableVotingMembersCount" : 1,
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1672993194, 2),
"t" : NumberLong(6)
},
"lastCommittedWallTime" : ISODate("2023-01-06T08:19:54.552Z"),
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1672993194, 2),
"t" : NumberLong(6)
},
"appliedOpTime" : {
"ts" : Timestamp(1672993194, 2),
"t" : NumberLong(6)
},
"durableOpTime" : {
"ts" : Timestamp(1672993194, 2),
"t" : NumberLong(6)
},
"lastAppliedWallTime" : ISODate("2023-01-06T08:19:54.552Z"),
"lastDurableWallTime" : ISODate("2023-01-06T08:19:54.552Z")
},
"lastStableRecoveryTimestamp" : Timestamp(1672993194, 2),
"electionCandidateMetrics" : {
"lastElectionReason" : "electionTimeout",
"lastElectionDate" : ISODate("2023-01-06T08:19:54.548Z"),
"electionTerm" : NumberLong(6),
"lastCommittedOpTimeAtElection" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"lastSeenOpTimeAtElection" : {
"ts" : Timestamp(1672992257, 1),
"t" : NumberLong(5)
},
"numVotesNeeded" : 1,
"priorityAtElection" : 1,
"electionTimeoutMillis" : NumberLong(10000),
"newTermStartDate" : ISODate("2023-01-06T08:19:54.552Z"),
"wMajorityWriteAvailabilityDate" : ISODate("2023-01-06T08:19:54.555Z")
},
"members" : [
{
"_id" : 0,
"name" : "localhost:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 485,
"optime" : {
"ts" : Timestamp(1672993194, 2),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2023-01-06T08:19:54Z"),
"lastAppliedWallTime" : ISODate("2023-01-06T08:19:54.552Z"),
"lastDurableWallTime" : ISODate("2023-01-06T08:19:54.552Z"),
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "Could not find member to sync from",
"electionTime" : Timestamp(1672993194, 1),
"electionDate" : ISODate("2023-01-06T08:19:54Z"),
"configVersion" : 112688,
"configTerm" : -1,
"self" : true,
"lastHeartbeatMessage" : ""
}
],
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1672993194, 2),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1672993194, 2)
}
rs:PRIMARY> show dbs
admin 0.000GB
config 0.000GB
db001 0.000GB
local 0.000GB