如何安全备份 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
相关推荐
会员源码网2 小时前
交易所 K 线模块无法启动?核心源码排查位置与实战解决方案
网络·elasticsearch
Elastic 中国社区官方博客2 小时前
Jina Rerankers 为 Elastic 推理服务(EIS)带来了快速、多语言的重排序能力
大数据·人工智能·elasticsearch·搜索引擎·ai·全文检索·jina
Fanxt_Ja2 小时前
多线程之ES同步数据
java·大数据·elasticsearch·搜索引擎
历程里程碑3 小时前
Linux19 实现shell基本功能
linux·运维·服务器·算法·elasticsearch·搜索引擎·哈希算法
yqd66618 小时前
elasticsearch
大数据·elasticsearch·搜索引擎
Elastic 中国社区官方博客20 小时前
金融服务公司如何大规模构建上下文智能
大数据·人工智能·elasticsearch·搜索引擎·ai·金融·全文检索
好好沉淀1 天前
Elasticsearch 中批量更新文档(Update By Query)的标准写法
大数据·elasticsearch
小程故事多_801 天前
Elasticsearch ES 分词与关键词匹配技术方案解析
大数据·人工智能·elasticsearch·搜索引擎·aigc
念丶小宇1 天前
Git常用指令
大数据·git·elasticsearch
铭毅天下1 天前
Python 同时适配 Elasticsearch 与 Easysearch 实战复盘
大数据·elasticsearch·搜索引擎·全文检索