1
要查看MongoDB是否正在备份,可以使用以下命令:
- 查看MongoDB的进程列表
ps -ef | grep mongo
该命令将列出所有正在运行的MongoDB进程。
- 查看MongoDB的日志文件
tail -f /var/log/mongodb/mongod.log
该命令将打印MongoDB的日志,你可以在日志中查看备份相关的信息。
如果正在进行备份,你可能会看到类似以下消息:
[initandlisten] Invariant failure: !inShutdown() src/mongo/db/operation_context.cpp 415
这意味着MongoDB正在执行备份操作。请注意,备份操作可能需要一些时间,具体时间取决于你的数据量和硬件配置。
2
要查看Mongo是否正在备份,可以使用以下命令:
-
打开Mongo shell:
mongo
-
进入admin数据库:
use admin
-
运行命令:
db.currentOp()
,该命令将返回当前正在执行的操作列表。 -
查找op字段值为“backup”的操作。如果有正在进行的备份操作,则会在列表中显示。
例如,如果有一个正在进行的备份操作,其op字段值为“backup”,它将显示如下所示:
{
"opid" : 12345,
"active" : true,
"secs_running" : 3600,
"op" : "backup",
"ns" : "",
"query" : { },
"msg" : "backup is in progress",
"numYields" : 0,
"locks" : { },
"waitingForLock" : false,
"lockStats" : { }
}
如果没有任何备份操作正在进行,则不会显示任何内容。
测试环境
mongo-28605872-replica0:PRIMARY> db.currentOp();
{
"inprog" : [
{
"type" : "op",
"host" : "mongo-28605872-replica0-0-0:27017",
"desc" : "monitoring-keys-for-HMAC",
"active" : true,
"currentOpTime" : "2023-04-21T17:56:34.458+0800",
"opid" : 19376814,
"op" : "none",
"ns" : "",
"command" : {
},
"numYields" : 0,
"waitingForLatch" : {
"timestamp" : ISODate("2023-04-21T03:21:18.440Z"),
"captureName" : "PeriodicRunner::_mutex"
},
"locks" : {
},
"waitingForLock" : false,
"lockStats" : {
},
"waitingForFlowControl" : false,
"flowControlStats" : {
}
},
{
"type" : "op",
"host" : "mongo-28605872-replica0-0-0:27017",
"desc" : "rsSync-0",
"active" : true,
"currentOpTime" : "2023-04-21T17:56:34.458+0800",
"effectiveUsers" : [
{
"user" : "__system",
"db" : "local"
}
],
"opid" : 19633341,
"op" : "none",
"ns" : "",
"command" : {
},
"numYields" : 0,
"locks" : {
},
"waitingForLock" : false,
"lockStats" : {
"ParallelBatchWriterMode" : {
"acquireCount" : {
"r" : NumberLong(1)
}
},
"ReplicationStateTransition" : {
"acquireCount" : {
"w" : NumberLong(1)
}
},
"Global" : {
"acquireCount" : {
"r" : NumberLong(1)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(1)
}
},
"Collection" : {
"acquireCount" : {
"r" : NumberLong(1)
}
},
"Mutex" : {
"acquireCount" : {
"r" : NumberLong(1)
}
}
},
"waitingForFlowControl" : false,
"flowControlStats" : {
}
},
{
"type" : "op",
"host" : "mongo-28605872-replica0-0-0:27017",
"desc" : "WT-OplogTruncaterThread-local.oplog.rs",
"active" : true,
"currentOpTime" : "2023-04-21T17:56:34.458+0800",
"opid" : 28,
"op" : "none",
"ns" : "",
"command" : {
},
"numYields" : 0,
"locks" : {
},
"waitingForLock" : false,
"lockStats" : {
"ReplicationStateTransition" : {
"acquireCount" : {
"w" : NumberLong(2)
}
},
"Global" : {
"acquireCount" : {
"w" : NumberLong(2)
}
},
"Database" : {
"acquireCount" : {
"w" : NumberLong(1)
}
}
},
"waitingForFlowControl" : false,
"flowControlStats" : {
"acquireCount" : NumberLong(1),
"timeAcquiringMicros" : NumberLong(1)
}
},
{
"type" : "op",
"host" : "mongo-28605872-replica0-0-0:27017",
"desc" : "conn381074",
"connectionId" : 381074,
"client" : "127.0.0.1:42660",
"appName" : "MongoDB Shell",
"clientMetadata" : {
"application" : {
"name" : "MongoDB Shell"
},
"driver" : {
"name" : "MongoDB Internal Client",
"version" : "4.2.19"
},
"os" : {
"type" : "Linux",
"name" : "Ubuntu",
"architecture" : "x86_64",
"version" : "18.04"
}
},
"active" : true,
"currentOpTime" : "2023-04-21T17:56:34.458+0800",
"effectiveUsers" : [
{
"user" : "root",
"db" : "admin"
}
],
"opid" : 19633359,
"lsid" : {
"id" : UUID("26a3682b-719c-4db2-a7ec-47abcc74b479"),
"uid" : BinData(0,"Y5mrDaxi8gv8RmdTsQ+1j7fmkr7JUsabhNmXAheU0fg=")
},
"secs_running" : NumberLong(0),
"microsecs_running" : NumberLong(180),
"op" : "command",
"ns" : "admin.$cmd.aggregate",
"command" : {
"currentOp" : 1,
"lsid" : {
"id" : UUID("26a3682b-719c-4db2-a7ec-47abcc74b479")
},
"$clusterTime" : {
"clusterTime" : Timestamp(1682070988, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"$db" : "admin"
},
"numYields" : 0,
"locks" : {
},
"waitingForLock" : false,
"lockStats" : {
},
"waitingForFlowControl" : false,
"flowControlStats" : {
}
},
{
"type" : "op",
"host" : "mongo-28605872-replica0-0-0:27017",
"desc" : "waitForMajority",
"active" : true,
"currentOpTime" : "2023-04-21T17:56:34.458+0800",
"opid" : 2,
"op" : "none",
"ns" : "",
"command" : {
},
"numYields" : 0,
"waitingForLatch" : {
"timestamp" : ISODate("2023-03-28T08:17:30.579Z"),
"captureName" : "WaitForMaorityService::_mutex"
},
"locks" : {
},
"waitingForLock" : false,
"lockStats" : {
},
"waitingForFlowControl" : false,
"flowControlStats" : {
}
},
{
"type" : "op",
"host" : "mongo-28605872-replica0-0-0:27017",
"desc" : "conn377298",
"connectionId" : 377298,
"client" : "245.0.77.14:44392",
"clientMetadata" : {
"driver" : {
"name" : "NetworkInterfaceTL",
"version" : "4.2.19"
},
"os" : {
"type" : "Linux",
"name" : "Ubuntu",
"architecture" : "x86_64",
"version" : "18.04"
}
},
"active" : true,
"currentOpTime" : "2023-04-21T17:56:34.458+0800",
"effectiveUsers" : [
{
"user" : "__system",
"db" : "local"
}
],
"opid" : 19633357,
"secs_running" : NumberLong(0),
"microsecs_running" : NumberLong(462571),
"op" : "getmore",
"ns" : "local.oplog.rs",
"command" : {
"getMore" : NumberLong("4045551348485042665"),
"collection" : "oplog.rs",
"batchSize" : 13981010,
"maxTimeMS" : NumberLong(5000),
"term" : NumberLong(3),
"lastKnownCommittedOpTime" : {
"ts" : Timestamp(1682070988, 1),
"t" : NumberLong(3)
},
"$replData" : 1,
"$oplogQueryData" : 1,
"$readPreference" : {
"mode" : "secondaryPreferred"
},
"$clusterTime" : {
"clusterTime" : Timestamp(1682070988, 1),
"signature" : {
"hash" : BinData(0,"jpFtjGG1t/RTanT6tPL6qUsOHkw="),
"keyId" : NumberLong("7215402756423548932")
}
},
"$db" : "local"
},
"planSummary" : "COLLSCAN",
"cursor" : {
"cursorId" : NumberLong("4045551348485042665"),
"createdDate" : ISODate("2023-04-21T04:29:43.465Z"),
"lastAccessDate" : ISODate("2023-04-21T09:56:33.995Z"),
"nDocsReturned" : NumberLong(2032),
"nBatchesReturned" : NumberLong(6183),
"noCursorTimeout" : false,
"tailable" : true,
"awaitData" : true,
"originatingCommand" : {
"find" : "oplog.rs",
"filter" : {
"ts" : {
"$gte" : Timestamp(1682051338, 1)
}
},
"tailable" : true,
"oplogReplay" : true,
"awaitData" : true,
"maxTimeMS" : NumberLong(60000),
"batchSize" : 13981010,
"term" : NumberLong(3),
"readConcern" : {
"afterClusterTime" : Timestamp(0, 1)
},
"$replData" : 1,
"$oplogQueryData" : 1,
"$readPreference" : {
"mode" : "secondaryPreferred"
},
"$clusterTime" : {
"clusterTime" : Timestamp(1682051378, 1),
"signature" : {
"hash" : BinData(0,"KUALMdxn5L3D6MD28siJ4uaqHPQ="),
"keyId" : NumberLong("7215402756423548932")
}
},
"$db" : "local"
},
"operationUsingCursorId" : NumberLong(19633357)
},
"numYields" : 2,
"locks" : {
},
"waitingForLock" : false,
"lockStats" : {
"ReplicationStateTransition" : {
"acquireCount" : {
"w" : NumberLong(2)
}
},
"Global" : {
"acquireCount" : {
"r" : NumberLong(2)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(2)
}
},
"Mutex" : {
"acquireCount" : {
"r" : NumberLong(1)
}
},
"oplog" : {
"acquireCount" : {
"r" : NumberLong(2)
}
}
},
"waitingForFlowControl" : false,
"flowControlStats" : {
}
},
{
"type" : "op",
"host" : "mongo-28605872-replica0-0-0:27017",
"desc" : "NoopWriter",
"active" : true,
"currentOpTime" : "2023-04-21T17:56:34.458+0800",
"opid" : 19633297,
"op" : "none",
"ns" : "",
"command" : {
},
"numYields" : 0,
"locks" : {
},
"waitingForLock" : false,
"lockStats" : {
},
"waitingForFlowControl" : false,
"flowControlStats" : {
}
},
{
"type" : "op",
"host" : "mongo-28605872-replica0-0-0:27017",
"desc" : "ReplBatcher",
"active" : true,
"currentOpTime" : "2023-04-21T17:56:34.458+0800",
"opid" : 19633340,
"op" : "none",
"ns" : "",
"command" : {
},
"numYields" : 0,
"locks" : {
},
"waitingForLock" : false,
"lockStats" : {
},
"waitingForFlowControl" : false,
"flowControlStats" : {
}
},
{
"type" : "op",
"host" : "mongo-28605872-replica0-0-0:27017",
"desc" : "conn376497",
"connectionId" : 376497,
"client" : "245.0.76.56:50412",
"clientMetadata" : {
"driver" : {
"name" : "NetworkInterfaceTL",
"version" : "4.2.19"
},
"os" : {
"type" : "Linux",
"name" : "Ubuntu",
"architecture" : "x86_64",
"version" : "18.04"
}
},
"active" : true,
"currentOpTime" : "2023-04-21T17:56:34.458+0800",
"effectiveUsers" : [
{
"user" : "__system",
"db" : "local"
}
],
"opid" : 19633356,
"secs_running" : NumberLong(0),
"microsecs_running" : NumberLong(462606),
"op" : "getmore",
"ns" : "local.oplog.rs",
"command" : {
"getMore" : NumberLong("2545129586868375853"),
"collection" : "oplog.rs",
"batchSize" : 13981010,
"maxTimeMS" : NumberLong(5000),
"term" : NumberLong(3),
"lastKnownCommittedOpTime" : {
"ts" : Timestamp(1682070988, 1),
"t" : NumberLong(3)
},
"$replData" : 1,
"$oplogQueryData" : 1,
"$readPreference" : {
"mode" : "secondaryPreferred"
},
"$clusterTime" : {
"clusterTime" : Timestamp(1682070988, 1),
"signature" : {
"hash" : BinData(0,"jpFtjGG1t/RTanT6tPL6qUsOHkw="),
"keyId" : NumberLong("7215402756423548932")
}
},
"$db" : "local"
},
"planSummary" : "COLLSCAN",
"cursor" : {
"cursorId" : NumberLong("2545129586868375853"),
"createdDate" : ISODate("2023-04-21T03:21:21.157Z"),
"lastAccessDate" : ISODate("2023-04-21T09:56:33.995Z"),
"nDocsReturned" : NumberLong(2450),
"nBatchesReturned" : NumberLong(7465),
"noCursorTimeout" : false,
"tailable" : true,
"awaitData" : true,
"originatingCommand" : {
"find" : "oplog.rs",
"filter" : {
"ts" : {
"$gte" : Timestamp(1682047271, 1)
}
},
"tailable" : true,
"oplogReplay" : true,
"awaitData" : true,
"maxTimeMS" : NumberLong(60000),
"batchSize" : 13981010,
"term" : NumberLong(3),
"readConcern" : {
"afterClusterTime" : Timestamp(0, 1)
},
"$replData" : 1,
"$oplogQueryData" : 1,
"$readPreference" : {
"mode" : "secondaryPreferred"
},
"$clusterTime" : {
"clusterTime" : Timestamp(1682047278, 2),
"signature" : {
"hash" : BinData(0,"JREfKtYKOrFmD3UGRzSF3YrY0oE="),
"keyId" : NumberLong("7215402756423548932")
}
},
"$db" : "local"
},
"operationUsingCursorId" : NumberLong(19633356)
},
"numYields" : 2,
"locks" : {
},
"waitingForLock" : false,
"lockStats" : {
"ReplicationStateTransition" : {
"acquireCount" : {
"w" : NumberLong(2)
}
},
"Global" : {
"acquireCount" : {
"r" : NumberLong(2)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(2)
}
},
"Mutex" : {
"acquireCount" : {
"r" : NumberLong(1)
}
},
"oplog" : {
"acquireCount" : {
"r" : NumberLong(2)
}
}
},
"waitingForFlowControl" : false,
"flowControlStats" : {
}
}
],
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1682070988, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1682070988, 1)
}