elasticsearch备份恢复

备份恢复

备份恢复的总体流程

  1. elasticsearch.yaml中配置的备份路径,拷贝到新的机器上。

    bash 复制代码
    # 备份路径
    path.repo: ["/data/elasticsearch/snapshots/snapshot01","/data/elasticsearch/snapshots/snapshot02"]
  2. 将备份路径通过nfs挂载到新的集群实例的每个节点上

  3. 创建snapshot repo

    • 创建snapshot repo

      bash 复制代码
      esname=elastic
      espassword=xxxxxx
      curl -X PUT -H 'Content-Type: application/json' --user ${esname}:${espassword} -d @snapshot-repo.json  "http://localhost:9200/_snapshot/recover_repo" 
    • snapshot-repo.json

      如下所示, location为备份路径

      bash 复制代码
      {
          "type": "fs",
          "settings": {
              "compress": true,
              "location": "/data/els_backup_new"
          }
      }
  4. 从snapshot repo恢复数据

    bash 复制代码
    esname=elastic
    espassword=xxxxxx
    
    # close duplicated index
    # curl -X POST -H 'Content-Type: application/json' --user ${esname}:${espassword}  "http://localhost:9200/.security-7/_close"
    
    # snapshot的名字
    snapshot=snapshot_2024-11-05_01-00
    
    curl -X POST -H 'Content-Type: application/json' --user ${esname}:${espassword} -d @recover-settings.json  "http://localhost:9200/_snapshot/recover_repo/$snapshot/_restore?wait_for_completion=true" | python -m json.tool

    其中recover-settings.json:

    bash 复制代码
    {
    "indices": "*,-.*"
    }

    snapshot的名称可以通过以下接口获取:

    bash 复制代码
    esname=elastic
    espassword=xxxxx
    curl -X GET -H 'Content-Type: application/json' --user ${esname}:${espassword}  "http://localhost:9200/_snapshot/recover_repo" 
  5. 查看迁移进度

    bash 复制代码
    esname=elastic
    espassword=xxxx
    
    curl -X GET --user ${esname}:${espassword}   "http://localhost:9200/_recovery/" 

    响应输出格式为json,可以通过grep -v '100.0%'来查看未恢复完成的索引。

备份恢复成功输出

bash 复制代码
[portal@es-node1 tmp]$ bash recover-es-from-snapshot.sh 
{"acknowledged":true,"shards_acknowledged":false,"indices":{}}  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 27914  100 27914    0     0     61      0  0:07:37  0:07:30  0:00:07  7721
{
    "snapshot": {
        "indices": [
            // 恢复的索引
        ],
        "shards": {
            "failed": 0,
            "successful": 1714,
            "total": 1714
        },
        "snapshot": "snapshot_2024-11-05_01-00"
    }
}

备份恢复的常见问题:

索引冲突

bash 复制代码
[portal@es-node1 tmp]$ bash recover-es-from-snapshot.sh 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   743  100   743    0     0    354      0  0:00:02  0:00:02 --:--:--   354
{
    "error": {
        "reason": "[recover_repo:snapshot_2024-11-05_01-00/l_5Y6dxoSvGAhAHH5zjwGQ] cannot restore index [.security-7] because an open index with same name already exists in the cluster. Either close or delete the existing index or restore the index under a different name by providing a rename pattern and replacement name",
        "root_cause": [
            {
                "reason": "[recover_repo:snapshot_2024-11-05_01-00/l_5Y6dxoSvGAhAHH5zjwGQ] cannot restore index [.security-7] because an open index with same name already exists in the cluster. Either close or delete the existing index or restore the index under a different name by providing a rename pattern and replacement name",
                "type": "snapshot_restore_exception"
            }
        ],
        "type": "snapshot_restore_exception"
    },
    "status": 500
}

出现这种情况,需要把索引关闭:

bash 复制代码
esname=elastic
espassword=xxx
# 关闭索引
curl -X POST -H 'Content-Type: application/json' --user ${esname}:${espassword}  "http://localhost:9200/.security-7/_close"

其中.security-7是索引的名称

