如何安全备份 Elasticsearch 数据?两种方案任你选

背景

有时候需要对 Elasticsearch 集群进行备份,或者恢复到其他集群。

方案

以下提供两种方案:使用 Elasticsearch 自带的 SNAPSHOT 快照机制,或者利用 elasticsearch-dump 工具完成。

使用快照与恢复功能

将索引数据备份到其他文件存储,恢复时先恢复快照,再恢复索引。

在 elasticsearch.yaml 配置快照存储路径。

yaml 复制代码
path.repo: ["/path/to/snapshot"]

注册快照存储库。

json 复制代码
PUT /_snapshot/my_backup
{
  "type": "fs",
  "settings": {
    "location": "/path/to/snapshot"
  }
}

创建快照。

json 复制代码
# 全量备份
PUT /_snapshot/my_backup/snapshot_cluster?wait_for_completion=true

# 按需备份
PUT /_snapshot/my_backup/snapshot_demo_index?wait_for_completion=true
{
  "indices": "demo_*",
  "ignore_unavailable": true
  "include_global_state": false.
  "metadata": {
    "author": "mengxiangge",
    "description": "backup before reindex"
  }
}

恢复快照。

json 复制代码
# 全量恢复
POST /_snapshot/my_backup/snapshot_cluster/_restore

# 按需恢复
POST /_snapshot/my_backup/snapshot_demo_index/_restore

使用 elasticsearch-dump 工具

elasticsearch-dump 是一个开源的命令行工具,用于将 Elasticsearch 索引数据导出为 JSON 文件,或将 JSON 文件导入 Elasticsearch 中。项目地址可以查阅链接

假设源数据节点为 10.2.0.1:9200,迁移到 10.2.1.1:9200。

bash 复制代码
# 迁移 Analyzer、Settings、Mapping
elasticdump --input=http://10.2.0.1:9200/my_index --output=http://10.2.1.1:9200/my_index --type=analyzer
elasticdump --input=http://10.2.0.1:9200/my_index --output=http://10.2.1.1:9200/my_index --type=settings
elasticdump --input=http://10.2.0.1:9200/my_index --output=http://10.2.1.1:9200/my_index --type=mapping

# 迁移数据
elasticdump --input=http://10.2.0.1:9200/my_index --output=http://10.2.1.1:9200/my_index --type=data
相关推荐
Elasticsearch10 小时前
一次编辑,更新所有仪表板:使用 Terraform 大规模管理 Kibana 可观测性配置
elasticsearch
Elasticsearch10 小时前
足够接近就是足够快:ES|QL Fast 模式如何让 Kibana 仪表板速度提升最高 100 倍
elasticsearch
Elasticsearch11 小时前
一分钟内从提示词生成仪表板,成本降低 5 倍:Kibana 中的 AI 仪表板和自定义 Vega-Lite 图表
elasticsearch
雾屿_Mistisle11 小时前
敏感文件泄露
大数据·elasticsearch·搜索引擎
Elasticsearch12 小时前
Elastic 9.5: Columnar 、 VectorDB 索引模式与自动校准,以及由 AI 驱动的告警分类整理
elasticsearch
晚安code12 小时前
一、Elasticsearch查询的 DSL 骨架:先把 JSON 看懂
elasticsearch
XS03010613 小时前
Git远程仓库实操笔记
笔记·git·elasticsearch
love530love13 小时前
Ubuntu系统通过Homebrew安装Lightpanda完整实战教程(含端口占用排坑)
大数据·linux·运维·人工智能·elasticsearch·搜索引擎
Elasticsearch1 天前
将 Embedding 模型加载到 Elasticsearch 中
elasticsearch
Elasticsearch1 天前
使用 Elasticsearch open inference API 对 OpenAI chat completions 进行支持
elasticsearch