Can't create backup mongodump with --db. Authentication failed

后端 未结 14 912
深忆病人
深忆病人 2020-12-29 18:22

When I create backup of all databases in MongoDB (version 3):

mongodump --username bacUser --password 12345

It\'s OK. But when I try to cre

相关标签:
14条回答
  • 2020-12-29 18:39

    If you still get same error with --authenticationDatabase admin , than probably your username and password are incorrect. Try adding a user db.createUser() , with appropriate role ( i gave write permission as well)

    than run below command : (ignore -h if you are running on local)

     mongodump -h <ip>:<port_number> -d db_name -u newUser -p newPassword -o /home/mongodump/
    

    Hope this helps...

    0 讨论(0)
  • 2020-12-29 18:42

    Use signle Quotation around password. if you are using any special character in your password. That will solve your issue. Use following command.

    mongodump -d database_name -u userName -p 'password' --out directory_name

    0 讨论(0)
  • 2020-12-29 18:45
    mongodump   --authenticationDatabase admin -uroot -pyourpassword
    

    here root is username and yourpassword is your password.

    This command will backup/dump all database back-up in current directory.

    0 讨论(0)
  • 2020-12-29 18:46

    userAdminAnyDatabase is not enough to do mongodump on all the dbs that's why you are getting this error. You will need a super user that has:

    userAdminAnyDatabase
    readWriteAnyDatabase
    clusterAdmin
    

    privileges to run mongodump on all dbs.

    OR you just need 'backup' privilege

    db.grantRolesToUser('username', [{
      role: 'backup',
      db: 'name of ur authentication db'
    }])
    
    0 讨论(0)
  • 2020-12-29 18:50

    for dump and restore

    mongodump --db nameDatabase --username userName --password password --authenticationDatabase admin --out mongodb\
    mongorestore --db nameDatabase --username userName --password password --authenticationDatabase admin <path backup> --drop
    
    0 讨论(0)
  • 2020-12-29 18:52

    In my case, mongodump was not correctly processing the password. The solution was to escape the password literal.

    This did not work:

    mongodump -p my$password -o <output directory>

    This did work:

    mongodump -p 'my$password' -o <output directory>

    0 讨论(0)
提交回复
热议问题