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是增量備份戴质,對未發(fā)生變化的index重復(fù)備份幾乎沒有資源消耗。
二: 刪除snapshot不會對其它snapshot產(chǎn)生影響。
下面我們通過一些用例來驗證上面的幾個觀點:
- 步驟1: 創(chuàng)建第一個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: 重復(fù)步驟1畸陡,創(chuàng)建第二個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是增量備份恶守,對未發(fā)生變化的index重復(fù)備份幾乎沒有資源消耗。
- 步驟3:創(chuàng)建第三個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已經(jīng)被3個快照關(guān)聯(lián)過。
步驟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