bash 复制代码
4.11.06-000001] failed on step [{"phase":"hot","action":"rollover","name":"check-rollover-ready"}]. Moving to ERROR step
java.lang.IllegalArgumentException: setting [index.lifecycle.rollover_alias] for index [.ds-.logs-deprecation.elasticsearch-default-2024.11.06-000001] is empty or not defined
	at org.elasticsearch.xpack.core.ilm.WaitForRolloverReadyStep.evaluateCondition(WaitForRolloverReadyStep.java:89) [x-pack-core-7.17.6.jar:7.17.6]
	at org.elasticsearch.xpack.ilm.IndexLifecycleRunner.runPeriodicStep(IndexLifecycleRunner.java:226) [x-pack-ilm-7.17.6.jar:7.17.6]
	at org.elasticsearch.xpack.ilm.IndexLifecycleService.triggerPolicies(IndexLifecycleService.java:418) [x-pack-ilm-7.17.6.jar:7.17.6]
	at org.elasticsearch.xpack.ilm.IndexLifecycleService.triggered(IndexLifecycleService.java:349) [x-pack-ilm-7.17.6.jar:7.17.6]
	at org.elasticsearch.xpack.core.scheduler.SchedulerEngine.notifyListeners(SchedulerEngine.java:186) [x-pack-core-7.17.6.jar:7.17.6]
	at org.elasticsearch.xpack.core.scheduler.SchedulerEngine$ActiveSchedule.run(SchedulerEngine.java:220) [x-pack-core-7.17.6.jar:7.17.6]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) [?:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]
	at java.lang.Thread.run(Thread.java:833) [?:?]
[2024-11-06T17:00:44,102][ERROR][o.e.x.i.IndexLifecycleRunner] [node-1] policy [ilm-history-ilm-policy] for index [.ds-ilm-history-5-2024.11.06-000001] failed on step [{"phase":"hot","action":"rollover","name":"check-rollover-ready"}]. Moving to ERROR step
java.lang.IllegalArgumentException: setting [index.lifecycle.rollover_alias] for index [.ds-ilm-history-5-2024.11.06-000001] is empty or not defined
	at org.elasticsearch.xpack.core.ilm.WaitForRolloverReadyStep.evaluateCondition(WaitForRolloverReadyStep.java:89) [x-pack-core-7.17.6.jar:7.17.6]
	at org.elasticsearch.xpack.ilm.IndexLifecycleRunner.runPeriodicStep(IndexLifecycleRunner.java:226) [x-pack-ilm-7.17.6.jar:7.17.6]
	at org.elasticsearch.xpack.ilm.IndexLifecycleService.triggerPolicies(IndexLifecycleService.java:418) [x-pack-ilm-7.17.6.jar:7.17.6]
	at org.elasticsearch.xpack.ilm.IndexLifecycleService.triggered(IndexLifecycleService.java:349) [x-pack-ilm-7.17.6.jar:7.17.6]
	at org.elasticsearch.xpack.core.scheduler.SchedulerEngine.notifyListeners(SchedulerEngine.java:186) [x-pack-core-7.17.6.jar:7.17.6]
	at org.elasticsearch.xpack.core.scheduler.SchedulerEngine$ActiveSchedule.run(SchedulerEngine.java:220) [x-pack-core-7.17.6.jar:7.17.6]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) [?:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]
	at java.lang.Thread.run(Thread.java:833) [?:?]
相关推荐
serendipity_hky7 分钟前
互联网大厂Java面试故事:核心技术栈与场景化业务问题实战解析
java·spring boot·redis·elasticsearch·微服务·消息队列·内容社区
howard200515 分钟前
实训云上搭建大数据集群
大数据·大数据集群·实训云
大模型服务器厂商23 分钟前
人形机器人的技术概况与算力支撑背景
大数据·人工智能
第二只羽毛35 分钟前
主题爬虫采集主题新闻信息
大数据·爬虫·python·网络爬虫
Elastic 中国社区官方博客1 小时前
ES|QL 在 9.2:智能查找连接和时间序列支持
大数据·数据库·人工智能·sql·elasticsearch·搜索引擎·全文检索
知秋正在9962 小时前
ElasticSearch服务端报错:FileSystemException: No space left on device
大数据·elasticsearch·搜索引擎
智元视界3 小时前
农业AI化:如何让一台无人机懂得“看天种地”?
大数据·人工智能·prompt·无人机·数字化转型·产业升级
Deepoch3 小时前
Deepoc-M 破局:半导体研发告别试错内耗
大数据·人工智能·数学建模·半导体·具身模型·deepoc
一个大专生的淘汰之路4 小时前
Elasticsearch 如何确保新增文档立即可见?
elasticsearch
金融小师妹4 小时前
基于NLP政策信号解析的联邦基金利率预测:美银动态调整12月降息概率至88%,2026年双降路径的强化学习模拟
大数据·人工智能·深度学习·1024程序员节