linux mongdb 备份操作笔记
目的:添加一个延迟1小时的sencodary作为冷备数据库
相关文档:Priority 0 Replica Set Members
WARNING:
The rs.reconfig() shell method can force the current primary to step down, which causes an election. When the primary steps down, the mongod closes all client connections. While this typically takes 10-20 seconds, try to make these changes during scheduled maintenance periods.
To successfully reconfigure a replica set, a majority of the members must be accessible. If your replica set has an even number of members, add an arbiter to ensure that members can quickly obtain a majority of votes in an election for primary.
#secondary 延迟
[url]http://docs.mongodb.org/manual/tutorial/configure-a-delayed-replica-set-member/
cfg.members[0].slaveDelay = 3600[/url]
#数据库备份和恢复
http://my.oschina.net/169/blog/158976
添加新的mongdb
https://docs.mongodb.org/manual/tutorial/expand-replica-set/#maximum-voting-members
https://docs.mongodb.org/manual/tutorial/backup-with-filesystem-snapshots/
操作实践:主要目的: 锁住secondary mongod库,将文件完整的copy一份出来,然后再解锁
1. 登录secondary服务器: ssh 10.0.1.1
2. 连接mongod
3. db.fsyncLock() 注意: 在执行db.fsyncLock()和db.fsyncUnlock()时,不能关闭当前的shell窗口,否则可能无法连接而需要重新启动mongod服务。
rs.printReplicationInfo() 查看同步延迟
4. 打开新shell, 连接10.0.1.2, sudo chmod o+w /data/mongodb/(改个权限好写入数据)
5. 连接10.0.1.1 scp -r /data/mongodb/data/ user1@10.0.1.2:/data/mongodb/(另外启动一个新的连接进行数据的copy)
6. db.fsyncUnlock()
添加新的priority=0的mongod secondary: 待续