s3cmd pipe mongodb 3.0.2 SASL auth failed - mongodb

Does anybody experience an issue with s3cmd and mongoimport after having upgraded to mongodb 3.0.2? I am receiving the SCRAM-SHA1 / SASL error but have no clue how I can fix this? The connection from and to s3 is still unaffected and working properly.
I was untill recently successfully using s3cmd to pipe the output from mongodb 2.6:
s3cmd get s3://filename - | mongoimport -d testdb -c testcollection
which is now returning:
"Failed: error connecting to db server: server returned error on SASL
authentication step: Authentication failed."
Thanks in advance

Try using the --authenticationDatabase parameter to direct the mongoimport tool to the database that holds the user’s credentials. Currently it fails to authenticate since it can't find the location of those credentials.
The full command should look something like this:
s3cmd get s3://filename - | mongoimport -d testdb -c testcollection -u <user_name> -p <password> --authenticationDatabase admin
This is all true to version 2.4 and up of the mongoimport tool, so make sure you have an updated version.

Related

mongodump from remote node - unable to authenticate using mechanism "SCRAM-SHA-256"

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.

Windows Batch Script for Automated Mongodb Backup

I have setup a superuser in mongodb and I am able to do a backup manually in the command line or connect to the database with the username and password in the console or in Compass, but if I move that command to a batch script and run the script, I always get the 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.
The command is:
mongodump --username myusername --password mypassword --out C:\backups --db mydb --authenticationDatabase admin
I have updated the bindIp to 0.0.0.0 and added security: authorization: "enabled".
Any thoughts on why I can't run this in the batch script. I am using Mongo 4.2
Thanks

Why can't `mongoimport` connect to my free-tier MongoDB Atlas cluster?

I have a free-tier MongoDB Atlas cluster, and I want to upload some JSON to it from my Mac.
I tried to run this:
mongoimport -h cluster0-shard-00-00-cxacx.mongodb.net:27017 -d literature -c books -u xxxx -p xxxx --file ~/Desktop/books.json --type json --ssl
However, I got this error:
Failed: error connecting to db server: no reachable servers, openssl error: SSL errors: SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
I tried without --ssl in the command, and I got this instead:
Failed: error connecting to db server: no reachable servers
Why can't it reach the server?
More info:
My mongoimport version is r3.2.22.
My OS is macOS 10.14.5.
My cluster version is 4.0.10.
The user has admin permission.
My IP address is white-listed.
I can connect to the cluster with the MongoDB Node Driver.
I get the same problem with mongofiles.
I also tried variations of the command with no success that included --authenticationDatabase admin and the name of the replica set and other server nodes.
Update: I was able to upload the JSON file by sending it to a Linux cloud server and running mongoimport from there.
Monogo atlas gives you service records (SRV) and not host.
"cluster0-shard-00-00-cxacx.mongodb.net" It is not a proper host.
Use it like:
mongoimport --uri
"mongodb://root:#atlas-host1:27017,atlas-host2:27017,atlas-host3:27017/?ssl=true&replicaSet=myAtlasRS&authSource=admin"
-d literature -c books -file ~/Desktop/books.json --type json --ssl
You will get complete URI from mongo atlas connect screen

Issues with mongoRestore [listCollections requires authentication]

I am trying to restore a MongoDB on an EC2 instance. I am currently running Mongo 4.0. I am restoring a .tgz, which I then unzip, and it contains a directory with all of my files. I previously used this command:
sudo mongorestore --db newDB mongoDump-2018-07-25-0200/viboDB/
Now that I am trying to update our database, I am getting the following error.
building a list of collections to restore from mongoDump-2018-07-25/0200 dir
Failed: viboBI2.Songs: error reading database: command listCollections requires authentication
I have logged into the mongo shell, and used db.auth() to authenticate as an admin. I have tried restarting mongo as well. Any help would be appreciated!
For restoring the Database you need to provide authentication.
mongorestore -u USERNAME -p PASSWORD --authenticationDatabase admin -d dbNAME PATH/TO/DIRECTORY
you can also provide host and port by adding -h and --port

Use mongorestore to restore a database to MongoDB (3.4) with --auth enabled, SASL error

Using mongorestore, I am trying to restore a MongoDB database to a new server (both version are 3.4). The new server has -auth enabled, so you are required to login. The database does not exist so I want mongorestore to create it using the --db option. This works when authorization is not enabled but if I enable authorization the restore fails with the following error:
Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.
I am using an admin account with the root role when I attempt the restore.
Backing up prod and restoring to dev is a fairly regular activity for us, but we can't just drop the existing database and recreate it because of the error above, not unless we disable authorization which doesn't make much sense. Is there a better way to do this/avoid the SASL errors/not have to disable auth?
I was getting the same error and while I couldn't figure out what was wrong restoring with my admin user (my hunch is a ! in the password which escaping did not help) I was able to restore by creating a new user specifically for the role.
In mongo shell:
>use admin;
>db.createUser({
user: 'restoreuser',
pwd: 'restorepwd',
roles: ['restore']
});
In terminal:
$mongorestore --host databasehost:12345 --username restoreuser --password restorepwd --authenticationDatabase admin --db targetdb ./path/to/dump/
Thanks to Adamo Tonete over at Percona, he helped us solve this problem. If you want to restore a database using your admin user with the root role, you need to specify the authentication database and user in the mongorestore command.
mongorestore --host hostname:27017 -u adminuser -p pass --authenticationDatabase admin -d TargetDatabase /Data/TargetDatabaseRestore
That tells mongo to use the admin database to authenticate the user you are passing in. If that user has the correct rights assigned, it will be able to create the new database.
First Access your db to 4366 port then run this command
mongorestore --port 4366 -u admin -p password --authenticationDatabase admin -d dealmoney /home/yash/Desktop/prodDump/teatingToProductionLastDump/dealmoney .