[Elasticsearch實戰] snapshot 探索

Elasticsearch文檔里對于snapshot有如下描述:
The index snapshot process is incremental. In the process of making the index snapshot Elasticsearch analyses the list of the index files that are already stored in the repository and copies only files that were created or changed since the last snapshot.
這里說snapshot是增量備份的,每次snapshot,es會分析index文件,并且只備份增量部分。
我們從文檔中得到幾個觀點:

一:snapshot是增量備份,對未發生變化的index重復備份幾乎沒有資源消耗。

二: 刪除snapshot不會對其它snapshot產生影響。

下面我們通過一些用例來驗證上面的幾個觀點:

  • 步驟1: 創建第一個snapshot_1,備份索引logs-181998
curl -XPUT 'localhost:9200/_snapshot/hdfs_repository/snapshot_1?wait_for_completion=true' -d 
'{
  "indices": "logs-181998",
  "ignore_unavailable": true,
  "include_global_state": false
}'

查看耗時:

{
    "snapshot": {
        "snapshot": "snapshot_1",
        "uuid": "cMIZv6WORLOUoY64dHhw8w",
        "version_id": 5040199,
        "version": "5.4.1",
        "indices": [
            "logs-181998"
        ],
        "state": "SUCCESS",
        "start_time": "2017-06-16T06:50:28.869Z",
        "start_time_in_millis": 1497595828869,
        "end_time": "2017-06-16T06:50:46.975Z",
        "end_time_in_millis": 1497595846975,
        "duration_in_millis": 18106,
        "failures": [],
        "shards": {
            "total": 5,
            "failed": 0,
            "successful": 5
        }
    }
}

可以看到"duration_in_millis": 18106,18106毫秒,18秒。
查看hdfs磁盤使用量:

# bin/hdfs dfs -du -h /user/eoi/elasticsearch
1.7 G  /user/eoi/elasticsearch/122_123_es-test
  • 步驟2: 重復步驟1,創建第二個snapshot_2,備份索引同一個索引logs-181998。
    直接看耗時"duration_in_millis": 287,287毫秒,0.2秒。幾乎沒有耗時。
    查看hdfs磁盤使用量:
# bin/hdfs dfs -du -h /user/eoi/elasticsearch
1.7 G  /user/eoi/elasticsearch/122_123_es-test

磁盤使用量也未增長。

這說明:snapshot是增量備份,對未發生變化的index重復備份幾乎沒有資源消耗。

  • 步驟3:創建第三個snapshot_3,備份2個索引:索引logs-181998和logs-191998。
curl -XPUT 'localhost:9200/_snapshot/hdfs_repository/snapshot_3?wait_for_completion=true' -d 
'{
  "indices": "logs-181998,logs-191998",
  "ignore_unavailable": true,
  "include_global_state": false
}'
  • 注意:索引logs-181998已經被3個快照關聯過。

  • 步驟4:刪除第一個snapshot_1

curl -XDELETE 'localhost:9200/_snapshot/hdfs_repository/snapshot_1
  • 步驟5:從snapshot_3還原logs-181998
curl -XPUT 'localhost:9200/_snapshot/hdfs_repository/snapshot_3/_restore?wait_for_completion=true' -d 
'{
  "indices": "logs-181998",
  "ignore_unavailable": true,
  "include_global_state": false,
  "rename_pattern": "(.+)",
  "rename_replacement": "restored_$1"
}'

還原成功:

health status index                 uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   logs-181998           w7gmFSdRQOe52Rk2xUzQLw   5   0    2708736            0      338mb          338mb
green  open   restored_logs-181998  7dzT8MjsT666Tnzf_bHNgA   5   0    2708735            0      338mb          338mb

這說明:刪除snapshot不會對其它snapshot產生影響。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容