可以使用mongoshake工具进行备份。
You can use the mongoshake utility for backups.
mongodbShake可以应用在实例间复制,机房间、跨数据中心复制。
MongodbShake can be used for inter-instance replication, inter-machine room replication, and cross-data center replication.
mongodbshake是通过读取MongoDB集群的Oplog操作日志,对MongoDB的数据进行复制,后续通过操作日志实现特定需求。
Mongodbshake is to copy the data of MongoDB by reading the Oplog operation log of MongoDB cluster, and then realize specific requirements through the operation log.
下载mongoshake安装包:
Download the mongoshake installation package:
解压:
Decompression:
tar zxf mongo-shake-v2.7.4.tgz
cd mongo-shake-v2.7.4/
内容如下所示:
The contents are as follows:
修改collector.conf文件(针对有密码验证的情况):
Modify the collector.conf file (with password authentication):
修改
modification
mongo_urls,代表源端mongo
mongo_urls, representing the source mongo
tunnel.address 目的端mongo
tunnel.address destination mongo
sync_mode = all (视情况而定,有all 全量+增量同步,full表示全量同步,incr表示增量同步)
sync_mode = all (depending on the situation, there are all full + incremental synchronization, full means full synchronization, incr means incremental synchronization)
filter.pass.special.db = admin
#指定特殊的namespace通过,比如admin,system.views,mongoshake,config。正常情况下,这几个都会被过滤,但是有可能有比较特殊的情况,例如,由于历史原因,用户的数据写入到admin库了,现在希望对这部分数据也进行同步,那么就可以执行filter.pass.special.db=admin。默认空。
#Specify special namespaces via, for example, admin, system.views, mongoshake, config. Under normal circumstances, these data will be filtered, but there may be special cases. For example, due to historical reasons, the user's data has been written into the admin library, and now you want to synchronize this part of data, you can execute filter.pass.special.db =admin. Default is empty.
格式如下:
The format is as follows:
备注:需要注意,源端与目的端的账号需要对mongo里面的库有全部权限(可以把权限设置为root)
Note: Note that the accounts of the source and destination terminals need to have all permissions on the libraries in mongo (the permissions can be set to root).
启动mongoshake
Start mongoshake
nohub ./collector.linux -conf ./collector.conf &
mongoshake的配置文件
Configuration file for mongoshake
(2.4版本之后mongoshake参考如下配置文件释义)
(After version 2.4, refer to the following configuration file for explanation of mongoshake)