【Elasticsearch】索引快照并还原到其他集群

【Elasticsearch】索引快照并还原到其他集群

前提:es节点的所有用户id和组id都需要相同,最好在新建集群时指定用户id和组id,否则挂载后执行curl时会提示权限报错。

解决方法(gpt生成),不敢在生产尝试。
点我

一、安装共享文件系统

1.启动nfs
bash 复制代码
systemctl start nfs rpcbind
2. 编辑nfs文件

vi /etc/exports

/opt/public 192.168.113.0/24(rw,no_root_squash,insecure,sync)

3. 修改共享目录用户

比如elasticsearch使用的是es用户,用户权限这里要修改为es

bash 复制代码
chown es.es /opt/public

查看状态

bash 复制代码
exportfs -rv

查看挂载源

bash 复制代码
showmount -a

二、ES配置

1.各个节点挂载共享目录到repo指定目录,这里可不重启es

我这里配置的path.repo

path.repo: /home/elasticsearch-7.9.1/repository

bash 复制代码
mount -t nfs 192.168.113.101:/opt/public /home/elasticsearch-7.9.1/repository
2. 新建存储库
bash 复制代码
curl -u elastic -H 'Content-type: application/json' -XPUT 'http://192.168.113.101:9200/_snapshot/my_fs_backup' -d '{
 "type": "fs",
 "settings": {
  "location": "my_fs_backup_location"
 }
}'
3. 新建快照("metrics_38")
bash 复制代码
curl -u elastic -H 'Content-type: application/json' -XPUT 'http://192.168.113.101:9200/_snapshot/my_fs_backup/metrics_38?wait_for_completion=true' -d '{
 "indices": "metrics_38"
}'

可以快照所有索引,使用"-"可以剔除指定的索引index1和index2

{

"indices": "*,-index1,-index2"

}

4. 查看快照状态

curl -u elastic -H 'Content-type: application/json' -XGET 'http://192.168.113.101:9200/_snapshot/my_fs_backup/metrics_38'

5. 后台查看数据

#repo.data: /home/elasticsearch-7.9.1/repository

复制代码
cd /home/elasticsearch-7.9.1/repository/my_fs_backup_location
du -sh

三、还原到其他ES集群

索引名称不能冲突。

1. 拷贝文件到path.repo目录下
2. 在其他上还原es集群上,新建存储库
复制代码
curl -H 'Content-type: application/json' -XPUT 'http://127.0.0.1:9200/_snapshot/my_fs_backup' -d '{
 "type": "fs",
 "settings": {
  "location": "my_fs_backup_location"
 }
}'
4. 还原快照,等待green
复制代码
curl -H 'Content-type: application/json' -XPOST 'http://127.0.0.1:9200/_snapshot/my_fs_backup/metrics_38/_restore' -d '{
 "indices": "metrics_38",
 "rename_pattern": "(.+)"
}'
5. 批量还原
复制代码
curl -H 'Content-type: application/json' -XPOST 'http://192.168.113.195:9200/_snapshot/my_fs_backup/metrics_38/_restore' -d '{
 "indices": "*",
 "rename_pattern": "(.+)",
  "rename_replacement": "restored-$1"
}'
相关推荐
演艺大赏23 分钟前
RESTServer 起不来,日志只有一行:headerCacheSize 65536 exceeds maximum value of 65534
大数据·hadoop·hbase
Databend1 小时前
活动邀请函|AI 时代的湖仓实践,从应用场景到 Cloud Agent 上手
大数据·数据库·agent
新*2 小时前
520 万数据迁移实战:Elasticsearch 索引重建与"改名"的完整踩坑记录
python·mysql·elasticsearch·数据迁移
阿里云大数据AI技术17 小时前
云栖实录|倍思科技 × 阿里云:让VOC洞察从“生成报告”走向“业务可用”
人工智能·elasticsearch·agent
数字新视界17 小时前
数据中心DCIM管理系统助力提升机房管理效率与安全性
大数据·人工智能·物联网·信息与通信·动环监控系统
阿里云大数据AI技术18 小时前
孩子王基于阿里云Data Agent的智能体实践:300+Agent 覆盖400+业务场景
大数据·人工智能·agent
大雪冬至6860612588720 小时前
【一次 Elasticsearch 高基数聚合慢查询的定位与优化】
elasticsearch
武子康20 小时前
H3-World 扩展跳跃与开门:新动作怎样进入训练数据?
大数据·人工智能·算法
Elasticsearch21 小时前
Elasticsearch:如何使用 Connectors 接入数据到 Elastic Agent builder 里进行企业搜索
elasticsearch
软件技术NINI21 小时前
DeepSeek 大模型落地应用实战指南
大数据·人工智能