elasticsearch

[Elasticsearch实战] snapshot 探索

2017-06-17  本文已影响251人  king_wang

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

下面我们通过一些用例来验证上面的几个观点:

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
# bin/hdfs dfs -du -h /user/eoi/elasticsearch
1.7 G  /user/eoi/elasticsearch/122_123_es-test

磁盘使用量也未增长。

这说明:snapshot是增量备份,对未发生变化的index重复备份几乎没有资源消耗。

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
}'
curl -XDELETE 'localhost:9200/_snapshot/hdfs_repository/snapshot_1
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产生影响。

上一篇下一篇

猜你喜欢

热点阅读