ES和MONGODB备份脚本

ES:

使用elasticdump备份:

###URL取svc: elasticsearch-masterd的 clusterip/9200

for item in (curl 'http://'URL'/_cat/indices' | awk '{print $3}' | grep -E "要备份的索引名称" )

do

echo mapping $item

elasticdump --input=http://$URL/$item --output=DIR/item'-mapping.json' --limit=1000 --type=mapping

echo settings $item

elasticdump --input=http://$URL/$item --output=DIR/item'-settings.json' --limit=1000 --type=settings

echo alias $item

elasticdump --input=http://$URL/$item --output=DIR/item'-alias.json' --type=alias

echo data $item

elasticdump --input=http://$URL/$item --output=DIR/item'-data.json' --limit=1000 --type=data

done

MONGODB:

使用mongodump备份全库数据

特别注意备份全库数据一定要在mongos 路由pod下进行,不要在分片的pod下进行;

1、进入mongos 路由pod执行全库备份命令

kubectl exec -it -n $namespace mongodb-mongodb-sharded-mongos-xxx -- /bin/bash

开始备份:mongodump --host mongodb-mongodb-sharded-headless --port 27017 \

-uroot -pkgclite \

--authenticationDatabase="admin" \

--out /tmp/backup

2、将备份的数据打包并拷贝到宿主机

cd /tmp

tar -zcvf mongodb_bakup.tar.gz backup

#退出容器:exit

kubectl cp -n {namepsace} {mongos路由pod名称}:/tmp/mongodb_bakup.tar.gz mongodb_bakup.tar.gz

相关推荐
曲幽5 小时前
FastAPI + PostgreSQL 实战:给应用装上“缓存”和“日志”翅膀
redis·python·elasticsearch·postgresql·logging·fastapi·web·es·fastapi-cache
AI全栈实验室12 天前
MongoDB迁移金仓踩了5个坑,最后一个差点回滚
mongodb
数据知道13 天前
MongoDB 元素查询运算符:使用 `$exists` 检查字段是否存在及处理缺失字段
数据库·mongodb
数据知道13 天前
MongoDB 批量写操作:`bulkWrite()` 在数据迁移与清洗中的高性能应用
数据库·mongodb
数据知道13 天前
MongoDB 数组更新操作符:`$push`、`$pull`、`$addToSet` 管理列表数据
数据库·mongodb
数据知道13 天前
MongoDB 更新操作符 `$set` 与 `$unset`:精准修改字段与删除字段
数据库·mongodb
数据知道13 天前
MongoDB 数值更新原子操作:`$inc` 实现点赞、计数器等高并发原子操作
数据库·算法·mongodb
数据知道14 天前
MongoDB 数组查询专项:`$all`、`$elemMatch` 与精确匹配数组的使用场景
数据库·mongodb
数据知道14 天前
MongoDB 正则表达式查询:在 MongoDB 中实现模糊搜索与索引优化陷阱
数据库·mongodb·正则表达式