问题说明

内置的 bakcup role,没有权限执行{ count: "system.profile", query: {} },导致备份失败。

这个 bug 在下面版本中已经修复:3.0.9, 3.2.1, 3.3.0

备份用户创建

db.createUser(
   {
     user: "backupUser",
     pwd: "111",
     roles: [ {role:"backup",db:"admin"} ]
   }
)

问题描述

这是一个 BUG:https://jira.mongodb.org/browse/SERVER-21724

If you have a database with a system.profile collection and try to back it up with mongodump authenticated as a user with the backup role you get:

Failed: error counting test.system.profile: not authorized on test to execute command { count: "system.profile", query: {} }

Either we should give the backup role the ability to back up system.profile collections, or we should modify mongodump to not attempt to back up those collections.

修复方案

创建一个修复的 Role:

db.createRole({
  role: "backup_fix",
  privileges: [
     { resource: { db: "", collection: "system.profile" }, actions: [ "find"] },
  ],
  roles: [
  ]
})

然后将这个 Role 赋予给 backup 用户:

db.grantRolesToUser("YOUR_BACKUP_USER", [{"role": "backup_fix", "db": "admin"}]);