需要什么才能备份 mongo 数据库

What is needed to be able to make a backup of mongo database

我正在尝试备份 mongo 数据库,但我一直收到身份验证错误。 我给了我的用户所有权限,但我仍然无法进行备份:

# mongosh --host 10.1.10.1 --port 27017 -u administrator admin --quiet --eval "db.getUsers();"
Enter password: ************************************
{
  users: [
    {
      _id: 'admin.administrator',
      userId: UUID("52befffa-7fa9-4ab9-9325-3dfdead28f20"),
      user: 'administrator',
      db: 'admin',
      roles: [
        { role: 'userAdminAnyDatabase', db: 'admin' },
        { role: 'restore', db: 'admin' },
        { role: 'readWriteAnyDatabase', db: 'admin' },
        { role: 'root', db: 'admin' },
        { role: 'backup', db: 'admin' }
      ],
      mechanisms: [ 'SCRAM-SHA-1', 'SCRAM-SHA-256' ]
    },
    {
      _id: 'admin.project-12',
      userId: UUID("375a91b7-8c27-4d1d-8d02-ba04faaa94ce"),
      user: 'project-12',
      db: 'admin',
      roles: [ { role: 'readWrite', db: 'project-12' } ],
      mechanisms: [ 'SCRAM-SHA-1', 'SCRAM-SHA-256' ]
    }
  ],
  ok: 1
}
# mongodump --host 10.1.10.1 --port 27017 -u administrator --archive=test-1 --db=project-12
Enter password:

2022-05-12T18:01:55.677+0200    Failed: can't create session: could not connect to server: connection() error occured during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.

我做错了什么?

您需要指定认证数据库,例如

mongodump --host 10.1.10.1 --port 27017 -u administrator --authenticationDatabase=admin ...

mongosh 上,身份验证数据库默认为您连接的数据库。参见