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

后端 未结 14 910
深忆病人
深忆病人 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:30

    The following steps worked for me on MongoDB 3.2:

    1. Check of course if your admin username and pw are correct. You can do this with the mongo shell:

    mongo

    use admin db.auth("admin", "yourpassword")

    If this returns 1, the password is correct.

    1. Then add the role "backup" to your admin (or make sure this role is already added). db.grantRolesToUser("admin", [{ role: "backup", db: "admin" }])

    2. Finally, the mongodump command. It did not work for me when I tried to pass the password as an argument. Instead do this:

    mongodump --username admin --authenticationDatabase admin --db yourmongodatabase

    Then add your password when it promts for it.

    This works for me...

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

    If you are using mLab then it could be the version in your local mongo is not match with mLab. By default, Ubuntu will install mongo v2.x and mLab is v3.x. You could check with this command:

    mongo --version
    

    Install new mongo version:

    1. Remove your old local mongo (be careful, it may remove all your local database)
    sudo apt remove mongo-clients mongodb
    
    1. Import the public key used by the package management system.
    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv D68FA50FEA312927
    
    1. Create a list file for MongoDB.

      • Ubuntu 14.04
    echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
    
    • Ubuntu 16.04
    echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
    
    1. Install the MongoDB packages
    sudo apt-get install -y mongodb-org
    

    Ref: https://docs.mongodb.com/v3.2/tutorial/install-mongodb-on-ubuntu/

    Now you can dump your database with this command:

    mongodump -h <host>:<port> -d <database-name> -u <user> -p <password> -o <output directory>
    
    0 讨论(0)
  • 2020-12-29 18:34

    work with this:

    --authenticationDatabase admin
    

    mongodump and mongorestore commands need the name of database where mongodb user's credentials are stored. (thanks @Zubair Alam)

    0 讨论(0)
  • 2020-12-29 18:34
    mongodump --collection coll_name --db DBname  -u UName -p *** 
              --authenticationDatabase <admin/privileged> --host ip  
              --port portNo  --out foldName
    
    0 讨论(0)
  • 2020-12-29 18:35

    This should work.

    mongodump -h SERVER_NAME:PORT -d DATABASE_NAME -u DATABASE_USER -p PASSWORD
    

    Also this error can popup if username or password are wrong.

    0 讨论(0)
  • 2020-12-29 18:37
    mongodump --host <host-ip> --port 27017 --db <database>  --authenticationDatabase admin --username <username> --password <password> --out ./Documents/
    

    After all the trail, I found above working command to dump from mongdb.

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