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

背景

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

方案

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

使用快照与恢复功能

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

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

path.repo: ["/path/to/snapshot"]

注册快照存储库。

PUT /_snapshot/my_backup
{
  "type": "fs",
  "settings": {
    "location": "/path/to/snapshot"
  }
}

创建快照。

# 全量备份
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"
  }
}

恢复快照。

# 全量恢复
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。

# 迁移 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

梦想歌

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值