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

前端 未结 5 1727
逝去的感伤
逝去的感伤 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:23

    The following worked for me to copy from Ubuntu Server to another Ubuntu Server, both running MongoDB v4+:

    1. The following command should be executed from the server, where you want to restore the database:
       ssh -fN -L 27018:127.0.0.1:27017 
    
    1. Now we have mapped our remote server database to our local server port 27018. Next, we can copy from remote server to our destination server using MongoDB's mongodump/mongorestore pipeline:
       mongodump --port 27018 --db  --username  --password  --archive | mongorestore --username  --password  --archive
    
    1. [OPTIONAL] You can check your restored database as followings:
       mongo --authenticationDatabase "admin" -u  -p
    
       show dbs
    

    Check if your database exists in the list.

提交回复
热议问题