How do I copy a database from one MongoDB server to another?

前端 未结 5 1729
逝去的感伤
逝去的感伤 2020-11-29 21:01

I have two mongodbs in different server, both start with --auth. Now I want to copy a db from one server to another.

> mongo
> use admin
&         


        
5条回答
  •  没有蜡笔的小新
    2020-11-29 21:34

    Starting from Mongo version 3.2 you can do it by using mongodump/mongorestore:

    mongodump  --host  --db  --archive | mongorestore --host  --archive
    

    Additional info could be found at:

    https://docs.mongodb.com/manual/reference/program/mongodump/ https://docs.mongodb.com/manual/reference/program/mongorestore/

    To make remote mongo reachable you can create ssh tunnel to it:

    creates a tunnel to the remote mongodb server and tunnels it through port 27117 to the local client

    ssh -fN -L 27117:localhost:27017  
    

    In this case the command to run on the local machine you want to restore to could be:

    mongodump  --port 27117 --db  --archive | mongorestore --archive
    

提交回复
热议问题