mongodb 3.4 学习 (五)备份&恢复
备份恢复命令
mongodump -h 127.0.0.1 -p 27017 -o /opt/backup -u app -p '@app' --collection demo --db app --oplog
mongorestore -h 127.0.0.1 -p 27017 -u app -p '@app' /opt/backup/mongodump-2013-10-24 --oplogReplay
配置Hidden Secondary用于备份
conf = rs.conf()
{
......
"members" : [
{
"_id" : 0,
"host" : "10.0.70.105:27021",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "10.0.70.105:27022",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "10.0.70.105:27023",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
......
}
conf.members[2].hidden = true
conf.members[2].priority = 0
conf
{
......
"members" : [
{
"_id" : 0,
"host" : "10.0.70.105:27021",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "10.0.70.105:27022",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "10.0.70.105:27023",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : true,
"priority" : 0,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
......
}
rs.reconfig(conf)
# 锁写
use admin
db.fsyncLock()
# 查看锁状态
use admin
db.currentOp()
# 解锁
use admin
db.fsyncUnlock()
备份shard群集
# 1 关闭balancer
use config
sh.stopBalancer()
# 2 锁定所有shard的复制集
db.fsyncLock()
# 3 修改CSRS的复制集配置
use config
db.BackupControl.findAndModify(
{
query: { _id: 'BackupControlDocument' },
update: { $inc: { counter : 1 } },
new: true,
upsert: true,
writeConcern: { w: 'majority', wtimeout: 15000 }
}
)
# 验证CSRS
rs.slaveOk()
use config
db.BackupControl.find(
{ "_id" : "BackupControlDocument", "counter" : 1 }
).readConcern('majority');
# 4 锁定CSRS的复制集
db.fsyncLock()
# 5 备份CSRS
mongodump --oplog
# 6 解锁CSRS
db.fsyncUnlock()
# 7 备份所有的shard
mongodump --oplog
# 8 解锁备份所有的shard
db.fsyncUnlock()
# 9 启动balancer
use config
sh.setBalancerState(true)
在新shard群集恢复数据
# 1 部署新shard复制集
# 2 部署新CSRS服务器
# 3 启动mongos服务
# 4 加入shard到群集
# 5 关闭mongs服务
# 6 恢复shard数据
mongorestore --drop --oplogReplay /data/dump/shardA --port 27021
# 7 恢复CSRS服务器
mongorestore --drop --oplogReplay /data/dump/configData
# 8 启动mongs服务
# 9 重启CSRS服务
# 10 重启shard服务
# 11 重启其他mongs服务
# 12 校验群集
db.printShardingStatus()
show collections
posted on
2017-05-26 09:50
北京涛子 阅读(
...) 评论(
)
编辑
收藏
转载于:https://www.cnblogs.com/liujitao79/p/6907053.html