Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore remote MongoDB server with local mongodump data

Tags:

scp

mongodb

We have a remote MongoDB server and we have mongodump data on a local developer's machine. What is the best way to restore the remote MongoDB server data with the local data? Is there a mongo command that we can use?

like image 976
Alexander Mills Avatar asked Dec 03 '22 21:12

Alexander Mills


1 Answers

Alright so we did this in two steps. I think you can do it in one step, with just mongorestore.

First we moved the data from the local machine to the remote machine with the scp command:

scp <path-to-mongofile> <remote-host>:<absolute-file-path>

then we ssh'd into the remote mongod server, and used mongorestore to restore the db

mongorestore --host=$HOST --port=$PORT -u $ADMIN_USER -p $PSWD  --db <your-db> <absolute-path-to-restore-db> --authenticationDatabase "admin"

but I think the first scp command is redundant. In fact, if you cannot ssh into the server running mongod, then you will have to use the mongorestore command directly from the local developer's machine.

like image 182
Alexander Mills Avatar answered Dec 06 '22 10:12

Alexander Mills