i am trying to import my database to my mongoLab database, but it keep showing the following error:
2016-10-19T21:05:49.183+0800 Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.
-bash: vd: command not found
This is how I ran my command:
mongorestore -h 243253423.mlab.com:2131242 -d meteor -u <Username> -p <Password> /Users/directory/desktop/mongo/dump
I ran across this error message and I am not sure this was your specific problem but this ended up working for me
mongorestore -d production-db \
-u myusername -p MyPassword \
--authenticationDatabase admin --host mydomain.com \
~/tmp/mongodump/local-production-db/
(be sure to check firewall sudo ufw status and net.bindIp sudo nano /etc/mongod.conf to confirm that you have access and your mongo process is listening on an external port)
Related
I have a MongoDB replica set with SCRAM-SHA-256 authentication only, and cannot cannot get the mongodump command to work on Ubuntu.
mongodump -h xxx.xxx.xxx.xxx:xxxx -u xxxx -p xxxx --authenticationDatabase xxxx --authenticationMechanism SCRAM-SHA-256 --db xxxx -c xxxx -q "{xxxx}" -o "xxxx/xxxx"
Failed: error connecting to db server: cannot establish SASL session: SASL(-4): no mechanism available: No worthy mechs found
I have installed every sasl2 library I could find and set every environment variable I could think of.
Anyone out there able to tell me what I'm missing?
I am weeks trying to do backup from my docker without any success.
My Docker Compose:
services:
mongo:
image: mongo
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: user
MONGO_INITDB_ROOT_PASSWORD: password
networks:
- internal
volumes:
- /opt/rpg/mongo/data:/data/db
Input: docker exec mongo sh -c 'exec mongodump -d rpg --archive' > /home/rpg/all-collections.archive
Output: Failed: error getting collections for database rpg: error running listCollections. Database: rpg Err: command listCollections requires authentication
Then i tried with password
Input: docker exec mongo sh -c 'exec mongodump -d rpg —uri="mongodb://user:password#mongo:27017/rpg?authSource=admin" --archive' > /home/rpg/all-collections.archive
Output: SASL authentication step: Authentication failed.
After weeks trying i get the connection with:
sudo docker run -it --rm --network internal mongo \
mongo --host mongo \
-u user \
-p password \
--authenticationDatabase admin \
rpg
Now I can see the collections and everything, but i still cant get the backup.
Tried too:
Input:
sudo docker run --rm --network internal mongo \
mongodump --host mongo \
-u user \
-p password \
--authenticationDatabase admin \
--db rpg
> ~/rpg2-collections.archive
Output:
Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.
Without success, can someone help me ?
Was having the same Authentication problem, and this command worked:
docker exec <docker_container_name> sh -c 'mongodump --uri="mongodb://username:password#localhost:27017/db_name?authSource=admin&readPreference=primary" --archive' > db.dump
I am doing it like this:
mongodump --host='{mongo_server}' --db='{mongo_db}' --collection='{collection_name}' --out={output_folder}
and it works just fine.
though as you can see i am doing collection by collection dump through python script on separate host, because i wasn't able to backup everything at once.
so the first step is to get all collections from container with installed mongo client:
mongo {mongo_server}/{mongo_db} --eval 'db.getCollectionNames()' --quiet
my script also uploads each collection dump to s3 bucket s3cmd, that is why you are seeing only part of it...
After weeks, i get a backup from files (not mongodump).
sudo tar czvf /home/backup.tar.gz /opt/rpg/mongo
And i did a repair and worked at my pc.
mongod --repair ./{{folder}}
Tried taking dump from a remote node and got the following error:
Failed: can't create session: could not connect to server:
connection(): auth error: sasl conversation error: unable to
authenticate using mechanism "SCRAM-SHA-256": (AuthenticationFailed)
Authentication failed.
Tried two methods to take dump from the remote node. But got the same error in both the methods.
# Method 1
mongodump -h remoteip#port -u xxx -p xxx --db xxx --authenticationDatabase xxx
# Method 2
mongodump --uri "mongodb://username:password#remoteip:port/db?authSource=xxx"
How to resolve this?
For me (trying to use mongodump on a single node DB on the same host), using --authenticationDatabase admin did the trick:
mongodump -u root --password 'secret' --authenticationDatabase admin -d mongo-dev -o /tmp/dump-2020-11-27.bson
(courtesy of mongodump from remote node - unable to authenticate using mechanism "SCRAM-SHA-256")
1.If you are using an URI for mongodump command,--authenticationDatabase admin option is equivalent to ?authSource=admin
mongodump --uri "mongodb://[username:password#]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]"
sample url:
mongodump --uri "mongodb+srv://username1:password1#host1/db1?authSource=admin"
I had the same issue. In my case, the password has special characters. It works with single quote for password:
-p 'my_password'
I had the same problem and solved it using single quotes in the password like this:
--password 'secret'
Was in the same spot that you are, solved it this way:
mongodump --uri "mongodb+srv://username:password#yourmongodbclustersourceurl" --archive \
mongorestore --uri "mongodb+srv://username:password#yourmongodbclusterdestinationurl" --archive \
--nsExclude "admin.system.*"
Needless to mention, you just need to change your username, password and the url in this formula and voila. Good luck.
In order for me to connect to this [secure] Mongo instance I have to run the following command:
mongo --ssl --host sampleHostname --sslPEMKeyFile /path/to/user.pem --sslCAFile /path/to/mongoca.cer --authenticationDatabase '$external' --authenticationMechanism=MONGODB-X509
I am trying to do a mongodump command to get the data but I keep running into the following errors:
Attempt 1
mongodump -d mydb
Failed: error connecting to db server: no reachable servers
Attempt 2
Can't create backup mongodump with --db. Authentication failed
mongodump -d mydb --authenticationDatabse '$external'
Failed: error connecting to db server: no reachable servers
Attempt 3 Using the same command as how I connect.
mongodump -d mydb --ssl --host sampleHostname --sslPEMKeyFile /path/to/user.pem --sslCAFile /path/to/mongoca.cer --authenticationDatabase '$external' --authenticationMechanism=MONGODB-X509
Failed: error getting collections for database 'mydb': error running 'listCollections'. Database: 'mydb' Err: not authorized on 'mydb' to execute command {listCollections: 1, cursor: {} }
I have tried the same command with sudo but it still returns the same error.
Attempt 4 Minimum permission for using mongodump (to dump a specific db)
mongodump -d mydb --ssl --host sampleHostname --sslPEMKeyFile /path/to/user.pem --sslCAFile /path/to/mongoca.cer --authenticationDatabase '$external' --authenticationMechanism=MONGODB-X509 --excludeCollection=system.indexes
Failed: error getting collections for database 'mydb': error running 'listCollections'. Database: 'mydb' Err: not authorized on 'mydb' to execute command {listCollections: 1, cursor: {} }
I am stuck and I am eventually going to run mongorestore but I do not want to run this without making sure I am able to backup first. I imagine the solution for mongodump will resolve any possible issues I may have with mongorestore (if any).
I found the solution thanks to this blog post , looks you have to set the -u value with the CN when using 509 and $external.
mongodump --ssl --sslPEMKeyFile user.pem --sslCAFile cap.pem --sslAllowInvalidHostnames --authenticationMechanism=MONGODB-X509 --authenticationDatabase '$external' --host "rsTmpCloudManager/10.100.15.118:27017,10.100.16.237:27017,10.100.17.107:27017" -d testJoce -u "CN=???,OU=???,O=???,L=???,ST=???,C=??"
Using the mongo client, I can authenticate successfully with my admin account:
$ mongo -u my_admin_username -p my_admin_pass --authenticationDatabase admin
MongoDB shell version: 2.6.3
connecting to: test
>
but when I try to execute mongorestore with the same credentials, it fails:
$ mongorestore -u my_admin_username -p my_admin_pass /backup/20140821/db/myproject/
connected to: 127.0.0.1
assertion: 13 not authorized on admin to execute command { getParameter: 1, authSchemaVersion: 1 }
Why is that? What am I missing? I'd like to execute successfully a mongorestore.
$ mongorestore -u my_admin_username -p my_admin_pass /backup/20140821/db/myproject/ -db myproject
This worked.