zoukankan      html  css  js  c++  java
  • mongorestore 一次踩雷

    1、在做mongodb备份后,研发突然有个需求说先看一下昨天备份里面的数据,进行一下核实。因为那部分数据今天已经删除,由于使用---gzip、--archive做的备份,所以必须导入到同名的数据库里面。只能重新启动一个临时的库来进行数据恢复的工作。好了,接下来就配置了一个新的mongodb来进行备份:

    [root@nightly etc]# mongorestore --host 127.0.0.1:27019 -d saturn --gzip --archive=/data/mbd/saturn_2018-02-01_23.gz
    2018-02-02T10:38:51.868+0800 Failed: no reachable servers

    很尴尬包错了,命令参数是正确的,接下来怀疑服务停了?排查服务的状态。发现服务正常运行呢。于是尝试连接:

    [root@nightly etc]# mongo --port 27019
    MongoDB shell version: 3.2.1
    connecting to: 127.0.0.1:27019/test
    Server has startup warnings:

    连接是正常的,证明服务是正常的,为什么报错说Failed: no reachable servers,无可访问的服务。只能去排查日志:

    2018-02-02T10:33:20.332+0800 I REPL     [initandlisten] Did not find local voted for document at startup;  NoMatchingDocument Did not find replica set lastVote document in local.replset.election
    2018-02-02T10:33:20.332+0800 I REPL     [initandlisten] Did not find local replica set configuration document at startup;  NoMatchingDocument Did not find replica set configuration document in local.system.replset

    2018-02-02T10:38:48.860+0800 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:51092 #6 (1 connection now open)
    2018-02-02T10:38:51.872+0800 I NETWORK  [conn6] end connection 127.0.0.1:51092 (0 connections now open)

    原来是设置了replset,而没有进行replset的配置。果断去配置文件里面注释掉:

    #replication:
    #  replSetName: rs0

    重启服务,再次执行mongorestore就没问题了。

    2、最近有一次恢复备份的需求,于是就用之前的备份文件进行恢复,按正常流程走,发现其中一个collection总是报数据重复,没有办法创建索引。备份应该是没有问题的,因为之前是恢复过的。不确定问题具体处在哪里?由于比较捉鸡

    于是采取临时解决方案,备份整个库的时候将那个有问题的collection排除在外,然后单独进行备份:

    mongodump -u hqms -p hqms123 -h 10.10.5.18:27017 -d saturn --excludeCollection=likereviews --gzip --archive=./saturn.gz
    mongodump -u hqms -p hqms123 -h 10.10.5.18:27017 -d saturn -c likereviews -o /data/

    然后在进行恢复:

    nohup mongorestore --host 127.0.0.1:27017 -d saturn --gzip --drop --archive=/data/saturn.gz &
    mongorestore -h 127.0.0.1:27017 -d saturn -c likereviews /data/saturn/likereviews.bson

    至此,不能倒入数据的问题解决了,但是还没有弄清楚为什么那样会导致数据重复,可能是复合唯一索引导致的吧?还需要进一步研究。

    写在最后:

        --------数据不易,且用且谨慎,端口、库名操作前要多确认!!!!!!!!!

  • 相关阅读:
    你的系统需要做系统集成测试么?
    测试驱动 ASP.NET MVC 和构建可测试 ASP.NET MVC 应用程序
    RikMigrations 或 Migrator.NET 进行自动化的数据库升级
    单元测试
    C#反射
    J2EE--Struts2基础开发
    Dynamics CRM 客户端的插件调试
    于快速创建 IEqualityComparer<T> 实例的类 Equality<T>
    ToolBox Analysis & Design
    实现$.fn.extend 和$.extend函数
  • 原文地址:https://www.cnblogs.com/cuishuai/p/8404270.html
Copyright © 2011-2022 走看看