欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 时评 > 【Elasticsearch】索引快照并还原到其他集群

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

2025/7/9 13:08:41 来源:https://blog.csdn.net/shen12138/article/details/139656210  浏览:    关键词:【Elasticsearch】索引快照并还原到其他集群

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

前提:es节点的所有用户id和组id都需要相同,最好在新建集群时指定用户id和组id,否则挂载后执行curl时会提示权限报错。
解决方法(gpt生成),不敢在生产尝试。
点我

一、安装共享文件系统

1.启动nfs
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

chown es.es /opt/public

查看状态

exportfs -rv

查看挂载源

showmount -a

二、ES配置

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

我这里配置的path.repo
path.repo: /home/elasticsearch-7.9.1/repository

mount -t nfs 192.168.113.101:/opt/public /home/elasticsearch-7.9.1/repository
2. 新建存储库
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”)
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"
}'

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词