

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

# 共用 Amazon DocumentDB 叢集快照
<a name="backup_restore-share_cluster_snapshots"></a>

使用 Amazon DocumentDB，您可以透過下列方式共用手動叢集快照：
+ 共用手動叢集快照，無論是加密或未加密，都可讓授權 AWS 帳戶複製快照。
+ 共用手動叢集快照，無論是加密或未加密，都可讓授權 AWS 帳戶直接從快照還原叢集，而不是複製叢集並從中還原叢集。

**注意**  
若要共用自動化叢集快照，請複製自動化快照來建立手動叢集快照，然後共用該複本。此程序也適用於 AWS Backup 產生的資源。

您可以與其他最多 20 個 共用手動快照 AWS 帳戶。您也可以將未加密的手動快照以公有形式共用，讓所有 帳戶都可使用此快照。將快照以公有形式共用時，請確保不要在任何公有快照中包含您的私人資訊。

與其他 共用手動快照， AWS 帳戶並使用 AWS CLI 或 Amazon DocumentDB API 從共用快照還原叢集時，您必須指定共用快照的 Amazon Resource Name (ARN) 做為快照識別符。

## 共用加密快照
<a name="backup_restore-share_encrypted_snapshots"></a>

共用加密快照有下列限制：
+ 您無法將加密快照以公有形式共用。
+ 您無法共用已使用共用快照之帳戶的預設 AWS KMS 加密金鑰進行加密的快照。

請按照以下步驟共用加密的快照。

1. 與您想要能夠存取快照的任何帳戶共用用來加密快照的 AWS Key Management Service (AWS KMS) 加密金鑰。

   您可以將其他 AWS 帳戶新增至金鑰政策，以與其他帳戶共用 AWS KMS 加密 AWS KMS 金鑰。如需更新金鑰政策的詳細資訊，請參閱《 *AWS Key Management Service 開發人員指南*》中的[在 AWS KMS 中使用金鑰政策](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html)。有關建立金鑰政策的範例，請參閱本主題稍後的[建立 IAM 政策以允許複製加密快照](#backup_restore-share_encrypted_snapshots-create_key_policy)。

1. 使用 與其他帳戶共用加密快照 AWS CLI，[如下所示](#backup_restore-share_snapshots)。

### 允許存取 AWS KMS 加密金鑰
<a name="backup_restore-share_encrypted_snapshots-share_key_policy"></a>

若要 AWS 帳戶 讓另一個 複製從您的帳戶共用的加密快照，您與之共用快照的帳戶必須能夠存取加密快照的 AWS KMS 金鑰。若要允許另一個帳戶存取 AWS KMS 金鑰，請將 AWS KMS 金鑰的 AWS KMS 金鑰政策更新為您在金鑰政策中以委託人身分共用之帳戶的 ARN。然後允許 `kms:CreateGrant` 動作。

將 AWS KMS 加密金鑰的存取權授予帳戶後，若要複製加密快照，如果該帳戶還沒有加密快照，則必須建立 AWS Identity and Access Management (IAM) 使用者。此外，該帳戶也必須將 IAM 政策連接至該 IAM 使用者，以允許使用者使用您的 AWS KMS 金鑰複製加密快照。帳戶必須是 IAM 使用者，且由於 AWS KMS 安全限制，不能是根 AWS 帳戶 身分。

在下列金鑰政策範例中，使用者 123451234512 是 AWS KMS 加密金鑰的擁有者。使用者 123456789012 是共用金鑰的帳戶。此更新的金鑰政策可讓帳戶存取 AWS KMS 金鑰。它透過將使用者 123456789012 根 AWS 帳戶 身分的 ARN 作為政策的委託人，以及允許 `kms:CreateGrant`動作來執行此操作。

------
#### [ JSON ]

****  

```
{
    "Id": "key-policy-1",
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "Allow use of the key",
            "Effect": "Allow",
            "Principal": {"AWS": [
                "arn:aws:iam::123451234512:user/KeyUser",
                "arn:aws:iam::123456789012:root"
            ]},
            "Action": [
                "kms:CreateGrant",
                "kms:Encrypt",
                "kms:Decrypt",
                "kms:ReEncrypt*",
                "kms:GenerateDataKey*",
                "kms:DescribeKey"
            ],
            "Resource": "*"},
            {
            "Sid": "Allow attachment of persistent resources",
            "Effect": "Allow",
            "Principal": {"AWS": [
                "arn:aws:iam::123451234512:user/KeyUser",
                "arn:aws:iam::123456789012:root"
            ]},
            "Action": [
                "kms:CreateGrant",
                "kms:ListGrants",
                "kms:RevokeGrant"
            ],
            "Resource": "*",
            "Condition": {"Bool": {"kms:GrantIsForAWSResource": true}}
        }
    ]
}
```

------

### 建立 IAM 政策以允許複製加密快照
<a name="backup_restore-share_encrypted_snapshots-create_key_policy"></a>

當外部 AWS 帳戶 可以存取您的 AWS KMS 金鑰時，該帳戶的擁有者可以建立政策，以允許為帳戶建立的 IAM 使用者複製使用該 AWS KMS 金鑰加密的加密快照。

下列範例顯示可連接至 IAM 使用者 AWS 帳戶 123456789012 的政策。此政策可讓 IAM 使用者從帳戶 123451234512 複製共用快照，該帳戶已使用 us-west-2 `c989c1dd-a3f2-4a5d-8d96-e793d082ab26` 區域中的 AWS KMS 金鑰加密。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "AllowUseOfTheKey",
            "Effect": "Allow",
            "Action": [
                "kms:Encrypt",
                "kms:Decrypt",
                "kms:ReEncrypt*",
                "kms:GenerateDataKey*",
                "kms:DescribeKey",
                "kms:CreateGrant",
                "kms:RetireGrant"
            ],
            "Resource": ["arn:aws:kms:us-west-2:123451234512:key/c989c1dd-a3f2-4a5d-8d96-e793d082ab26"]
        },
        {
            "Sid": "AllowAttachmentOfPersistentResources",
            "Effect": "Allow",
            "Action": [
                "kms:CreateGrant",
                "kms:ListGrants",
                "kms:RevokeGrant"
            ],
            "Resource": ["arn:aws:kms:us-west-2:123451234512:key/c989c1dd-a3f2-4a5d-8d96-e793d082ab26"],
            "Condition": {
                "Bool": {
                    "kms:GrantIsForAWSResource": true
                }
            }
        }
    ]
}
```

------

如需更新金鑰政策的詳細資訊，請參閱《 *AWS Key Management Service 開發人員指南*》中的[在 中使用金鑰政策 AWS KMS](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html)。

## 共用快照
<a name="backup_restore-share_snapshots"></a>

您可以使用 或 共用 Amazon DocumentDB 手動叢集快照 ( AWS 管理主控台 或自動化快照的副本） AWS CLI：

------
#### [ Using the AWS 管理主控台 ]

若要使用 共用快照 AWS 管理主控台，請完成下列步驟：

1. 登入 AWS 管理主控台，並在 https：//[https://console.aws.amazon.com/docdb](https://console.aws.amazon.com/docdb) 開啟 Amazon DocumentDB 主控台。

1. 在導覽窗格中，選擇 **Snapshots (快照)**。

1. 選取您要共享的手動快照。

1. 在**動作**下拉式功能表中，選擇共用。

1. 為**資料庫快照可見**性選擇下列其中一個選項：
   + 如果來源未加密，請選擇**公**有，以允許所有 AWS 帳戶從手動快照還原叢集。或者，選擇**私有**以僅允許您指定的 AWS 帳戶從手動快照還原叢集。
**警告**  
如果您將**資料庫快照可見**性設定為**公開**，所有 AWS 帳戶都可以從手動快照還原叢集，並存取您的資料。請勿將任何包含私有資訊的手動叢集快照共享為**公**有。
   + 如果來源資料庫叢集已加密，**DB snapshot visibility (資料庫快照可見度)** 會設為 **Private (私有)**，因為加密快照無法以公有形式共用。
**注意**  
使用預設加密的快照 AWS KMS key 無法共用。

1. 針對**AWS 帳戶 ID**，輸入您要允許 從手動快照還原叢集的帳戶的帳戶 AWS 識別符，然後選擇**新增**。重複 以包含額外的 AWS 帳戶識別符，最多 20 個 AWS 帳戶。

   如果您在將 AWS 帳戶識別符新增至允許的帳戶清單時發生錯誤，您可以選擇不正確 AWS 帳戶識別符右側的**刪除**，將其從清單中刪除。  
![圖表：共用快照偏好設定](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/share-snapshot.png)

1. 為要允許還原手動快照的所有 AWS 帳戶新增識別符後，請選擇**儲存**以儲存變更。

------
#### [ Using the AWS CLI ]

若要使用 共用快照 AWS CLI，請使用 Amazon DocumentDB `modify-db-snapshot-attribute`操作。使用 `--values-to-add` 參數來新增 AWS 帳戶 有權還原手動快照IDs 清單。

下列範例允許兩個 AWS 帳戶 識別符 123451234512 和 123456789012 還原名為 的快照`manual-snapshot1`。這還會移除 `all` 屬性值，以將快照標記為私有。

針對 Linux、macOS 或 Unix：

```
aws docdb modify-db-cluster-snapshot-attribute \
    --db-cluster-snapshot-identifier sample-cluster-snapshot \
    --attribute-name restore \
    --values-to-add '["123451234512","123456789012"]'
