一、背景
- 思路
#### ocs救援 / MongoDB做一次性数据迁移
var:
tables <- 多行
src_ip
src_port
src_user
src_passwd
src_authdb
src_schema
tgt_ip
tgt_port
tgt_user
tgt_passwd
tgt_authdb
tgt_schema
for t in tables:
mongodbexport -host 172.xx.xx.xx -port 27017 -u admin -p password -authdb admin -db xxxx -collection xxx | mongodbimport -host 172.yy.y.y -port xxxx -u admin -p xxxx -authdb -db xxx -collection xxx
### 常规备份恢复
src_ip
src_port
src_user
src_passwd
src_authdb
s3_addr/s3_folder
mongodbdump | zstd | s3cmd put s3://s3.hw.xxxx/dba-sox-backup/mongodb/集群名/yyyy-mm-dd-hh-mi.zstd
rclone mount
s3cmd get s3://s3.hw.xxxx | zstd -d | mongodbrestore
-
S3对象存储 百胜企业自建对象存储
二、mongodump/mongorestore
# 备份
mongodump -h 172.21.39.174 -u root -p 'root@Yumc' --port=27017 --authenticationDatabase sorder -d sorder -c 'preOrder|2024-01-24' -o /data/sorder.bak01
# 恢复
mongorestore -h 172.21.41.149 -u root -p 'root@Yumc' --authenticationDatabase sorder -d sorder -c 'preOrder|2024-01-24' /data/sorder.bak01/sorder/preOrder%7C2024-01-24.bson
说明:
-
mongorestore恢复的数据会覆盖mongo集群中已有的数据,恢复前记得一定要是空集群。
三、mongoexport/mongoimprot
# 备份
./mongoexport -u root -p 'root@Yumc' --authenticationDatabase=sorder -d sorder -c 'orderInfo|20240124' --type=json -o 'orderInfo|20240124.json'
# 恢复
./mongoimport -u root -p 'root@Yumc' --authenticationDatabase=sorder -d sorder -c 'orderInfo|20240124' --type=json --file 'orderInfo|20240124.json' -h 172.21.39.174
说明:
- mongoimport导数据进入mongo属于追加,不会覆盖已经存在的数据。