我在docker容器中有一个MongoDB实例,以运行一些本地服务,并使用mongodump
执行备份。最近,由于MongoDB不再认为它是主数据库,因此此备份过程以及运行在顶部的应用程序已中断。我需要(最新的)备份内容才能将服务迁移到新服务器。如何使MongoDB转储其数据库内容以便重新部署实例?
这是我运行以执行备份的命令和错误消息:
mongodump --host "db" --port 27017 --db rocketchat
2019-05-17T11:28:59.950+0000 Failed: error counting rocketchat.rocketchat_apps_persistence: node is not in primary or recovering state
我尝试运行mongodump命令的一些变体,包括将服务器视为辅助实例:
mongodump --host "db" --port 27017 --readPreference secondaryPreferred
2019-05-17T11:16:23.066+0000 Failed: error counting admin.system.version: node is not in primary or recovering state
当我尝试为服务器初始化副本集时,它已经认为它已初始化。
rs0:OTHER> rs.initiate()
{
"info2" : "no configuration specified. Using a default configuration for the set",
"me" : "1d70c5ced11b:27017",
"info" : "try querying local.system.replset to see current configuration",
"ok" : 0,
"errmsg" : "already initialized",
"code" : 23,
"codeName" : "AlreadyInitialized",
"operationTime" : Timestamp(1558063935, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1558063935, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
不幸的是,同步包含WiredTiger数据的docker卷的内容也不起作用。我最终遇到了同样的问题,数据库错误地认为它不是主数据库。可悲的是,这也意味着某些低级备份(在mongodump备份之上)也无法正常工作。
设置:
编辑:
rs.status()和rs.config()的结果
rs0:OTHER> rs.status()
{
"operationTime" : Timestamp(1558063935, 1),
"ok" : 0,
"errmsg" : "Our replica set config is invalid or we are not a member of it",
"code" : 93,
"codeName" : "InvalidReplicaSetConfig",
"$clusterTime" : {
"clusterTime" : Timestamp(1558063935, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
rs0:OTHER> rs.config()
{
"_id" : "rs0",
"version" : 1,
"protocolVersion" : NumberLong(1),
"writeConcernMajorityJournalDefault" : true,
"members" : [
{
"_id" : 0,
"host" : "8d6d6fda7542:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : -1,
"catchUpTakeoverDelayMillis" : 30000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5ccfbd9f66a45fbddfa5c0f0")
}
}