

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 在 Amazon OpenSearch Service 中建立索引快照
<a name="managedomains-snapshots"></a>

Amazon OpenSearch Service 中的快照是叢集的索引和狀態的備份。*狀態*包含叢集設定、節點資訊、索引設定和碎片分配。

OpenSearch Service 快照的形式如下：
+ **自動快照**僅適用叢集復原。如果發生紅色叢集狀態或資料遺失，您可以使用它們來還原您的網域。如需詳細資訊，請參閱下面的[還原快照](managedomains-snapshot-restore.md)。OpenSearch Service 會將自動快照存放在預先設定的 Simple Storage Service (Amazon S3) 儲存貯體，不另外收取費用。
+ **手動快照**適用於叢集復原，*或者*將資料從一個叢集移至另一個叢集。您必須初始化手動快照。這些快照會存放在您自己的 Simple Storage Service (Amazon S3) 儲存貯體中，而且需支付標準 S3 費用。如果您擁有自我管理 OpenSearch 叢集的快照，您可以使用該快照遷移至 OpenSearch Service 網域。如需詳細資訊，請參閱[遷移至 Amazon OpenSearch Service](migration.md)。

所有 OpenSearch Service 網域都會建立自動快照，但頻率在下列情況下不同：
+ 對於執行 OpenSearch 或 Elasticsearch 5.3 版和更新版本的網域，OpenSearch Service 會每隔 1 小時自動拍攝快照，且最多可保留其中 336 個快照 (連續保留 14 天)。由於每小時快照的增量改進性質，所以中斷較少。在發生網域問題時，它們還提供較新的復原點。
+ 對於執行 Elasticsearch 5.1 版和舊版的網域，OpenSearch Service 會每隔 1 天自動拍攝快照 (在您指定期間)，最多可保留其中 14 個快照，且不會保留任何快照資料超過 30 天。

如果您的叢集進入紅色狀態，所有自動快照都會失敗，而叢集狀態會持續存在。如果您未在兩週內修正該問題，則可能會永久遺失叢集中的資料。如需疑難排解步驟，請參閱[紅色叢集狀態](handling-errors.md#handling-errors-red-cluster-status)。

## 先決條件
<a name="managedomains-snapshot-prerequisites"></a>

若要手動建立快照，您必須使用 IAM 和 Simple Storage Service (Amazon S3)。嘗試拍攝快照之前，請先確認符合以下先決條件：


****  

| 先決條件  | Description | 
| --- | --- | 
| S3 bucket (S3 儲存貯體) | 建立 S3 儲存貯體以儲存 OpenSearch Service 網域的手動快照。如需說明，請參閱《*Amazon Simple Storage Service 使用者指南*》中的[建立一般用途儲存貯](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html)體。 請記住儲存貯體的名稱以在下列位置使用它：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/opensearch-service/latest/developerguide/managedomains-snapshots.html)  請勿將 Amazon Glacier 生命週期規則套用至此儲存貯體。手動快照不支援 Amazon Glacier 儲存類別。  | 
| IAM 角色 | 建立 IAM 角色以將許可委派給 OpenSearch Service。如需說明，請參閱 *IAM 使用者指南*中的[建立 IAM 角色 (主控台)](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-user.html#roles-creatingrole-user-console)。本章其餘各節稱此角色為 `TheSnapshotRole`。 **連接 IAM 政策** 將下列政策連接至 `TheSnapshotRole` 以允許存取 S3 儲存貯體： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/opensearch-service/latest/developerguide/managedomains-snapshots.html) 如需將政策連接至角色的指示，請參閱《[IAM 使用者指南》中的新增 IAM 身分許可 （主控台）](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html#add-policies-console)。 ** **編輯信任關係** 編輯 `TheSnapshotRole` 的信任關係，在 `Principal` 陳述式中指定 OpenSearch Service，如下例所示： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/opensearch-service/latest/developerguide/managedomains-snapshots.html) 如需編輯信任關係的指示，請參閱《*IAM 使用者指南*》中的[更新角色信任政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_update-role-trust-policy.html)。 | 
| 許可 |  為了註冊快照儲存庫，您需要能夠將 `TheSnapshotRole` 傳遞至 OpenSearch Service。您也需要存取 `es:ESHttpPut` 動作。若要授予這兩個許可，請將下列政策連接至其憑證用於簽署請求的 IAM 角色： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/opensearch-service/latest/developerguide/managedomains-snapshots.html) 如果您的使用者或角色沒有傳遞 的`iam:PassRole`許可`TheSnapshotRole`，當您在下一個步驟嘗試註冊儲存庫時，可能會遇到下列常見錯誤： <pre>$ python register-repo.py<br />{"Message":"User: arn:aws:iam::123456789012:user/MyUserAccount<br />is not authorized to perform: iam:PassRole on resource:<br />arn:aws:iam::123456789012:role/TheSnapshotRole"}</pre>  | 

## 刪除手動快照
<a name="managedomains-snapshot-delete"></a>

若要刪除手動快照，請執行以下命令：

```
DELETE _snapshot/repository-name/snapshot-name
```

## 使用索引狀態管理自動化快照
<a name="managedomains-snapshot-ism"></a>

您可以使用索引狀態管理 (ISM) [快照](https://opendistro.github.io/for-elasticsearch-docs/docs/im/ism/policies/#snapshot)操作，根據索引的存留期、大小或文件數量的變更自動觸發索引快照。當您需要每個索引一個快照時，ISM 是最佳的。如果您需要一組索引的快照，請參閱 [使用快照管理自動化快照](managedomains-snapshot-mgmt.md)。

若要在 OpenSearch Service 中使用 SM，您需要註冊自己的 Amazon S3 儲存庫。如需使用 `snapshot` 操作的範例 ISM 政策，請參閱[範例政策](ism.md#ism-example)。

## 使用 Curator 進行快照
<a name="managedomains-snapshot-curator"></a>

如果 ISM 不適用於索引和快照管理，您可以改用 Curator。其提供進階篩選功能，可協助簡化複雜叢集的管理任務。使用 [pip](https://pip.pypa.io/en/stable/installing/) 安裝 Curator。

```
pip install elasticsearch-curator
```

您可以使用 Curator 做為命令列界面 (CLI) 或 Python API。如果您使用 Python API，則必須使用版本 7.13.4 或更早版本的舊版 [elasticsearch-py](https://elasticsearch-py.readthedocs.io/) 用戶端。不支援 opensearch-py 用戶端。

如果您使用 CLI，在命令列匯出您的登入資料，並且設定 `curator.yml`，如下所示：

```
client:
  hosts: search-my-domain.us-west-1.es.amazonaws.com
  port: 443
  use_ssl: True
  aws_region: us-west-1
  aws_sign_request: True
  ssl_no_validate: False
  timeout: 60

logging:
  loglevel: INFO
```