使用percona pbm恢复到另一个mongod replica set集群
【环境说明】
mongodb replica set (备份文件) + percona-backup-mongodb-2.2.0
【mongodb数据库异库恢复操作】
数据库备份及恢复都很重要,需要将mongodb replica set集群备份文件异地恢复到另一个mongodb replica set 集群验证,当前备份工具是percona pbm
【步骤】
根据percona pbm文档说明
在异库安装好集群,且运行正常。
主节点跟从节点挂载好备份的共享存储
mkdir -p /mnt/nfs
vim /etc/fstab
xxx.xx.xx.xx:/mnt/Kingdee/NFS/backup /mnt/nfs nfs defaults 0 0
mount -a
根据一样步骤安装percona-backup-mongodb-2.2.0-1.el7.x86_64
主库创建一样的用户及权限
db.getSiblingDB("admin").createRole({ "role": "pbmAnyAction", "privileges": [ { "resource": { "anyResource": true }, "actions": [ "anyAction" ] } ], "roles": [] }); db.getSiblingDB("admin").createUser({user: "pbmuser", "pwd": "secretpwd", "roles" : [ { "db" : "admin", "role" : "readWrite", "collection": "" }, { "db" : "admin", "role" : "backup" }, { "db" : "admin", "role" : "clusterMonitor" }, { "db" : "admin", "role" : "restore" }, { "db" : "admin", "role" : "pbmAnyAction" } ] });
设置一下环境变量,注意设置为当前环境的用户密码及IP跟集群名称
export PBM_MONGODB_URI="mongodb://pbmuser:secretpwd@localhost:27017/?authSource=admin&replSetName=easydb_test"
配置参数信息
vim pbm_config.yaml pitr: enabled: false oplogSpanMin: 0 compression: gzip storage: type: filesystem filesystem: path: /mnt/nfs/mongodb_bak/mongodbdump backup: compression: gzip
执行运用参数,该参数信息跟源库一致:
pbm config --file pbm_config.yaml
启动服务pbm angent服务
systemctl start pbm-agent
查看服务状态,这里看到是没有扫描出备份文件,使用pbm list差不到源库备份的信息
systemctl status pbm-agent
需要执行force-resync参数扫描一下备份文件,然后可以扫描到源库备份的文件
pbm config --force-resync Storage resync started
pbm list Backup snapshots: 2023-07-18T02:22:34Z <logical> [restore_to_time: 2023-07-18T02:22:39Z] 2023-07-18T15:00:01Z <logical> [restore_to_time: 2023-07-18T15:00:06Z] 2023-07-19T15:00:01Z <logical> [restore_to_time: 2023-07-19T15:00:05Z] 2023-07-20T15:00:01Z <logical> [restore_to_time: 2023-07-20T15:00:05Z] PITR <off>: 2023-07-18T02:22:40Z - 2023-07-21T02:39:19Z
然后就可以直接进行全库恢复操作
pbm restore 2023-07-20T15:00:01Z Starting restore 2023-07-21T07:12:28.21123997Z from '2023-07-20T15:00:01Z'...Restore of the snapshot from '2023-07-20T15:00:01Z' has started
查看备份信息及日志journalctl -u pbm-agent
基于时间点恢复
pbm restore --time="2023-07-21T02:39:19" Starting restore 2023-07-21T08:35:58.048118546Z to point-in-time 2023-07-21T02:39:19...
查看备份信息及日志journalctl -u pbm-agent
数据验证
这个文档每分钟执行一行数据并且记录时间点,查看时间点为2023-07-21 10:39:01,与基于时间点恢复2023-07-21T02:39:19+8小时一致
【注意事项】
另一个环境不要执行备份操作,官方文档中也有说明,防止备份文件被损坏;
在执行基于时间点恢复时候没有关掉源库的增量备份也能恢复成功。