```

針對 Windows：

```
aws docdb modify-db-cluster-snapshot-attribute ^
    --db-cluster-snapshot-identifier sample-cluster-snapshot ^
    --attribute-name restore ^
    --values-to-add '["123451234512","123456789012"]'
```

此操作的輸出將會如下所示。

```
{
    "DBClusterSnapshotAttributesResult": {
        "DBClusterSnapshotIdentifier": "sample-cluster-snapshot",
        "DBClusterSnapshotAttributes": [
            {
                "AttributeName": "restore",
                "AttributeValues": [
                    "123451234512",
                    "123456789012"
                ]
            }
        ]
    }
}
```

若要從清單中移除 AWS 帳戶 識別符，請使用 `--values-to-remove` 參數。下列範例可防止 AWS 帳戶 ID 123456789012 還原快照。

針對 Linux、macOS 或 Unix：

```
aws docdb modify-db-cluster-snapshot-attribute \
    --db-cluster-snapshot-identifier sample-cluster-snapshot \
    --attribute-name restore \
    --values-to-remove '["123456789012"]'
```

針對 Windows：

```
aws docdb modify-db-cluster-snapshot-attribute ^
    --db-cluster-snapshot-identifier sample-cluster-snapshot ^
    --attribute-name restore ^
    --values-to-remove '["123456789012"]'
```

此操作的輸出將會如下所示。

```
{
    "DBClusterSnapshotAttributesResult": {
        "DBClusterSnapshotIdentifier": "sample-cluster-snapshot",
        "DBClusterSnapshotAttributes": [
            {
                "AttributeName": "restore",
                "AttributeValues": [
                    "123451234512"
                ]
            }
        ]
    }
}
```

------