---
title: Elasticsearch snapshot
tags: Elasticsearch
description: View the slide with "Slide Mode".
---
# Elasticsearch snapshot :moyai:
<!-- Put the link to this slide here so people can follow -->
## 用途
針對備份cluster裡面的資料,而cluster裡面的其他設定,像是cluster configuration跟 security configuration則要透過[其他方法](https://www.elastic.co/guide/en/elasticsearch/reference/7.3/backup-cluster.html)
[Snapshot and restore](https://www.elastic.co/guide/en/elasticsearch/reference/current/snapshot-restore.html#snapshot-restore)
>A snapshot is a backup taken from a running Elasticsearch cluster. You can take snapshots of<font color=red> individual indices or of the entire cluster</font>. Snapshots can be stored in either local or remote repositories. Remote repositories can reside on S3, HDFS, Azure, Google Cloud Storage, and other platforms supported by a <font color=red>repository</font> plugin.
>
><font color=red>Snapshots are incremental</font>: each snapshot of an index only stores data that is not part of an earlier snapshot. This enables you to take frequent snapshots with minimal overhead.
>[name=昱齊]<font color="#e06c75"> 可以用來做定期備份</font>
>You can restore snapshots to a running cluster with the restore API.<font color=red> By default, all indices</font> in the snapshot are restored. Alternatively, you can restore specific indices or restore the cluster state from a snapshot. When restoring indices, you can modify the index name and selected index settings.
>[name=昱齊]所有index,但應該沒包含elasticsearch.keystore、config、憑證
><font color=red>You must register a snapshot repository before you can take snapshots.</font>
>
>You can use <font color=red>snapshot lifecycle management</font> to automatically take and manage snapshots.
## Version compatibility
> A snapshot contains a copy of the on-disk data structures that make up an index. This means that snapshots can only be restored to versions of Elasticsearch that can read the indices:
>
><font color=red>A snapshot of an index created in 6.x can be restored to 7.x.</font>
A snapshot of an index created in 5.x can be restored to 6.x.
A snapshot of an index created in 2.x can be restored to 5.x.
A snapshot of an index created in 1.x can be restored to 2.x.
:::warning
:exclamation:When backing up your data prior to an upgrade, keep in mind that you won’t be able to restore snapshots after you upgrade if they contain indices created in a version that’s incompatible with the upgrade version.
:::
> 升版後,如果你的備份資料版本太舊,就沒辦法載回新的elasticsearch中
## 解決版本差太多
> If you end up in a situation where you need to restore a snapshot of an index that is incompatible with the version of the cluster you are currently running, you can restore it <font color=red>on the latest compatible version</font> and use [reindex-from-remote](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#reindex-from-remote) to rebuild the index on the current version. Reindexing from remote is only possible if the original index has source enabled. Retrieving and reindexing the data can take significantly longer than simply restoring a snapshot. If you have a large amount of data, we recommend testing the reindex from remote process with a subset of your data to understand the time requirements before proceeding.
>[name=昱齊]看起來是不斷往相容最新版本搬多次
### 一次多個index
- index能否用*選全部
- _all for all indices
- supports wildcards, 即*
- [multi-index](https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-index.html#multi-index)
不同版本(6.5.4-> 7.3.2),可以移轉嗎
> 不行,要先用rolling backup做更版
能移哪些資料
操作方式
1. 註冊 repository
https://medium.com/verybuy-dev/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8-elasticsearch-snapshot-%E5%8A%9F%E8%83%BD%E5%81%9A-migration-4fc463ce698c
---
參數
- `ignore_unavailable`
- Setting it to true will cause indices that <font color=blue>do not exist to be ignored </font>during snapshot creation
- `wait_for_completion`
---
- snapshot 狀態
- `incompatible`
- The snapshot was created with an old version of Elasticsearch and therefore is incompatible with the current version of the cluster.
>[name=昱齊]驚呆了,哪些會這樣
可以用snapshot做定期備份
- Snapshots are incremental: each snapshot of an index only stores data that is not part of an earlier snapshot.