`

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/

操作实践:
添加新的priority=0的mongod secondary:
前提: 10.0.1.1 primary, 10.0.1.2 secondary, 10.0.1.3 arbiter
目的; 添加10.0.1.4作为延迟1小时的冷备份

锁住secondary mongod库,将文件完整的copy一份出来,然后再解锁
1. 登录secondary服务器: ssh 10.0.1.2
2. 连接mongod
3. db.fsyncLock()  注意: 在执行db.fsyncLock()和db.fsyncUnlock()时,不能关闭当前的shell窗口,否则可能无法连接而需要重新启动mongod服务。
rs.printReplicationInfo() 查看同步延迟
4. 打开新shell, 连接10.0.1.4, sudo chmod o+w /data/mongodb/(改个权限好写入数据)
5. 连接10.0.1.1 scp -r /data/mongodb/data/ user1@10.0.1.4:/data/mongodb/(另外启动一个新的连接进行数据的copy)
6. db.fsyncUnlock()


利用scp拷贝:
copy 私钥id_rsa 到你的目录下 ~/.ssh/id_rsa
再使用scp进行copy文件。
如果嫌每次输入私钥的密码麻烦,可以暂时去掉私钥的密码:http://zjhwl.iteye.com/admin/blogs/2228852

启动10.0.1.4,加入到这个replic set中去
1. 从10.0.1.2中拷一个mongo的程序到10.0.1.4中(可以借助scp的方式拷贝)
2. 登录10.0.1.4启动mongod: mongod -f ***/mongodb.conf --fork
3. 配置10.0.1.1,10.0.1.2,10.0.1.3,10.0.1.4的iptables
4. 登录10.0.1.1的mongd, rs.add({"_id":NumberInt(8), host: "10.0.1.4:11114", priority: NumberInt(0),"hidden": true,"slaveDelay":NumberInt(3600) })

蜗牛食堂
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics