在做mongodb备份后,研发突然有个需求说先看一下昨天备份里面的数据,进行一下核实。因为那部分数据今天已经删除,由于使用---gzip、--archive做的备份,所以必须导入到同名的数据库里面。只能重新启动一个临时的库来进行数据恢复的工作。好了,接下来就配置了一个新的mongodb来进行备份:
[[email protected] 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
很尴尬包错了,命令参数是正确的,接下来怀疑服务停了?排查服务的状态。发现服务正常运行呢。于是尝试连接:
[[email protected] 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就没问题了。
写在最后:
--------数据不易,且用且谨慎,端口、库名操作前要多确认!!!!!!!!!