0

Or just may be dump database on to the folder on the server and then scp it to local machine? I'm trying to use mongodump from /usr/bin, but nothing good comes out of it, for instance:

mongodump --ssl -u root -p password --authenticationDatabase name -d databaseName -o /database -->Failed: error connecting to db server: no reachable servers

if: mongodump -u root -p password --authenticationDatabase name -d databaseName -o /database -->Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.

tried to do --host=ip.ad.re.ss:27017 tried to do --host=host-name:27017 --host=127.0.0.1:27017 --host=web-address:27017

tried to switch off mongodb...

Tried to copy files manually, but end up with the empty database on the local machine...

tried to use: mongo --> db.copydatabase(from, to, name)

Nothing is happening positive... How to use mongodump? Possible to use any other way. Only through terminal, ubuntu setup doesn't have any gnu.

3
  • I created admin with root privileges, and using this authentication to copy database. But it still gives me auth error... I tried to show users... it gives me empty array, but if I use admin, then show users it gives me admin... Totally confused how to use mongodump. – bugthefifth May 26 at 12:52
  • Do you mean how to copy the entire Mongo database? You can simply copy the dbPath folder (stop the database before you copy it). If you got an empty database then most likely you set dbPath wrong at your local machine. – Wernfried Domscheit May 26 at 14:50
  • I tried to scp them, but as I remember right now, at that operation I didn't stop mongo. May be because of this my dbs on the local machine is empty? After that I started trying to mongodump... aaaaannd it's just doesn't work for me :( I have no idea why... I will try to scp tomorrow. I hope you are right. I was fighting with mongo for many many hours today... – bugthefifth May 26 at 15:24
-1

As you said - more errorless method:

  • connect to server and create dump there (like this, mongodump -u root -p password --authenticationDatabase admin -d databaseName -o /database)
  • scp database dump from the server to vm
  • Restore DB on VM mongorestore --authenticationDatabase=admin -u=root -p=password ./dump/

Based on your error:

  • you are doing something wrong in params (did you use --authenticationDatabase admin)?
  • you are doing something wrong with regarding place (server, network)

Basically, your variant should work, just need to adjust the params for sure.

11
  • Thank you for the answer. I will try it. I just saw your answer. Have a great day! – bugthefifth May 26 at 20:46
  • I will try scp with switched off database first... Because this mongodump command I tried many variations with it, but it's fighting with me... I tried admin and plus created admin and tried with new admin with root privileges... One time I had not authenticated with admin user :)) – bugthefifth May 26 at 20:53
  • Hello. Your answer was the closest to the right answer. Could you please fix your answer accordingly so I can give it a check mark. "My approach was too complicated to save database from the server to the vm on the local comp. As I understand the host ip could not be recognised inside of the vm, so no way this copying could be done in one step. So what I did: 1. mongodump -d (or --db?) databaseName (on the server) 2. scp database dump from the server to vm 3. mongorestore --verbose \path\from ... – bugthefifth May 28 at 18:18
  • Obviously there is a way to mongodump from server to server, But this question would be usefull for people who get confused trying to copy database from a server to vm... – bugthefifth May 28 at 18:20
  • I didn't actually know that this command can be used separately to dump and restore. That's why I didn't think right away to separate this command into 3 smaller steps... I have no idea who and why gave you - mark, you were very close to complete right answer... no authentication required though with the command, no ssl when copying to the same server... the commands are actually short and simple. – bugthefifth May 28 at 18:27
0

Basically what is missing from your mongodump command is... "" round your --host -value.

--host="host-name:27017"

Check similar question here

9
  • Hello! TY for replying. I tried this: /usr/bin/mongodump --host="webAdress.com:27017" --ssl -u root -p password --authenticationDatabase admin -d databaseName -o /database – bugthefifth May 27 at 9:23
  • error dialing 127.0.0.1:27017: dial tcp 127.0.0.1:27017: connect: connection refused – bugthefifth May 27 at 9:24
  • error dialing host-forDatabase:27017: dial tcp 127.0.0.1:27017: connect: connection refused – bugthefifth May 27 at 9:24
  • When use this command with the web address: Failed: error connecting to db server: no reachable servers – bugthefifth May 27 at 9:26
  • I know the port is right. I checked it through mongo. I tried all possible variations of connection... Still it says it cannot connect or refuse to connect. – bugthefifth May 27 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.