如何安全备份 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
相关推荐
小冷coding5 分钟前
【ES】 Elasticsearch在电商系统中的核心应用场景与实践案例
大数据·elasticsearch·搜索引擎
EndingCoder6 分钟前
高级项目:构建一个 CLI 工具
大数据·开发语言·前端·javascript·elasticsearch·搜索引擎·typescript
fen_fen43 分钟前
查询ES进程、端口,以及进程映射的端口
大数据·elasticsearch·搜索引擎
橙露1 小时前
日志分析与监控:ELK栈(Elasticsearch+Logstash+Kibana)搭建全流程指南
大数据·elk·elasticsearch
问君能有几多愁~1 天前
Git 上库流程培训文档
大数据·git·elasticsearch
TracyCoder1231 天前
MySQL 实战宝典(二):MySQL vs Elasticsearch 文本检索性能全方位对比
数据库·mysql·elasticsearch
TracyCoder1231 天前
后端架构基石:MySQL、ES、Redis 与 RabbitMQ 核心设计指南
mysql·elasticsearch·架构
南棱笑笑生1 天前
20260127让天启AIO-3576Q38开发板跑Rockchip瑞芯微原厂的Buildroot【linux-6.1内核】【使用天启Firefly的DTS】
linux·运维·elasticsearch·rockchip
小北方城市网1 天前
Elasticsearch 分布式检索生产级优化:从索引设计到查询性能
java·大数据·运维·redis·分布式·elasticsearch·搜索引擎
大志哥1231 天前
使用logstash和elasticsearch实现日志链路(一)
大数据·elasticsearch·搜索引擎