[Elasticsearch实战] snapshot 探索

0.19字数 405阅读 978

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产生影响。

推荐阅读更多精彩内容