Elasticsearch利用快照數據遷移和災備

  面對多集羣的企業級複雜架構,準備一套備份集羣顯得很是重要,備份集羣在平時不參與讀寫操做,可是始終包含業務集羣的全部數據,在有業務集羣不能使用的時候,能夠直接經過切換Elasticsearch來完成災備效果,這篇文章寫的是跨集羣實現數據遷移和數據災備node


一.Snapshot And Restore說明vim

  快照是從正在運行的Elasticsearch集羣中獲取的備份。您能夠獲取單個索引或整個集羣的快照,並將其存儲在共享文件系統的存儲庫中bash

  快照能夠經過restore API恢復到正在運行的集羣中網絡


二.首先,你須要一個倉庫架構

vim conf/elasticsearch.yml
path.repo /data/backup

注意:這個目錄必須是一個網絡共享盤,如Nfs,Samba等


三.告訴Elasticsearch倉庫在哪裏app

PUT /_snapshot/my_backup #使用_snapshot API指定倉庫名稱
{
  "type": "fs",
  "settings": {
        "location": "my_backup_location" #指定倉庫位置
        "compress": true #壓縮Mappings和settings,不能壓縮數據
  }
}
GET /_snapshot/my_backup #獲取倉庫位置


四.準備好了就開始備份elasticsearch

PUT /_snapshot/my_backup/kuaizhao1?wait_for_completion=true

#wait_for_completion等待快照完成後再返回ide

1.返回以下字符串爲成功ui

{"snapshot":{"snapshot":"kuaizhao1,"uuid":"x3AXRHavTySEe2BpBhU_FQ","version_id":5060199,"version":"5.6.1","indices":["test-aop-2014.04","test-xtx-2020.05","test2-newlis-2020.05","test-xtx-2014.04"],"state":"
SUCCESS","start_time":"2020-05-28T06:58:09.818Z","start_time_in_millis":1590649089818,"end_time":"2020-05-28T06:58:10.258Z",
"end_time_in_millis":1590649090258,"duration_in_millis":440,"failures":[],"shards":{"total":8,"failed":0,"successful":8}}}


2.在備份倉庫/data/backup中生成以下文件this

-rw-rw-r-- 1 elk  elk   29 May 28 11:09 incompatible-snapshots
-rw-rw-r-- 1 elk  elk   275 May 28 11:03 index-0
-rw-rw-r-- 1 elk  elk   8 May 28 11:03 index.latest
drwxrwxr-x 6 elk  elk    4096 May 28 11:03 indices
-rw-rw-r-- 1 elk  elk   698 May 28 11:03 meta-RUiiWfeISgWFNrVfQ80sGw.dat
-rw-rw-r-- 1 elk  elk   232 May 28 11:03 snap-RUiiWfeISgWFNrVfQ80sGw.dat


五.增量備份,其實就是在倉庫裏再建一個快照

PUT /_snapshot/my_backup/kuaizhao2?wait_for_completion=true

#自動識別倉庫中其餘的快照信息,只對新增或更新的索引進行快照


六.把包含快照數據的網盤掛到另外一套集羣的任一節點

開始恢復快照

1.這是一套新的集羣,上面沒有其餘索引,沒有重名索引

POST _snapshot/my_backup/kuaizhao1/_restore

2.以前恢復過快照,或者上面有重名索引

POST test-xtx-2020.05/_close #先把要還原的索引關閉
POST _snapshot/my_backup/kuaizhao2/_restore
GET _cat/shards #還原成功後自動打開索引


七. 錯誤排查

RepositoryVerificationException[[backup5.28] a file written by master to the store [/data/backup] cannot be accessed on the node [{test1-2}{OZKGLppLRgy1cFdhiVrVGw}{5CgnmLyaS_yGLnxFx1Wrxg}{10.1.5.13}{10.1.5.13:9300}]. This might indicate that the store [/data/backup] is not shared between this node and the master node or that permissions on the store don't allow reading files written by the master node]

快照倉庫不能是本地目錄,只能是網絡共享盤

location [/data/backup] doesn't match any of the locations specified by path.repo because this setting is empty

要先在elasticsearch.yml中配置倉庫重啓後才能繼續

相關文章
相關標籤/搜索