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.
Related
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}}
Using MongoAtlas and trying to run mongorestore and I am getting the following error.
Failed: error connecting to db server: no reachable servers
I am using the command Atlas proposes.
mongorestore --host BStaging-shard-0/bstaging-shard-00-00-lq11i.mongodb.net:27017,bstaging-shard-00-01-lq11i.mongodb.net:27017,bstaging-shard-00-02-lq11i.mongodb.net:27017 --ssl --username heroku --password "VN" --authenticationDatabase admin
2019-04-14T11:02:31.336-0500
Failed: error connecting to db server: no reachable servers
Fixed:
Updated MongoDB community Shell
Changed bash_profile to point to new shell
Changed bash_profile to point to new mongo db community4.0
(/usr/local/opt/mongodb-community#4.0/bin:/usr/local/opt/mongodb-community-shell/bin:$PATH)
source bash_profile
reconnect to mongo
mongo "mongodb://staging-shard-00-00-dgdr.mongodb.net:27017,staging-shard-00-01-dgdr.mongodb.net:27017,staging-shard-00-02-dgdr.mongodb.net:27017/test?replicaSet=Staging-shard-0" --ssl --authenticationDatabase admin --username me --password pwd
restore
mongorestore --host Staging-shard-0/staging-shard-00-00-dgdr.mongodb.net:27017,staging-shard-00-01-dgdr.mongodb.net:27017,staging-shard-00-02-dgdr.mongodb.net:27017 --ssl --username me --password pwd --authenticationDatabase admin
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=??"
I try to create a backup of my MongoDB replicaset but I have an authentication problem :D .
So when I try to use mongodump
root#e03c2a89ac31:/# mongodump -u myBackupAccount -p 123456 --host mongo1 --out /home/backup
2017-01-17T11:00:41.069+0000 Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.
root#e03c2a89ac31:/# mongodump -u myBackupAccount -p 123456 --host mongo1 --authenticationDatabase admin --out /home/backup
2017-01-17T12:37:45.819+0000 Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.
But if I try with a mongo shell, I can connect to my instance
root#e03c2a89ac31:/# mongo -u myBackupAccount -p 123456 --host mongo1
MongoDB shell version v3.4.1
connecting to: mongodb://mongo1:27017/
MongoDB server version: 3.4.1
REPLICASET_NAME:PRIMARY> exit
My backup user was created with that command
root#e03c2a89ac31:/# mongo -u myUserAdmin --authenticationDatabase "admin" -p 123456
MongoDB shell version v3.4.1
connecting to: mongodb://mongo1:27017/
MongoDB server version: 3.4.1
REPLICASET_NAME:PRIMARY> db.createUser({user: "myBackupAccount", pwd: "123456", roles: [ { role: "backup", db: "admin" } ]})
So do you know why it isn't working ?
I did somethings bad ? :p
Thanks in advance for your help ;)
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)