ES和MONGODB备份脚本

发布于:2025-02-11 ⋅ 阅读:(41) ⋅ 点赞:(0)

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


网站公告

今日签到

点亮在社区的每一天
去签到