日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ElasticSearch 快照 备份、恢复数据

發布時間:2024/8/23 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ElasticSearch 快照 备份、恢复数据 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

    • ElasticSearch 設置備份文件地址
    • 注冊快照存儲庫
    • 查看快照存儲庫保存結果
    • 創建快照
      • 異步創建
      • 指定索引進行快照
      • 查看全部快照
    • 在服務器查看備份的數據
    • 恢復數據
      • 本機恢復
      • 其他服務器恢復
    • 常見問題
      • 報錯 doesn't match any of the locations specified by path.repo because this setting is empty

ElasticSearch 設置備份文件地址

  • 在elasticsearch.yml 新增
path.repo: ["/home/es/snapshot"]

注冊快照存儲庫

ecopherebbs是我們定義的快照名,可以自定義

PUT _snapshot/ecopherebbs {"type": "fs","settings": {"location": "/home/es/snapshot"} }

保存成功

查看快照存儲庫保存結果

GET _snapshot

返回結果

{"ecopherebbs" : {"type" : "fs","settings" : {"compress": true,"location" : "/home/es/snapshot"}} }

創建快照

異步創建

  • 創建
PUT _snapshot/ecopherebbs/snapshot_20210631 {"ignore_unavailable": true,"include_global_state": true }
  • 查看狀態
GET _snapshot/ecopherebbs/snapshot_20210631

處理中

{"snapshots" : [{"snapshot" : "snapshot_20210631","uuid" : "PTBkWV-pQ8CQ7l4RNxISfA","version_id" : 7090399,"version" : "7.9.3","indices" : ["t_e_s_t___2_0_2_1_0_4_2_1_0_9_2_9_index","test0627","test110",".kibana-event-log-7.9.3-000001","fang_fa_index","filebeat-7.9.3-2021.06.29-000001","gateway_requests","my_index","ilm-history-2-000003",".kibana-event-log-7.9.3-000002",".kibana_1"],"data_streams" : [ ],"include_global_state" : true,"state" : "IN_PROGRESS","start_time" : "2021-06-30T05:26:10.530Z","start_time_in_millis" : 1625030770530,"end_time" : "1970-01-01T00:00:00.000Z","end_time_in_millis" : 0,"duration_in_millis" : 0,"failures" : [ ],"shards" : {"total" : 0,"failed" : 0,"successful" : 0}}] }

處理完成

{"snapshots" : [{"snapshot" : "snapshot_20210631","uuid" : "PTBkWV-pQ8CQ7l4RNxISfA","version_id" : 7090399,"version" : "7.9.3","indices" : ["t_e_s_t___2_0_2_1_0_4_2_1_0_9_2_9_index","test0627","test110",".kibana-event-log-7.9.3-000001","fang_fa_index","filebeat-7.9.3-2021.06.29-000001","gateway_requests","my_index","ilm-history-2-000003",".kibana-event-log-7.9.3-000002",".kibana_1"],"data_streams" : [ ],"include_global_state" : true,"state" : "SUCCESS","start_time" : "2021-06-30T05:26:10.530Z","start_time_in_millis" : 1625030770530,"end_time" : "2021-06-30T05:26:16.937Z","end_time_in_millis" : 1625030776937,"duration_in_millis" : 6407,"failures" : [ ],"shards" : {"total" : 200,"failed" : 0,"successful" : 200}}] }

指定索引進行快照

PUT _snapshot/ecopherebbs/snapshot_20210630?wait_for_completion=true {"indices": "index1,index2","ignore_unavailable": true,"include_global_state": true }
  • wait_for_completion=true時會一直阻塞直到快照完成,kibana執行時超時為30秒,超時后快照依然會在后臺執行
  • snapshot_20200729 就是指定的備份快照命中
  • 請求體重indices指定需要備份的索引(多個用逗號隔開),也可以不指定,這樣會備份所有的es索引庫數據
  • 查看全部快照

    GET _snapshot/ecopherebbs/_all?pretty

    在服務器查看備份的數據

    每次執行快照都會生成一個 meta和一個snap文件

    [es@test12 snapshot]$ ls -lrt 總用量 1404 drwxrwxr-x. 62 es es 4096 6月 30 13:23 indices -rw-rw-r--. 1 es es 460329 6月 30 13:24 meta--WCM58RpQNm5bEywCjO_cg.dat -rw-rw-r--. 1 es es 1596 6月 30 13:24 snap--WCM58RpQNm5bEywCjO_cg.dat -rw-rw-r--. 1 es es 1596 6月 30 13:26 snap-PTBkWV-pQ8CQ7l4RNxISfA.dat -rw-rw-r--. 1 es es 460329 6月 30 13:26 meta-PTBkWV-pQ8CQ7l4RNxISfA.dat -rw-rw-r--. 1 es es 302 6月 30 13:52 snap-N3zRMDnDTEqoiShEwjKosA.dat -rw-rw-r--. 1 es es 460329 6月 30 13:52 meta-N3zRMDnDTEqoiShEwjKosA.dat -rw-rw-r--. 1 es es 24990 6月 30 13:52 index-2 -rw-rw-r--. 1 es es 8 6月 30 13:52 index.latest

    恢復數據

    本機恢復

    POST _snapshot/ecopherebbs/snapshot_20210631_02/_restore

    執行恢復要將之前的索引刪除,否則會報錯

    • 或者在恢復時執行新索引名稱 官網描述
    POST /_snapshot/my_backup/snapshot_1/_restore {"indices": "index_1", "rename_pattern": "index_(.+)", "rename_replacement": "restored_index_$1" }

    其他服務器恢復

    注意:版本要相同,版本不同很有可能會導致失敗

  • 配置第一步設置的目錄
    path.repo: ["/home/es/snapshot"]
  • 創建倉庫
  • PUT _snapshot/ecopherebbs {"type": "fs","settings": {"location": "/home/es/snapshot-test"} }
  • 執行恢復索引
  • POST _snapshot/ecopherebbs/snapshot_20210631_02/_restore

    常見問題

    報錯 doesn’t match any of the locations specified by path.repo because this setting is empty

    {"error" : {"root_cause" : [{"type" : "repository_exception","reason" : "[ecopherebbs] location [/home/es/snapshot] doesn't match any of the locations specified by path.repo because this setting is empty"}],"type" : "repository_exception","reason" : "[ecopherebbs] failed to create repository","caused_by" : {"type" : "repository_exception","reason" : "[ecopherebbs] location [/home/es/snapshot] doesn't match any of the locations specified by path.repo because this setting is empty"}},"status" : 500 }
    • 解決方法:

    在為es集群環境做災備和恢復時候,首先需要創建創建一個倉庫,并往倉庫中存放快照(每個快照中會區分不同的索引)。但是在創建倉庫的時候,要求倉庫的地址必須在每個集群環境中的elasticsearch.yml中進行配置

    個人公眾號(大數據學習交流): hadoopwiki

    總結

    以上是生活随笔為你收集整理的ElasticSearch 快照 备份、恢复数据的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。