如何安全备份 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
相关推荐
AI逐月9 小时前
Git 彻底清除历史记录
大数据·git·elasticsearch
管理大亨14 小时前
ELK + Redis Docker 企业级部署落地方案
大数据·运维·elk·elasticsearch·docker·jenkins
悟空码字16 小时前
SpringBoot 整合 ElasticSearch,给搜索插上“光速翅膀”
java·后端·elasticsearch
Elasticsearch16 小时前
开始使用 Elastic Agent Builder 和 Strands Agents SDK
elasticsearch
AI逐月17 小时前
Git 停止追踪已提交文件问题
大数据·git·elasticsearch
_默_17 小时前
前端常用依赖归纳【vueuse\lodash-es\dayjs\bignumber】
大数据·前端·elasticsearch
raoxiaoya17 小时前
golang调用 elasticsearch 8,向量检索
开发语言·elasticsearch·golang
Elasticsearch17 小时前
亲爱的圣诞老人,这里有一点小小的帮助,献给圣诞节
elasticsearch
Haooog19 小时前
Elasticsearch (ES) 面试题清单(不定时更新)
大数据·elasticsearch·搜索引擎·面试
武子康1 天前
大数据-184 Elasticsearch Doc Values 机制详解:列式存储如何支撑排序/聚合/脚本
大数据·后端·elasticsearch