Try   HackMD

Elasticsearch snapshot實作 :moyai:

實作

Snapshot and restore

1. Register a snapshot repository

1.1 local repository

1.1.1 建立本地 repository

$ mkdir /tmp/es_repo $ chown -R elasticsearch:elasticsearch /tmp/es_repo

1.1.2 改elasticsearch.yml

path.repo: ["/tmp/es_repo"]

1.1.3 對 clsuter 設定

curl -X PUT "localhost:9200/_snapshot/my_backup?pretty" -H 'Content-Type: application/json' -d' { "type": "fs", "settings": { "location": "/tmp/es_repo" } } '

昱齊會出錯~ 一定要shared filesystem

1.2 google cloud storage

1.2.1 安裝套件並重啟服務

$ /usr/share/elasticsearch/bin/elasticsearch-plugin install repository-gcs
$ systemctl restart elasticsearch

1.2.2 gcs 官方教學

  1. 建立bucket -> 一個儲存單位
  2. 建立服務帳戶,並取得json 金鑰

1.2.3 將json金鑰放入elasticsearch-keystore,並重啟服務

$ /usr/share/elasticsearch/bin/elasticsearch-keystore add-file gcs.client.default.credentials_file /etc/elasticsearch/金鑰檔案.json

這邊只需要調整金鑰檔名即可

1.2.4 登記 repository

curl -u elastic -X PUT "localhost:9200/_snapshot/my_backup?pretty" -H 'Content-Type: application/json' -d' { "type": "gcs", "settings": { "bucket": "if_efk", "client": "default" } } '
  • 可調整的:my_backup、bucket後面接的是gcs上面設定的名稱

2. 建立快照

curl -u elastic -X PUT "localhost:9200/_snapshot/my_backup/snapshot_1?wait_for_completion=true&pretty" -H 'Content-Type: application/json' -d' { "indices": "test,.security-7", "ignore_unavailable": true, "include_global_state": false, "metadata": { "taken_by": "yq", "taken_because": "backup before upgrading" } } '

3. 還原快照

3.1 不設參數

curl -u elastic -X POST "localhost:9200/_snapshot/my_backup/snapshot_1/_restore?pretty"

3.2 設參數

curl -u elastic -X POST "localhost:9200/_snapshot/my_backup/snapshot_1/_restore?pretty" -H 'Content-Type: application/json' -d' { "indices": "test", "include_global_state": true } '

昱齊還有bug,暫時無法成功