能够备份mongo数据库所需的内容

  • 本文关键字:数据库 备份 mongo mongodb
  • 更新时间 :
  • 英文 :


我正在尝试备份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上,认证数据库默认为您连接的数据库。查看试图保存到mongodb时验证失败

最新更新