简体   繁体   English

如何使用mongodb进行备份

[英]How to get backup with mongodb

When I want to take a back up I confront to this command 当我想备份时,我会面对这个命令

mongodump -d databasename -u admin -p -o /home mongodump -d数据库名-u管理员-p -o / home

I encounter an error Errmsg: "auth faild",code:18}

But with this user and pass I can connect to database But while I would prefer to disconnect authentication I will Get backup 但是有了这个用户并通过,我可以连接到数据库了,但是当我想断开身份验证时,我将获得备份

Thanks 谢谢

This message indicates that mongodump couldn't authenticate against the mongod . 此消息表明mongodump无法针对mongod身份验证。 There are a few possible causes. 有几种可能的原因。 Looking at the docs we can see the following note about the -p option. 查看文档,我们可以看到有关-p选项的以下注释。

Changed in version 3.0.0: If you do not specify an argument for --password, mongodump returns an error. 在版本3.0.0中更改:如果未为--password指定参数,则mongodump将返回错误。

Changed in version 3.0.2: If you wish mongodump to prompt the user for the password, pass the --username option without --password or specify an empty string as the --password value, as in --password "" . 在版本3.0.2中更改:如果希望mongodump提示用户输入密码,请传递--username选项而不使用--password或将空字符串指定为--password值,如--password“”所示。

In the example command you provided, there is just a -p which means it is expecting a password. 在您提供的示例命令中,只有-p表示需要密码。

Additionally, the --authenticationDatabase option is missing. 此外,缺少--authenticationDatabase选项。 Looking at the docs for mongodump : 在看mongodump的文档:

Specifies the database in which the user is created. 指定在其中创建用户的数据库。 See Authentication Database. 请参阅身份验证数据库。

If you do not specify an authentication database, mongodump assumes that the database specified to export holds the user's credentials. 如果未指定身份验证数据库,则mongodump假定指定要导出的数据库包含用户的凭据。

If you do not specify an authentication database or a database to export, mongodump assumes the admin database holds the user's credentials. 如果您未指定身份验证数据库或要导出的数据库,则mongodump会假定admin数据库拥有用户的凭据。

Since the -d parameter is specified, mongodump will try to authenticate against that database. 由于指定了-d参数,因此mongodump将尝试针对该数据库进行身份验证。 It is more likely that the user exists in the admin database. 用户更有可能存在于admin数据库中。

Taking all of this into account, please try the following command: 考虑到所有这些,请尝试以下命令:

mongodump -d <databasename> -u <user> --authenticationDatabase admin -o /home

This command will prompt you for a password via stdin . 该命令将通过stdin提示您stdin密码。 If you want to specify the password on the command line, the command changes to 如果要在命令行上指定密码,命令将更改为

mongodump -d <databasename> -u <user> --authenticationDatabase admin -p <password> -o /home

Please replace <databasename> , <user> , and <password> with the appropriate values for your environment. 请使用适合您环境的值替换<databasename><user><password>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM