简体   繁体   English

如何在mongodb中将数据库从一台服务器复制到另一台服务器

[英]How to copy database from one server to another in mongodb

I am trying to copy a database [mongodb] in production server hosted in nginx to my local dev environment setup [linux machine]. 我正在尝试将Nginx托管的生产服务器中的数据库[mongodb]复制到本地开发环境设置[linux计算机]。

I tried the solution given in following url How do I copy a database from one MongoDB server to another? 我尝试了以下url中给出的解决方案如何将数据库从一台MongoDB服务器复制到另一台服务器?

But when I establish a ssh tunnel and try to copy, I am getting following error 但是,当我建立ssh隧道并尝试复制时,出现以下错误

db.copyDatabase("admin","testadmin","localhost:27018")
{
        "ok" : 0,
        "errmsg" : "couldn't connect to server localhost:27018, connection attempt failed"
}

if I try to copy the database directly in my destination server. 如果我尝试直接在目标服务器中复制数据库。 I am getting the following error 我收到以下错误

db.copyDatabase("admin","testadmin","mongodb://<remotehostname>:27017")
{
        "operationTime" : Timestamp(1545126863, 1),
        "ok" : 0,
        "errmsg" : "Must specify set name for replica set ConnectionStrings",
        "code" : 9,
        "codeName" : "FailedToParse",
        "$clusterTime" : {
                "clusterTime" : Timestamp(1545126863, 1),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        }
}

Please help. 请帮忙。 I am stuck with issue for two days. 我被问题困扰了两天。 I am not sure whether I can use mongodump and restore. 我不确定是否可以使用mongodump和还原。 I am using mongo version 3.4 in my remote server and mongo version 3.6 in my local. 我在远程服务器上使用mongo 3.4版,在本地服务器上使用mongo 3.6版。 Could this be a problem? 这可能是个问题吗?

I also tried adding replica set, but got below error. 我也尝试添加副本集,但出现以下错误。 How to find the replica set name? 如何找到副本集名称?

db.copyDatabase("admin","testadmin","mongodb://<remotehostname>:27017/?replicaSet=test")
{
        "operationTime" : Timestamp(1545117923, 135),
        "ok" : 0,
        "errmsg" : "Bad digit \"/\" while parsing 27017/?replicaSet=test",
        "code" : 9,
        "codeName" : "FailedToParse",
        "$clusterTime" : {
                "clusterTime" : Timestamp(1545117923, 135),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        }
}

An alternative would probably be to use mongoDump/mongorestore. 一种替代方法可能是使用mongoDump / mongorestore。

https://stackoverflow.com/a/22201759/5107937 https://stackoverflow.com/a/22201759/5107937

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在没有外壳(命令行)访问的情况下将表从一个数据库复制到同一服务器上的另一个数据库? - How can I copy a table from one database to another on the same server without shell (command line) access? 如何将表从一个mysql数据库复制到另一个mysql数据库 - How to copy a table from one mysql database to another mysql database 如何将表从一个数据库复制到其他服务器的另一个数据库 - How to copy tables from one DB to another DB Of Different server 从一台服务器到另一台服务器的 Ansible 复制服务器镜像 - Ansible copy server image from one server to another 将MySQL数据库从一个服务器导入另一个服务器 - Importing MySQL database from one server to another 如何在PHP中将tgz文件从一台服务器复制到另一台Linux服务器? - How to copy tgz file one server to another linux server in php? 如何将值从一列复制到另一列? - How to copy a value from one column to another? 使用bash将数据从一个数据库复制到另一个数据库 - Copy data from one database into another using bash 将mongodb数据目录复制到另一台服务器 - Copy mongodb data directory to another server 手动安装 php 扩展(从一台服务器复制到另一台服务器) - Manual Installation of php extension (copy from one server to another)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM