• 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

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

    写在最后:

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

  • 相关阅读:
    ac通过Parallels Desktop虚拟机实现共享windows独有软件提供的特殊网络11
    ac通过Parallels Desktop虚拟机实现共享windows独有软件提供的特殊网络9
    新东方智慧教室:全方位的智慧教室解决方案
    告别开发
    Unity中Awake的执行时间点
    警惕C#事件使用过程中的GC陷阱
    概率生成函数(高清重置版)暨 [CTSC2006]歌唱王国
    Leaflet中使用leafletecharts插件实现Echarts的Migration迁徙图
    Leaflet中使用leafletecharts插件实现Echarts的Migration迁徙图(带炫光特效)
    Nginx映射本地json文件,配置解决浏览器跨域问题,提供前端get请求模拟数据
  • 原文地址:https://www.cnblogs.com/cuishuai/p/8404270.html
Copyright © 2020-2023  润新知