Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy password protected database from remote server in mongodb?

Tags:

mongodb

I am running mongodb 2.4.8 and need to copy a database from remote server. Server has auth enabled in combination with a user having privileges the database. I have tried copydb but it didn't work. I guess it failed because of remote server using auth in combination with role based user(mentioned under authentication section of documentation).

 host = "myhost.com"
 mynonce = db.runCommand( { copydbgetnonce : 1, fromhost: host } ).nonce
 username = "myuser"
 password = "mypassword"
 password_hash = hex_md5(mynonce + username + hex_md5(username + ":mongo:" + password))
 db.runCommand({ 
   copydb: 1, 
   fromdb: "test", 
   todb: "test", 
   fromhost: host, 
   username: username, 
   key: password_hash 
 })
 # output: { "ok" : 0, "errmsg" : "" }
 # but nothing really gets copied

What other options do I have? I would prefer a solution which can work from within the mongo shell as I do not have ssh access to server.

like image 815
rubish Avatar asked Dec 18 '25 01:12

rubish


1 Answers

try db.copyDatabase(fromdb, todb, fromhost, username, password). as manual said: http://docs.mongodb.org/manual/reference/method/db.copyDatabase/

like image 103
hasib32 Avatar answered Dec 20 '25 17:12

hasib32



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!