

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

# 在 Amazon DocumentDB 中備份和還原
<a name="backup_restore"></a>

Amazon DocumentDB （與 MongoDB 相容） 會持續將您的資料備份至 Amazon Simple Storage Service (Amazon S3) 1-35 天，讓您可以快速還原至備份保留期間內的任何時間點。Amazon DocumentDB 也會擷取資料的自動快照，做為此持續備份程序的一部分。

**注意**  
這些是服務管理的 Amazon S3 儲存貯體，您將無法存取備份檔案。如果您想要控制自己的備份，請遵循[傾印、還原、匯入和匯出資料](https://docs.aws.amazon.com/documentdb/latest/developerguide/backup_restore-dump_restore_import_export_data.html)的指示。

如果要將備份資料保留超過備份保留期，您也可以建立叢集資料的手動快照。備份過程不會影響您的叢集效能。

本節討論 Amazon DocumentDB 中備份功能的使用案例，並說明如何管理 Amazon DocumentDB 叢集的備份。

**Topics**
+ [備份和還原：概念](backup_restore-nouns_verbs.md)
+ [了解 備份儲存體用量](backup_restore-understanding_backup_storage_usage.md)
+ [傾印、還原、匯入和匯出資料](backup_restore-dump_restore_import_export_data.md)
+ [叢集快照考量事項](backup_restore-cluster_snapshot_considerations.md)
+ [比較自動和手動快照](backup_restore-compare_automatic_manual_snapshots.md)
+ [建立手動叢集快照](backup_restore-create_manual_cluster_snapshot.md)
+ [複製叢集快照](backup_restore-copy_cluster_snapshot.md)
+ [共用叢集快照](backup_restore-share_cluster_snapshots.md)
+ [從叢集快照還原](backup_restore-restore_from_snapshot.md)
+ [還原至某個時間點](backup_restore-point_in_time_recovery.md)
+ [刪除叢集快照](backup_restore-delete_cluster_snapshot.md)

# 備份和還原：概念
<a name="backup_restore-nouns_verbs"></a>


| 名詞 | Description | API (動詞) | 
| --- | --- | --- | 
|  Backup retention period (備份保留期間)  |  在 1 到 35 天的期限內，您可以執行時間點還原。  |  `create-db-cluster` `modify-db-cluster` `restore-db-cluster-to-point-in-time`  | 
|  Amazon DocumentDB 儲存磁碟區  |  高可用性和高耐用性的儲存磁碟區，可透過三個可用區域以六種方式複寫資料。無論叢集中的執行個體數量為何，Amazon DocumentDB 叢集都非常耐用。  |  `create-db-cluster` `delete-db-cluster` | 
|  備份時段  |  1 天內建立自動快照的期間。  |  `create-db-cluster` `describe-db-cluster` `modify-db-cluster` | 
|  自動快照  |  屬於叢集完整備份的每日快照，並由 Amazon DocumentDB 中的連續備份程序自動建立。  |  `restore-db-cluster-from-snapshot` `describe-db-cluster-snapshot-attributes` `describe-db-cluster-snapshots` | 
|  手動快照  |  您手動建立的快照，可在超過備份保留期之後用來保留叢集的完整備份。  |  `create-db-cluster-snapshot` `copy-db-cluster-snapshot` `delete-db-cluster-snapshot` `describe-db-cluster-snapshot-attributes` `describe-db-cluster-snapshots` `modify-db-cluster-snapshot-attribute`  | 

# 了解 備份儲存體用量
<a name="backup_restore-understanding_backup_storage_usage"></a>

Amazon DocumentDB 備份儲存包含備份保留期間內的連續備份，以及保留期間內以外的手動快照。若要控制您的備份儲存用量，您可以降低備份保留間隔、移除不再需要的舊手動快照，或同時進行兩者。如需 Amazon DocumentDB 備份的一般資訊，請參閱 [在 Amazon DocumentDB 中備份和還原](backup_restore.md)。如需 Amazon DocumentDB 備份儲存的定價資訊，請參閱 [Amazon DocumentDB 定價](https://aws.amazon.com/documentdb/pricing/)。

若要控制您的成本，您可以監控連續備份和超出保留期的手動快照所消耗的儲存量。然後，您可以降低備份保留間隔，並移除不再需要的手動快照。

您可以使用 Amazon CloudWatch 指標 `TotalBackupStorageBilled`、 `SnapshotStorageUsed`和 `BackupRetentionPeriodStorageUsed`來檢閱和監控 Amazon DocumentDB 備份所使用的儲存量，如下所示：
+ `BackupRetentionPeriodStorageUsed` 表示目前用於儲存連續備份的備份儲存量。此指標值取決於叢集磁碟區的大小，以及您在保留期中所做的變更數。不過，為了方便計費，指標不會超過保留期內累積的叢集磁碟區大小。例如，如果您的叢集大小為 100 GiB，而保留期為兩天，則 `BackRetentionPeriodStorageUsed` 的最大值為 200 GiB (100 GiB\$1100 GiB)。

   
+ `SnapshotStorageUsed` 表示用於儲存在備份保留期外之手動快照的備份儲存量。在保留期內拍攝的手動快照不計入您的備份儲存。同樣地，自動快照不會計入您的備份儲存。每個快照的大小是您取得快照時的叢集磁碟區大小。`SnapshotStorageUsed` 值取決於您保留的快照數量和每個快照的大小。例如，假設您在保留期之外有一個快照，且叢集磁碟區在拍攝快照時的大小為 100 GiB。則 `SnapshotStorageUsed` 的數量為 100 GiB。

   
+ `TotalBackupStorageBilled` 表示 `BackupRetentionPeriodStorageUsed` 和 `SnapshotStorageUsed` 的總和，減去相當於叢集磁碟區一天大小的免費備份儲存量。例如，如果您的叢集大小為 100 GiB，您有一天的保留日，而且您在保留期間之外有一個快照，則 `TotalBackupStorageBilled`為 100 GiB (100 GiB ＋ 100 GiB - 100 GiB)。

   
+ 這些指標會針對每個 Amazon DocumentDB 叢集獨立計算。

您可以透過 CloudWatch 主控台監控 Amazon DocumentDB 叢集，並使用 CloudWatch 指標建置報告。 [CloudWatch ](https://console.aws.amazon.com/cloudwatch) 如需如何使用 CloudWatch 指標的詳細資訊，請參閱[監控 Amazon DocumentDB](monitoring_docdb.md)。

# 傾印、還原、匯入和匯出資料
<a name="backup_restore-dump_restore_import_export_data"></a>

您可以使用 `mongodump`、`mongoexport`、 `mongorestore`和 `mongoimport`公用程式，將資料移入和移出 Amazon DocumentDB 叢集。本節探討這些工具和組態的目的，以協助您達到更佳效能。

**Topics**
+ [`mongodump`](#backup_restore-dump_restore_import_export_data-mongodump)
+ [`mongorestore`](#backup_restore-dump_restore_import_export_data-mongorestore)
+ [`mongoexport`](#backup_restore-dump_restore_import_export_data-mongoexport)
+ [`mongoimport`](#backup_restore-dump_restore_import_export_data-mongoimport)
+ [教學課程](#backup_restore-dump_restore_import_export_data-tutorial)

## `mongodump`
<a name="backup_restore-dump_restore_import_export_data-mongodump"></a>

該 `mongodump` 公用程式建立 MongoDB 資料庫的二進位 (BSON) 備份。由於以二進位格式存放資料所達到的大小效率，因此`mongodump`工具是希望將其還原至 Amazon DocumentDB 叢集時，從來源 MongoDB 部署傾印資料的偏好方法。

根據您用來執行 命令的執行個體或機器上可用的資源，您可以使用 `--numParallelCollections`選項增加從預設 1 傾印的平行集合數目，`mongodump`以加速您的 。良好的經驗法則是從 Amazon DocumentDB 叢集主要執行個體上每個 vCPU 一個工作者開始。

**注意**  
我們建議使用 MongoDB 資料庫工具，包括適用於 Amazon DocumentDB 的 100.6.1 版。您可以在[此處](https://www.mongodb.com/download-center/database-tools/releases/archive)存取 MongoDB 資料庫工具下載。

### 範例使用方式
<a name="backup_restore-dump_restore_import_export_data-mongodump-example"></a>

以下是 Amazon DocumentDB 叢集中 `mongodump` 公用程式的範例用量`sample-cluster`。

```
mongodump --ssl \
    --host="sample-cluster.node.us-east-1.docdb.amazonaws.com:27017" \
    --collection=sample-collection \
    --db=sample-database \
    --out=sample-output-file \
    --numParallelCollections 4  \
    --username=sample-user \
    --password=abc0123 \
    --sslCAFile global-bundle.pem
```

## `mongorestore`
<a name="backup_restore-dump_restore_import_export_data-mongorestore"></a>

`mongorestore` 公用程式可讓您還原與 `mongodump` 公用程式一起建立的資料庫的二進位 (BSON) 備份。您可以在使用 `--numInsertionWorkersPerCollection` 選項還原期間，增加每個集合的工作者數目，提升還原效能 (預設為 1)。良好的經驗法則是從 Amazon DocumentDB 叢集主要執行個體上每個 vCPU 一個工作者開始。

### 範例使用方式
<a name="backup_restore-dump_restore_import_export_data-mongorestore-example"></a>

以下是 Amazon DocumentDB 叢集 中`mongorestore`公用程式的範例用量`sample-cluster`。

```
mongorestore --ssl \
    --host="sample-cluster.node.us-east-1.docdb.amazonaws.com:27017" \
    --username=sample-user \
    --password=abc0123 \
    --sslCAFile global-bundle.pem <fileToBeRestored>
```

## `mongoexport`
<a name="backup_restore-dump_restore_import_export_data-mongoexport"></a>

此`mongoexport`工具會將 Amazon DocumentDB 中的資料匯出為 JSON、CSV 或 TSV 檔案格式。`mongoexport` 工具是匯出需可人工或機器讀取之資料的偏好方法。

**注意**  
`mongoexport` 不直接支援平行匯出。不過，您可以藉由同時針對不同的集合執行多個 `mongoexport` 任務來提高效能。

### 範例使用方式
<a name="backup_restore-dump_restore_import_export_data-mongoexport-example"></a>

以下是 Amazon DocumentDB 叢集 中`mongoexport`工具的範例用量`sample-cluster`。

```
mongoexport --ssl \
    --host="sample-cluster.node.us-east-1.docdb.amazonaws.com:27017" \
    --collection=sample-collection \
    --db=sample-database \
    --out=sample-output-file \
    --username=sample-user \
    --password=abc0123 \
    --sslCAFile global-bundle.pem
```

## `mongoimport`
<a name="backup_restore-dump_restore_import_export_data-mongoimport"></a>

此`mongoimport`工具會將 JSON、CSV 或 TSV 檔案的內容匯入 Amazon DocumentDB 叢集。您可以使用 `-–numInsertionWorkers` 參數來平行化和加速匯入 (預設值為 1)。

### 範例使用方式
<a name="backup_restore-dump_restore_import_export_data-mongoimport-example"></a>

以下是 Amazon DocumentDB 叢集 中`mongoimport`工具的範例用量`sample-cluster`。

```
mongoimport --ssl \
    --host="sample-cluster.node.us-east-1.docdb.amazonaws.com:27017" \
    --collection=sample-collection \
    --db=sample-database \
    --file=<yourFile> \
    --numInsertionWorkers 4 \
    --username=sample-user \
    --password=abc0123 \
    --sslCAFile global-bundle.pem
```

## 教學課程
<a name="backup_restore-dump_restore_import_export_data-tutorial"></a>

下列教學課程說明如何使用 `mongodump`、`mongoexport`、 `mongorestore`和 `mongoimport`公用程式將資料移入和移出 Amazon DocumentDB 叢集。

1. **先決條件** — 開始之前，請確定已佈建 Amazon DocumentDB 叢集，而且您可以存取與叢集相同 VPC 中的 Amazon EC2 執行個體。如需詳細資訊，請參閱[使用 Amazon EC2 連線](connect-ec2.md)。

   為了能夠使用 mongo 公用程式工具，您必須在 EC2 執行個體中安裝 mongodb-org-tools 套件，如下所示。

   ```
   sudo yum install mongodb-org-tools-4.0.18
   ```

   由於 Amazon DocumentDB 預設使用 Transport Layer Security (TLS) 加密，因此您還必須下載 Amazon RDS 憑證授權機構 (CA) 檔案，以使用 mongo shell 進行連線，如下所示。

   ```
   wget https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem
   ```

1. **下載範例資料**：在本教學課程中，您將下載一些包含餐廳相關資訊的範例資料。

   ```
   wget https://raw.githubusercontent.com/ozlerhakan/mongodb-json-files/master/datasets/restaurant.json
   ```

1. **將範例資料匯入 Amazon DocumentDB ** — 由於資料採用邏輯 JSON 格式，您將使用 `mongoimport`公用程式將資料匯入 Amazon DocumentDB 叢集。

   ```
   mongoimport --ssl \ 
       --host="tutorialCluster.amazonaws.com:27017" \ 
       --collection=restaurants \
       --db=business \ 
       --file=restaurant.json \
       --numInsertionWorkers 4 \
       --username=<yourUsername> \
       --password=<yourPassword> \
       --sslCAFile global-bundle.pem
   ```

1. **使用 傾印資料 `mongodump` ** — 現在您的 Amazon DocumentDB 叢集中有資料，您可以使用 `mongodump`公用程式取得該資料的二進位傾印。

   ```
   mongodump --ssl \
       --host="tutorialCluster.us-east-1.docdb.amazonaws.com:27017"\
       --collection=restaurants \
       --db=business \
       --out=restaurantDump.bson \
       --numParallelCollections 4 \
       --username=<yourUsername> \
       --password=<yourPassword> \
       --sslCAFile global-bundle.pem
   ```

1. **捨棄`restaurants`集合** - 在還原`business`資料庫中的`restaurants`集合之前，您必須先捨棄該資料庫中已存在的集合，如下所示。

   ```
   use business
   ```

   ```
   db.restaurants.drop()
   ```

1. **使用 還原資料 `mongorestore`** — 使用步驟 3 資料的二進位傾印，您現在可以使用 `mongorestore`公用程式將資料還原至 Amazon DocumentDB 叢集。

   ```
   mongorestore --ssl \
       --host="tutorialCluster.us-east-1.docdb.amazonaws.com:27017" \
       --numParallelCollections 4 \
       --username=<yourUsername> \
       --password=<yourPassword> \
       --sslCAFile global-bundle.pem restaurantDump.bson
   ```

1. **使用 匯出資料 `mongoexport`** — 若要完成教學課程，請以 JSON 檔案的格式從叢集匯出資料，與您在步驟 1 中匯入的檔案不同。

   ```
   mongoexport --ssl \
       --host="tutorialCluster.node.us-east-1.docdb.amazonaws.com:27017" \
       --collection=restaurants \
       --db=business \
       --out=restaurant2.json \
       --username=<yourUsername> \
       --password=<yourPassword> \
       --sslCAFile global-bundle.pem
   ```

1. **驗證** — 您可以使用下列命令，驗證步驟 5 的輸出是否產生與步驟 1 相同的結果。

   ```
   wc -l restaurant.json
   ```

   從這個命令的輸出：

   ```
   2548 restaurant.json
   ```

   ```
   wc -l restaurant2.json
   ```

   從這個命令的輸出：

   ```
   2548 restaurant2.json
   ```

# 叢集快照考量事項
<a name="backup_restore-cluster_snapshot_considerations"></a>

Amazon DocumentDB 會在叢集的備份時段期間建立叢集的每日自動快照。Amazon DocumentDB 會根據您指定的備份保留期儲存叢集的自動快照。如有需要，您可將叢集復原至備份保留期間的任何時間點。在相同叢集的相同區域執行複製操作時，自動快照不會發生。

**Topics**
+ [備份儲存體](#backup_restore-backup_storage)
+ [備份時段](#backup_restore-backup_window)
+ [Backup retention period (備份保留期間)](#backup_restore-backup_retention_period)
+ [複製叢集快照加密](#backup_restore-encryption)

除了自動叢集快照，您也可以手動建立叢集快照。您可以複製自動與手動快照。如需詳細資訊，請參閱[建立手動叢集快照](backup_restore-create_manual_cluster_snapshot.md)及[複製 Amazon DocumentDB 叢集快照](backup_restore-copy_cluster_snapshot.md)。

**注意**  
您的叢集必須為*可用*狀態，才能建立自動快照。  
您無法共用 Amazon DocumentDB 自動化叢集快照。因應措施是，您可以藉由複製自動快照來建立手動快照，然後共用該複本。如需複製快照的詳細資訊，請參閱 [複製 Amazon DocumentDB 叢集快照](backup_restore-copy_cluster_snapshot.md)。如需從快照還原叢集的詳細資訊，請參閱 [從叢集快照還原](backup_restore-restore_from_snapshot.md)。

## 備份儲存體
<a name="backup_restore-backup_storage"></a>

每個 的 Amazon DocumentDB 備份儲存 AWS 區域 體是由備份保留期間所需的備份儲存體組成，其中包括該區域中的自動和手動叢集快照。預設備份保留期間為 1 天。如需備份儲存定價的詳細資訊，請參閱 [Amazon DocumentDB 定價](https://aws.amazon.com/documentdb/pricing/)。

刪除叢集時，所有自動快照將一併刪除，且無法復原。不過，刪除叢集時不會刪除手動快照。如果您選擇讓 Amazon DocumentDB 在刪除叢集之前建立最終快照 （手動快照），您可以使用最終快照來復原叢集。

如需快照與儲存的詳細資訊，請參閱 [了解 備份儲存體用量](backup_restore-understanding_backup_storage_usage.md)。

## 備份時段
<a name="backup_restore-backup_window"></a>

自動快照會每天在您偏好的備份時段內執行。如果快照需要的時間超過所分配的備份時段，備份會在時段結束後繼續執行直到完成。備份時段不可與每週叢集維護時段重疊。

如果您在建立叢集時未指定偏好的備份時段，Amazon DocumentDB 會指派預設的 30 分鐘備份時段。這個時段是根據與叢集區域相關聯的 8 小時時段內隨機選擇。您可以修改叢集來變更偏好的備份時段。如需詳細資訊，請參閱[修改 Amazon DocumentDB 叢集](db-cluster-modify.md)。


| 區域名稱 | 區域 | UTC 時間區塊 | 
| --- | --- | --- | 
| 美國東部 (俄亥俄) | us-east-2 | 03:00-11:00 | 
| 美國東部 (維吉尼亞北部) | us-east-1 | 03:00-11:00 | 
| 美國西部 (奧勒岡) | us-west-2 | 06:00-14:00 | 
| Africa (Cape Town) | af-south-1 | 03：00–11：00 | 
| 亞太地區 (香港) | ap-east-1 | 06:00-14:00 | 
| 亞太地區 (海德拉巴) | ap-south-2 | 06：30–14：30 | 
| 亞太地區 (馬來西亞) | ap-southeast-5 | 13:00-21:00 | 
| 亞太區域 (孟買) | ap-south-1 | 06:00-14:00 | 
| 亞太地區 (大阪) | ap-northeast-3 | 12：00-20：00 | 
| 亞太區域 (首爾) | ap-northeast-2 | 13:00-21:00 | 
| 亞太區域 (新加坡) | ap-southeast-1 | 14：00-22：00 | 
| 亞太地區 (悉尼) | ap-southeast-2 | 12：00-20：00 | 
| 亞太地區 (雅加達) | ap-southeast-3 | 08：00-16：00 | 
| 亞太地區 (墨爾本) | ap-southeast-4 | 11：00-19：00 | 
| 亞太區域 (泰國) | ap-southeast-7 | 15：00-23：00 | 
| 亞太區域 (東京) | ap-northeast-1 | 13:00-21:00 | 
| 加拿大 (中部) | ca-central-1 | 03:00-11:00 | 
| 中國 (北京) | cn-north-1 | 06:00-14:00 | 
| 中國 (寧夏) | cn-northwest-1 | 06:00-14:00 | 
| 歐洲 (法蘭克福) | eu-central-1 | 21：00-05：00 | 
| 歐洲 (蘇黎世) | eu-central-2 | 02：00-10：00 | 
| 歐洲 (愛爾蘭) | eu-west-1 | 22:00-06:00 | 
| 歐洲 (倫敦) | eu-west-2 | 22:00-06:00 | 
| 歐洲 (米蘭) | eu-south-1 | 02：00-10：00 | 
| Europe (Paris) | eu-west-3 | 23：59-07：29 | 
| 歐洲 (西班牙) | eu-south-2 | 02：00–10：00 | 
| Europe (Stockholm) | eu-north-1 | 04：00–12：00 | 
| 墨西哥 (中部) | mx-central-1 | 03:00-11:00 | 
| 中東 (阿拉伯聯合大公國) | me-central-1 | 05：00–13：00 | 
| 南美洲 (聖保羅) | sa-east-1 | 00：00-08：00 | 
| 以色列 (特拉維夫) | il-central-1 | 04：00-12：00 | 
| AWS GovCloud （美國東部） | us-gov-east-1 | 17：00-01：00 | 
| AWS GovCloud （美國西部） | us-gov-west-1 | 06:00-14:00 | 

## Backup retention period (備份保留期間)
<a name="backup_restore-backup_retention_period"></a>

備份保留期間是在自動刪除之前保留自動備份的天數。Amazon DocumentDB 支援 1–35 天的備份保留期。

您可以在建立叢集時設定備份保留期。如果您沒有明確設定備份保留期，則會為叢集指派預設的備份保留期 1 天。建立叢集之後，您可以使用 AWS 管理主控台 或 修改叢集，以修改備份保留期間 AWS CLI。如需詳細資訊，請參閱[修改 Amazon DocumentDB 叢集](db-cluster-modify.md)。

## 複製叢集快照加密
<a name="backup_restore-encryption"></a>

叢集和快照加密是以 KMS 加密金鑰為基礎。KMS 金鑰 ID 是 KMS 加密金鑰的 Amazon Resource Name (ARN)、KMS 金鑰識別符或 KMS 金鑰別名。

適用下列準則和限制：
+ 建立快照時，會從叢集推斷加密。如果叢集已加密，該叢集的快照會使用相同的 KMS 金鑰加密。如果叢集未加密，則快照不會加密。
+ 如果您從 Amazon Web Services 帳戶複製加密的叢集快照，您可以指定 的值`KmsKeyId`，以使用新的 KMS 加密金鑰來加密複本。如果您未指定 `KmsKeyId` 的值，則會使用與來源叢集快照相同的 KMS 金鑰來加密叢集快照的複本。
+ 如果您複製從另一個 Amazon Web Services 帳戶共用的加密叢集快照，則必須指定 的值`KmsKeyId`。
+ 若要將加密的叢集快照複製到另一個 Amazon Web Services 區域，請將 `KmsKeyId` 設定為您要用來加密目的地區域中叢集快照複本的 KMS 金鑰 ID。KMS 加密金鑰專屬於在其中建立的 Amazon Web Services 區域，您無法在另一個 Amazon Web Services 區域中使用來自某個 Amazon Web Services 區域的加密金鑰。
+ 如果您複製未加密的叢集快照並指定 `KmsKeyId` 參數的值，則會傳回錯誤。

# 比較自動和手動快照
<a name="backup_restore-compare_automatic_manual_snapshots"></a>

以下是 Amazon DocumentDB （與 MongoDB 相容） 自動和手動快照的主要功能。

**Amazon DocumentDB 自動快照具有下列主要功能：**
+ **自動快照命名** — 自動快照名稱遵循模式 `rds:<cluster-name>-yyyy-mm-dd-hh-mm`，`yyyy-mm-dd-hh-mm`代表快照建立的日期和時間。
+ **依排程自動建立** — 當您建立或修改叢集時，您可以將*備份保留期*設定為 1 到 35 天的整數值。根據預設，新叢集的備份保留期為 1 天。備份保留期定義自動刪除自動快照之前的保留天數。您無法在 Amazon DocumentDB 叢集上停用自動備份。

  除了設定備份保留期之外，您也可以設定*備份時段*，也就是一天中建立自動快照的期間。
+ **刪除自動快照** — 當您刪除自動快照的叢集時，會自動刪除快照。您無法手動刪除自動快照。
+ **增量 —** 在備份保留期間，會記錄資料庫更新，以便有變更的增量記錄。
+ **從自動快照還原** — 您可以使用 AWS 管理主控台 或 從自動快照還原 AWS CLI。當您使用 從快照還原時 AWS CLI，您必須在叢集*可用*後分別新增執行個體。
+ **共用** — 您無法共用 Amazon DocumentDB 自動化叢集快照。因應措施是，您可以藉由複製自動快照來建立手動快照，然後共用該複本。如需複製快照的詳細資訊，請參閱 [複製 Amazon DocumentDB 叢集快照](backup_restore-copy_cluster_snapshot.md)。如需從快照還原叢集的詳細資訊，請參閱 [從叢集快照還原](backup_restore-restore_from_snapshot.md)。
+ **您可以從備份保留期內的任何時間點還原** - 由於資料庫更新會遞增記錄，因此您可以將叢集還原至備份保留期內的任何時間點。

  當您使用 從自動快照或從point-in-time還原還原時 AWS CLI，您必須在叢集*可用*後分別新增執行個體。

**Amazon DocumentDB 手動快照具有下列主要功能：**
+ **隨需建立** — Amazon DocumentDB 手動快照是使用 Amazon DocumentDB 管理主控台或 隨需建立 AWS CLI。
+ **刪除手動快照** — 只有當您使用 Amazon DocumentDB 主控台或 明確刪除手動快照時，才會刪除手動快照 AWS CLI。當您刪除手動快照的叢集時，並不會刪除手動快照。
+ **完整備份** — 拍攝手動快照時，會建立並儲存叢集資料的完整備份。
+ **手動快照命名** — 您可以指定手動快照名稱。Amazon DocumentDB `datetime` 不會將戳記新增至名稱，因此如果您想要將該資訊包含在名稱中，則必須新增該資訊。
+ **從手動快照還原** — 您可以使用主控台或 從手動快照還原 AWS CLI。當您使用 從快照還原時 AWS CLI，您必須在叢集*可用*後分別新增執行個體。
+ **Service Quotas** — 每個 的手動快照上限為 100 個 AWS 區域。
+ **共用** — 您可以共用手動叢集快照，這些快照可由授權複製 AWS 帳戶。您可以共用加密或未加密的手動快照。如需複製快照的詳細資訊，請參閱 [複製 Amazon DocumentDB 叢集快照](backup_restore-copy_cluster_snapshot.md)。
+ **手動快照建立時，您會還原至** ：從手動快照還原時，您會在手動快照建立時還原至 。

  當您使用 從快照還原時 AWS CLI，您必須在叢集*可用*後分別新增執行個體。

# 建立手動叢集快照
<a name="backup_restore-create_manual_cluster_snapshot"></a>

您可以使用 AWS 管理主控台 或 建立手動快照 AWS CLI。建立快照所需的時間量因資料庫的大小而異。建立快照時，您必須執行下列作業：

1. 找出要備份的叢集。

1. 為您的快照命名。您稍後可用它來進行還原。

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

若要使用 建立手動快照 AWS 管理主控台，您可以遵循下列任一方法。

1. **方法 1：**

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

   1. 在導覽窗格中，選擇 **Snapshots** (快照)。
**提示**  
如果畫面左側沒有出現導覽窗格，請選擇頁面左上角的功能表圖示 (![\[Hamburger menu icon with three horizontal lines.\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/docdb-menu-icon.png))。

   1. 在 **Snapshots (快照)** 頁面選擇 **Create (建立)**。

   1. 在 **Create cluster snapshot (建立叢集快照)** 頁面：

      1. **叢集識別符** — 從叢集的下拉式清單中，選擇要建立快照的叢集。

      1. **快照識別符** — 輸入快照的名稱。

         快照命名限制條件：
         + 長度為 【1–255】 個字母、數字或連字號。
         + 第一個字元必須是字母。
         + 不能以連字號結尾，或包含兩個連續連字號。
         + 對於每個 AWS 區域每個帳戶的所有叢集 （跨 Amazon RDS、Amazon Neptune 和 Amazon DocumentDB)，必須是唯一的。

      1. 選擇**建立**。

1. **方法 2：**

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

   1. 在導覽窗格中，選擇**叢集**。
**提示**  
如果畫面左側沒有出現導覽窗格，請選擇頁面左上角的功能表圖示 (![\[Hamburger menu icon with three horizontal lines.\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/docdb-menu-icon.png))。

   1. 在 **Clusters (叢集)** 頁面，找到您要建立快照的叢集，並選擇叢集左側的按鈕。

   1. 在 **Actions (動作)** 功能表上，選擇 **Take snapshot (建立快照)**。

   1. 在 **Create cluster snapshot (建立叢集快照)** 頁面：

      1. **快照識別符** — 輸入快照的名稱。

         快照命名限制條件：
         + 長度為 【1–63】 個字母、數字或連字號。
         + 第一個字元必須是字母。
         + 不能以連字號結尾，或包含兩個連續連字號。
         + 對於每個 AWS 區域每個帳戶的所有叢集 （跨 Amazon RDS、Amazon Neptune 和 Amazon DocumentDB)，必須是唯一的。

      1. 選擇**建立**。

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

若要使用 建立叢集快照 AWS CLI，請使用 `create-db-cluster-snapshot`操作搭配下列參數。

**Parameters**
+ **--db-cluster-identifier** – 必要。您正在建立快照的叢集名稱。此叢集必須存在並且為*可用*。
+ **--db-cluster-snapshot-identifier** – 必要。您正在建立的手動快照名稱。

下列範例會為名為 `sample-cluster` 的叢集建立一個名為 `sample-cluster-snapshot` 的快照。

針對 Linux、macOS 或 Unix：

```
aws docdb create-db-cluster-snapshot \
    --db-cluster-identifier sample-cluster \
    --db-cluster-snapshot-identifier sample-cluster-snapshot
```

針對 Windows：

```
aws docdb create-db-cluster-snapshot ^
    --db-cluster-identifier sample-cluster ^
    --db-cluster-snapshot-identifier sample-cluster-snapshot
```

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

```
{
    "DBClusterSnapshot": {
        "AvailabilityZones": [
            "us-east-1a",
            "us-east-1b",
            "us-east-1c"
        ],
        "DBClusterSnapshotIdentifier": "sample-cluster-snapshot",
        "DBClusterIdentifier": "sample-cluster",
        "SnapshotCreateTime": "2020-04-24T04:59:08.475Z",
        "Engine": "docdb",
        "Status": "creating",
        "Port": 0,
        "VpcId": "vpc-abc0123",
        "ClusterCreateTime": "2020-01-10T22:13:38.261Z",
        "MasterUsername": "master-user",
        "EngineVersion": "4.0.0",
        "SnapshotType": "manual",
        "PercentProgress": 0,
        "StorageEncrypted": true,
        "KmsKeyId": "arn:aws:kms:us-east-1:<accountID>:key/sample-key",
        "DBClusterSnapshotArn": "arn:aws:rds:us-east-1:<accountID>:cluster-snapshot:sample-cluster-snapshot"
    }
}
```

------

# 複製 Amazon DocumentDB 叢集快照
<a name="backup_restore-copy_cluster_snapshot"></a>

在 Amazon DocumentDB 中，您可以在相同 AWS 區域 或不同的 中複製快照 AWS 區域。您也可以將共用快照複製到相同 AWS 區域 或不同的 帳戶中 AWS 區域。如需有關共用快照的詳細資訊，請參閱 [共用 Amazon DocumentDB 叢集快照](backup_restore-share_cluster_snapshots.md)。

**注意**  
Amazon DocumentDB 會根據您保留的備份和快照資料量，以及您保留資料的期間向您收費。如需與 Amazon DocumentDB 備份和快照相關聯之儲存體的詳細資訊，請參閱 [了解 備份儲存體用量](backup_restore-understanding_backup_storage_usage.md)。如需 Amazon DocumentDB 儲存體的定價資訊，請參閱 [Amazon DocumentDB 定價](https://aws.amazon.com/documentdb/pricing/)。

**Topics**
+ [複製共用快照](#backup_restore-copy_shared_cluster_snapshot)
+ [跨 複製快照 AWS 區域](#backup_restore-copy_snapshot_across_regions)
+ [限制](#backup_restore-copy_cluster_snapshot-limitations)
+ [處理加密](#backup_restore-copy_cluster_snapshot-handle_encryption)
+ [參數群組考量](#backup_restore-copy_cluster_snapshot-parameter_group_considerations)
+ [複製叢集快照](#backup_restore-copy_a_cluster_snapshot)

## 複製共用快照
<a name="backup_restore-copy_shared_cluster_snapshot"></a>

您可以複製其他 AWS 帳戶共用給您的快照。如果您要複製已從另一個 AWS 帳戶共用的加密快照，您必須能夠存取用來加密快照的 AWS KMS 加密金鑰。如需詳細資訊，請參閱[處理加密](#backup_restore-copy_cluster_snapshot-handle_encryption)。

## 跨 複製快照 AWS 區域
<a name="backup_restore-copy_snapshot_across_regions"></a>

當您將快照複製到與來源快照 AWS 區域 不同的 時 AWS 區域，每個複本都是完整快照。完整快照複本包含還原 Amazon DocumentDB 叢集所需的所有資料和中繼資料。

## 限制
<a name="backup_restore-copy_cluster_snapshot-limitations"></a>

以下是複製快照時的一些限制：
+ 如果您在目標快照變成可用之前刪除來源快照，則快照複製可能會失敗。刪除來源快照之前，請確認目標快照的狀態為 `AVAILABLE`。
+ 對於單一目的地區域，每一帳戶最多可有 5 個快照複製請求在進行中。
+ 根據 AWS 區域 涉及的內容和要複製的資料量，跨區域快照複本可能需要數小時才能完成。在某些情況下，可能會有來自指定來源的大量跨區域快照複製請求 AWS 區域。在這些情況下，Amazon DocumentDB 可能會將來自該來源的新跨區域複製請求 AWS 區域 放入佇列，直到某些進行中的複本完成為止。位於佇列中的複製請求不會顯示進度資訊。複製開始時才會顯示進度資訊。

## 處理加密
<a name="backup_restore-copy_cluster_snapshot-handle_encryption"></a>

您可以複製以 AWS KMS 加密金鑰所加密的快照。如果您複製加密快照，則快照的副本也必須加密。如果您在相同的 中複製加密快照 AWS 區域，您可以使用與原始快照相同的 AWS KMS 加密金鑰來加密複本，也可以指定不同的 AWS KMS 加密金鑰。如果您跨區域複製加密快照，則無法對副本使用與來源快照相同的 AWS KMS 加密金鑰，因為 AWS KMS 金鑰是區域特定的。反之，您必須在目的地 n AWS 區域中指定有效的 AWS KMS 金鑰。

在整個複製過程中來源快照仍會保持加密狀態。如需詳細資訊，請參閱[Amazon DocumentDB 中的資料保護](security.data-protection.md)。

**注意**  
對於 Amazon DocumentDB 叢集快照，您無法在複製快照時加密未加密的叢集快照。

## 參數群組考量
<a name="backup_restore-copy_cluster_snapshot-parameter_group_considerations"></a>

當您跨區域複製快照時，複本不包含原始 Amazon DocumentDB 叢集所使用的參數群組。當您還原快照以建立新的叢集時，該叢集會取得 AWS 區域 其建立所在 的預設參數群組。若要為新叢集提供與原始叢集相同的參數，您必須執行下列動作：

1. 在目的地中 AWS 區域，使用與原始[叢集相同的設定建立 Amazon DocumentDB 叢集參數群組](https://docs.aws.amazon.com/documentdb/latest/developerguide/cluster_parameter_groups-create.html)。如果新的 中已存在， AWS 區域您可以使用該項目。

1. 在目的地還原快照後 AWS 區域，請修改新的 Amazon DocumentDB 叢集，並從上一個步驟新增新的或現有的參數群組。如需詳細資訊，請參閱[修改 Amazon DocumentDB 叢集](db-cluster-modify.md)。

## 複製叢集快照
<a name="backup_restore-copy_a_cluster_snapshot"></a>

您可以使用 AWS 管理主控台 或 複製 Amazon DocumentDB 叢集 AWS CLI，如下所示。

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

若要使用 複製叢集快照 AWS 管理主控台，請完成下列步驟。此程序適用於在相同區域或 AWS 區域 跨區域中複製加密或未加密的叢集快照。

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

1. 在導覽窗格中，選擇**快照**，然後選擇您要複製之快照左側的按鈕。
**提示**  
如果畫面左側沒有出現導覽窗格，請選擇頁面左上角的功能表圖示 (![\[Hamburger menu icon with three horizontal lines.\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/docdb-menu-icon.png))。

1. 從 **Actions** (動作) 功能表中，選擇 **Copy** (複製)。

1. 在產生的**建立叢集快照複本**頁面中，完成**設定**區段。

   1. **目的地區域** — 選用。若要將叢集快照複製到不同的 AWS 區域，請 AWS 區域 針對**目的地區域**選擇該快照。

   1. **新快照識別符** — 輸入新快照的名稱。

      目標快照命名限制條件：
      + 不能是現有快照的名稱。
      + 長度為 【1-63】 個字母、數字或連字號。
      + 第一個字元必須是字母。
      + 不能以連字號結尾，或包含兩個連續連字號。
      + 對於每個區域每個 Amazon RDS、Neptune 和 Amazon DocumentDB 的所有叢集 AWS 帳戶，必須是唯一的。

   1. **複製標籤** — 若要將來源快照上擁有的任何標籤複製到快照複本，請選擇**複製標籤**。

1. 填妥 **Encryption-at-rest (靜態加密)** 部分。

   1. **靜態加密** — 如果您的快照未加密，您將無法使用這些選項，因為您無法從未加密的快照建立加密的副本。如果您的快照已加密，您可以變更靜態加密期間 AWS KMS key 使用的 。

      如需加密快照複本的詳細資訊，請參閱 [複製叢集快照加密](backup_restore-cluster_snapshot_considerations.md#backup_restore-encryption)。

      如需靜態加密的詳細資訊，請參閱 [加密靜態 Amazon DocumentDB 資料](encryption-at-rest.md)。

   1. **AWS KMS 金鑰** — 從下拉式清單中，選擇下列其中一項：
      + **（預設） aws/rds** — 帳戶號碼和 AWS KMS 金鑰 ID 會列在此選項後面。
      + **<some-key-name>** — 如果您建立金鑰，則會列出它並供您選擇。
      + **輸入金鑰 ARN** — 在 **ARN** 方塊中，輸入 AWS KMS 金鑰的 Amazon Resource Name (ARN)。ARN 的格式是 `arn:aws:kms:<region>:<accountID>:key/<key-id> `。

1. 若要製作所選快照的複本，請選擇 **Copy snapshot (複製快照)**。或者，您可以選擇**取消**，不複製快照。

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

若要使用 複製未加密的叢集快照 AWS CLI，請使用 `copy-db-cluster-snapshot`操作搭配下列參數。如果您要將快照複製到另一個快照 AWS 區域，請在要複製快照 AWS 區域 的 中執行 命令。
+ **--source-db-cluster-snapshot-identifier** – 必要。要製作複本之叢集快照的識別碼。叢集快照必須存在且位於可用狀態。如果您要將快照複製到另一個快照， AWS 區域 或要複製共用叢集快照，則此識別符必須是來源叢集快照的 ARN 格式。此參數不區分大小寫。
+ **--target-db-cluster-snapshot-identifier** – 必要。要從來源叢集快照建立之新叢集快照的識別碼。此參數不區分大小寫。

  目標快照命名限制條件：
  + 不能是現有快照的名稱。
  + 長度為 【1-63】 個字母、數字或連字號。
  + 第一個字元必須是字母。
  + 不能以連字號結尾，或包含兩個連續連字號。
  + 對於每個區域每個 Amazon RDS、Neptune 和 Amazon DocumentDB 的所有叢集 AWS 帳戶，必須是唯一的。
+ **--source-region** — 如果您要將快照複製到另一個快照 AWS 區域，請指定要從中複製加密叢集快照 AWS 區域 的 。

  如果您要將快照複製到另一個 AWS 區域 ，但未指定 `--source-region`，則必須改為指定 `pre-signed-url`選項。此`pre-signed-url`值必須是 URL，其中包含簽章第 4 版簽署的請求，以便在複製叢集快照 AWS 區域 的來源中呼叫`CopyDBClusterSnapshot`動作。若要進一步了解 `pre-signed-url`，請參閱 [ CopyDBClusterSnapshot](https://docs.aws.amazon.com/documentdb/latest/developerguide/API_CopyDBClusterSnapshot.html)。
+ **--kms-key-id** — 金鑰的 KMS 金鑰識別符，用於加密叢集快照的副本。

  如果您要將加密的叢集快照複製到另一個快照 AWS 區域，則需要此參數。您必須指定目的地的 KMS 金鑰 AWS 區域。

  如果您要在相同的 中複製加密叢集快照 AWS 區域，則 AWS KMS 金鑰參數為選用。叢集快照的副本會使用與來源叢集快照相同的 AWS KMS 金鑰加密。如果您想要指定用來加密複本的新 AWS KMS 加密金鑰，您可以使用此參數執行此操作。
+ **--copy-tags** — 選用。要複製的標籤和值。

若要在複製操作進行時取消複製操作，您可以刪除由 識別的目標叢集快照，`--target-db-cluster-snapshot-identifier`或在叢集快照處於**複製**狀態`TargetDBClusterSnapshotIdentifier`時刪除。

**Example**  
**範例 1：將未加密快照複製到相同的區域**  
下列 AWS CLI 範例會在 AWS 區域 與來源快照相同的 `sample-cluster-snapshot-copy`中建立`sample-cluster-snapshot`名為 的複本。建立副本時，原始快照的所有標籤會複製到快照副本。  
針對 Linux、macOS 或 Unix：  

```
aws docdb copy-db-cluster-snapshot \
    --source-db-cluster-snapshot-identifier sample-cluster-snapshot \
    --target-db-cluster-snapshot-identifier sample-cluster-snapshot-copy \
    --copy-tags
```
針對 Windows：  

```
aws docdb copy-db-cluster-snapshot ^
    --source-db-cluster-snapshot-identifier sample-cluster-snapshot ^
    --target-db-cluster-snapshot-identifier sample-cluster-snapshot-copy ^
    --copy-tags
```
此操作的輸出將會如下所示。  

```
{
    "DBClusterSnapshot": {
        "AvailabilityZones": [
            "us-east-1a",
            "us-east-1b",
            "us-east-1c"
        ],
        "DBClusterSnapshotIdentifier": "sample-cluster-snapshot-copy",
        "DBClusterIdentifier": "sample-cluster",
        "SnapshotCreateTime": "2020-03-27T08:40:24.805Z",
        "Engine": "docdb",
        "Status": "copying",
        "Port": 0,    
        "VpcId": "vpc-abcd0123",
        "ClusterCreateTime": "2020-01-10T22:13:38.261Z",
        "MasterUsername": "master-user",
        "EngineVersion": "4.0.0",
        "SnapshotType": "manual",
        "PercentProgress": 0,
        "StorageEncrypted": true,
        "KmsKeyId": "arn:aws:kms:us-east-1:111122223333:key/sample-key-id",
        "DBClusterSnapshotArn": "arn:aws:rds:us-east-1:111122223333:cluster-snapshot:sample-cluster-snapshot-copy",
        "SourceDBClusterSnapshotArn": "arn:aws:rds:us-east-1:111122223333:cluster-snapshot:sample-cluster-snapshot"
    }
}
```

**Example**  
**範例 2：跨 複製未加密的快照 AWS 區域**  
下列 AWS CLI 範例會建立具有 `sample-cluster-snapshot`ARN 的 複本`arn:aws:rds:us-east-1:123456789012:cluster-snapshot:sample-cluster-snapshot`。此副本名為 `sample-cluster-snapshot-copy`，位於執行命令的 AWS 區域 中。  
針對 Linux、macOS 或 Unix：  

```
aws docdb copy-db-cluster-snapshot \
    --source-db-cluster-snapshot-identifier arn:aws:rds:us-east-1:123456789012:cluster-snapshot:sample-cluster-snapshot \
    --target-db-cluster-snapshot-identifier sample-cluster-snapshot-copy
```
針對 Windows：  

```
aws docdb copy-db-cluster-snapshot ^
    --source-db-cluster-snapshot-identifier arn:aws:rds:us-east-1:123456789012:cluster-snapshot:sample-cluster-snapshot ^
    --target-db-cluster-snapshot-identifier sample-cluster-snapshot-copy
```
此操作的輸出將會如下所示。  

```
{
    "DBClusterSnapshot": {
        "AvailabilityZones": [
            "us-east-1a",
            "us-east-1b",
            "us-east-1c"
        ],
        "DBClusterSnapshotIdentifier": "sample-cluster-snapshot-copy",
        "DBClusterIdentifier": "sample-cluster",
        "SnapshotCreateTime": "2020-04-29T16:45:51.239Z",
        "Engine": "docdb",
        "AllocatedStorage": 0,
        "Status": "copying",
        "Port": 0,
        "VpcId": "vpc-abc0123",
        "ClusterCreateTime": "2020-04-28T16:43:00.294Z",
        "MasterUsername": "master-user",
        "EngineVersion": "4.0.0",
        "LicenseModel": "docdb",
        "SnapshotType": "manual",
        "PercentProgress": 0,
        "StorageEncrypted": false,
        "DBClusterSnapshotArn": "arn:aws:rds:us-east-1:123456789012:cluster-snapshot:sample-cluster-snapshot-copy",
        "SourceDBClusterSnapshotArn": "arn:aws:rds:us-east-1:123456789012:cluster-snapshot:sample-cluster-snapshot",
    }
}
```

**Example**  
**範例 3：跨 複製加密快照 AWS 區域**  
下列 AWS CLI 範例會建立`sample-cluster-snapshot`從 us-west-2 區域到 us-east-1 區域的 複本。此命令會在 us-east-1 區域中呼叫。  
針對 Linux、macOS 或 Unix：  

```
aws docdb copy-db-cluster-snapshot \
    --source-db-cluster-snapshot-identifier arn:aws:rds:us-west-2:123456789012:cluster-snapshot:sample-cluster-snapshot \
    --target-db-cluster-snapshot-identifier sample-cluster-snapshot-copy \
    --source-region us-west-2 \
    --kms-key-id sample-us-east-1-key
```
針對 Windows：  

```
aws docdb copy-db-cluster-snapshot ^
    --source-db-cluster-snapshot-identifier arn:aws:rds:us-west-2:123456789012:cluster-snapshot:sample-cluster-snapshot ^
    --target-db-cluster-snapshot-identifier sample-cluster-snapshot-copy ^
    --source-region us-west-2 ^
    --kms-key-id sample-us-east-1-key
```
此操作的輸出將會如下所示。  

```
{
    "DBClusterSnapshot": {  
        "AvailabilityZones": [],
        "DBClusterSnapshotIdentifier": "sample-cluster-snapshot-copy",
        "DBClusterIdentifier": "sample-cluster",
        "SnapshotCreateTime": "2020-04-29T16:45:53.159Z",
        "Engine": "docdb",
        "AllocatedStorage": 0,
        "Status": "copying",
        "Port": 0,
        "ClusterCreateTime": "2020-04-28T16:43:07.129Z",
        "MasterUsername": "chimera",
        "EngineVersion": "4.0.0",
        "LicenseModel": "docdb",
        "SnapshotType": "manual",
        "PercentProgress": 0,
        "StorageEncrypted": true,
        "KmsKeyId": "arn:aws:kms:us-east-1:123456789012:key/0846496a-d48e-41c4-9353-86d8301d7e35",
        "DBClusterSnapshotArn": "arn:aws:rds:us-east-1:123456789012:cluster-snapshot:sample-cluster-snapshot-copy",
        "SourceDBClusterSnapshotArn": "arn:aws:rds:us-west-2:123456789012:cluster-snapshot:sample-cluster-snapshot",
    }
}
```

**Example**  
**範例 4：跨 複製未加密的共用快照 AWS 區域**  
下列 AWS CLI 範例 帳戶 - `123456789012`會建立帳戶`sample-cluster-snapshot`共用的未加密叢集快照複本 - `999999999999` 從 us-east-1 區域到 us-west-2 區域。此命令會在 us-west-2 區域中呼叫。如需有關共用快照的詳細資訊，請參閱 [共用快照](backup_restore-share_cluster_snapshots.md#backup_restore-share_snapshots)。  
針對 Linux、macOS 或 Unix：  

```
aws docdb copy-db-cluster-snapshot \
--region us-west-2 \
--source-db-cluster-snapshot-identifier arn:aws:rds:us-east-1:999999999999:cluster-snapshot:sample-cluster-snapshot \
--target-db-cluster-snapshot-identifier sample-cluster-snapshot-copy
```
針對 Windows：  

```
aws docdb copy-db-cluster-snapshot ^
--region us-west-2 ^
--source-db-cluster-snapshot-identifier arn:aws:rds:us-east-1:999999999999:cluster-snapshot:sample-cluster-snapshot ^
--target-db-cluster-snapshot-identifier sample-cluster-snapshot-copy
```
此操作的輸出將會如下所示。  

```
{
 "DBClusterSnapshots": [
 {
 "AvailabilityZones": [],
 "DBClusterSnapshotIdentifier": "sample-cluster-snapshot-copy",
 "DBClusterIdentifier": "sample-cluster",
 "SnapshotCreateTime": "2025-08-22T11:27:00.497000+00:00",
 "Engine": "docdb",
 "Status": "copying",
 "Port": 0,
 "ClusterCreateTime": "2024-07-02T16:44:50.246000+00:00",
 "MasterUsername": "master-user",
 "EngineVersion": "5.0.0",
 "SnapshotType": "manual",
 "PercentProgress": 0,
 "StorageEncrypted": false,
 "DBClusterSnapshotArn": "arn:aws:rds:us-west-2:123456789012:cluster-snapshot:sample-cluster-snapshot-copy",
 "SourceDBClusterSnapshotArn": "arn:aws:rds:us-east-1:999999999999:cluster-snapshot:sample-cluster-snapshot"
 }
 ]
}
```

**Example**  
**範例 5：將加密的共用快照複製到 AWS 區域**  
下列 AWS CLI 範例，帳戶 - `123456789012`會建立帳戶`sample-cluster-snapshot`共用的加密叢集快照複本 - `999999999999` 從 us-east-1 區域到 us-west-2 區域。目標快照會使用客戶受管 KMS 金鑰 - 加密`arn:aws:kms:us-west-2:123456789012:key/6c1f3264-1797-472b-ba37-03011e682d28`。此命令會在 us-west-2 區域中呼叫。如需有關共用快照的詳細資訊，請參閱 [共用快照](backup_restore-share_cluster_snapshots.md#backup_restore-share_snapshots)。  
針對 Linux、macOS 或 Unix：  

```
aws docdb copy-db-cluster-snapshot \
--region us-west-2 \
--source-db-cluster-snapshot-identifier arn:aws:rds:us-east-1:999999999999:cluster-snapshot:sample-cluster-snapshot \
--target-db-cluster-snapshot-identifier sample-cluster-snapshot-copy \
--kms-key-id arn:aws:kms:us-west-2:123456789012:key/6c1f3264-1797-472b-ba37-03011e682d28
```
針對 Windows：  

```
aws docdb copy-db-cluster-snapshot ^
--region us-west-2 ^
--source-db-cluster-snapshot-identifier arn:aws:rds:us-east-1:999999999999:cluster-snapshot:sample-cluster-snapshot ^
--target-db-cluster-snapshot-identifier sample-cluster-snapshot-copy ^
--kms-key-id arn:aws:kms:us-west-2:123456789012:key/6c1f3264-1797-472b-ba37-03011e682d28
```
此操作的輸出將會如下所示。  

```
{
 "DBClusterSnapshots": [
 {
 "AvailabilityZones": [],
 "DBClusterSnapshotIdentifier": "sample-cluster-snapshot-copy",
 "DBClusterIdentifier": "sample-cluster",
 "SnapshotCreateTime": "2025-08-22T11:27:00.497000+00:00",
 "Engine": "docdb",
 "Status": "copying",
 "Port": 0,
 "ClusterCreateTime": "2024-07-02T16:44:50.246000+00:00",
 "MasterUsername": "master-user",
 "EngineVersion": "5.0.0",
 "SnapshotType": "manual",
 "PercentProgress": 0,
 "StorageEncrypted": true,
 "KmsKeyId": "arn:aws:kms:us-west-2:123456789012:key/6c1f3264-1797-472b-ba37-03011e682d28",
 "DBClusterSnapshotArn": "arn:aws:rds:us-west-2:123456789012:cluster-snapshot:sample-cluster-snapshot-copy",
 "SourceDBClusterSnapshotArn": "arn:aws:rds:us-east-1:999999999999:cluster-snapshot:sample-cluster-snapshot"
 }
 ]
}
```

**注意**  
如需加密快照複本的詳細資訊，請參閱 [複製叢集快照加密](backup_restore-cluster_snapshot_considerations.md#backup_restore-encryption)。  
如需靜態加密的詳細資訊，請參閱 [加密靜態 Amazon DocumentDB 資料](encryption-at-rest.md)。

------

# 共用 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 使用者 for AWS 帳戶 123456789012 的政策。此政策可讓 IAM 使用者從已在 `c989c1dd-a3f2-4a5d-8d96-e793d082ab26` us-west-2 區域中使用 AWS KMS 金鑰加密的帳戶 123451234512 複製共用快照。

------
#### [ 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://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"
                ]
            }
        ]
    }
}
```

------

# 從叢集快照還原
<a name="backup_restore-restore_from_snapshot"></a>

Amazon DocumentDB （與 MongoDB 相容） 會建立儲存磁碟區的叢集快照。您可以藉由從叢集快照進行還原來建立新叢集。還原叢集時，您需提供做為還原來源的叢集快照名稱，以及該還原所建立的新叢集名稱。您無法從快照還原到現有叢集，因為新叢集會在您還原時建立。

當您從叢集快照還原叢集時：
+ 這個動作只會還原叢集，而不會還原該叢集的執行個體。您必須呼叫 `create-db-instance` 動作，為還原的叢集建立執行個體，並且在 `--db-cluster-identifier` 中指定所還原叢集的識別碼。只有當叢集*可用*時，才可以建立執行個體。
+ 您無法將已加密的快照還原至未加密的叢集。不過，您可以透過指定 AWS KMS 金鑰，將未加密的快照還原至加密的叢集。
+ 若要從加密快照還原叢集，您必須能夠存取 AWS KMS 金鑰。

**注意**  
您無法將 3.6 叢集還原至 4.0 叢集，但可以從一個叢集版本遷移至另一個叢集版本。如需詳細資訊，請前往 [遷移至 Amazon DocumentDB](docdb-migration.md)。

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

下列程序說明如何使用 Amazon DocumentDB 管理主控台從叢集快照還原 Amazon DocumentDB 叢集。

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

1. 在導覽窗格中，選擇 **Snapshots (快照)**，找到您要用於還原至叢集的快照，並選擇其左側的按鈕。
**提示**  
如果畫面左側沒有出現導覽窗格，請選擇頁面左上角的功能表圖示 (![\[Hamburger menu icon with three horizontal lines.\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/docdb-menu-icon.png))。

1. 在**操作**功能表上，選擇 **Restore (還原)**。

1. 在 **Restore snapshot (還原快照)** 頁面，完成 **Configuration (組態設定)** 區段。

   1. **叢集識別符** — 新叢集的名稱。您可以接受 Amazon DocumentDB 提供的名稱，或輸入您偏好的名稱。Amazon DocumentDBsupplied的名稱格式為 `docdb-`加上 UTC 時間戳記；例如 `docdb-yyyy-mm-dd-hh-mm-ss`。

   1. **執行個體類別** — 新叢集的執行個體類別。您可以接受預設執行個體類別，或從下拉式清單中選擇執行個體類別。

   1. **執行個體數目** — 您希望使用此叢集建立的執行個體數目。您可以接受預設的 3 個執行個體 (1 個主要讀取/寫入和 2 個唯讀複本)，或從下拉式清單中選擇執行個體數目。

1. 針對**叢集儲存組態**，選擇儲存選項。
**注意**  
**Amazon DocumentDB I/O 最佳化**儲存組態僅適用於 Amazon DocumentDB 5.0 和 8.0 引擎版本。

1. 如果您滿意此叢集組態，請選擇 **Restore cluster (還原叢集)**，等待叢集還原。

1. 如果您想要變更某些組態，例如指定非預設的 Amazon VPC 或安全群組，請選擇從頁面左下角**顯示進階設定**，然後繼續執行下列步驟。

   1. 完成 **Network settings (網路設定)** 區段。
      + **Virtual Private Cloud (VPC)** — 接受目前的 VPC，或從下拉式清單中選擇 VPC。
      + **子網路群組** — 接受`default`子網路群組，或從下拉式清單中選擇一個。
      + **VPC 安全群組** — 接受`default (VPC)`安全群組，或從清單中選擇一個安全群組。

   1. 填寫 **Cluster options (叢集選項)** 區段。
      + **資料庫連接埠** — 接受預設連接埠 `27017`或使用向上或向下箭頭來設定您要用於應用程式連線的連接埠。

   1. 填寫 **Encryption (加密)** 區段。
      + **靜態加密** — 如果您的快照已加密，則無法使用這些選項。如果未加密，您可以選擇以下其中一項：
        + 若要加密所有叢集的資料，請選擇 **Enable encryption-at-rest (啟用靜態加密)**。如果您選擇此選項，則必須指定 KMS 金鑰。
        + 若不加密叢集的資料，請選擇 **Disable encryption-at-rest (停用靜態加密)**。如果選擇此選項，您會在加密區段完成。
      + **AWS KMS 金鑰** — 從下拉式清單中選擇下列其中一項：
        + **（預設） aws/rds** — 帳戶號碼和 AWS KMS 金鑰 ID 會列在此選項後面。
        + **客戶受管金鑰** — 只有在您在 AWS Identity and Access Management (IAM) 主控台中建立 IAM 加密金鑰時，才能使用此選項。您可以選擇金鑰加密您的叢集。
        + **輸入金鑰 ARN** — 在 **ARN** 方塊中，輸入 AWS KMS 金鑰的 Amazon Resource Name (ARN)。ARN 的格式是 `arn:aws:kms:<region>:<accountID>:key/<key-id>`。

   1. 完成 **Log exports (日誌匯出)** 區段。
      + **選取要發佈至 CloudWatch 的日誌類型** — 選擇下列其中一項：
        + **已啟用** — 讓您的叢集將 DDL 記錄匯出至 Amazon CloudWatch Logs。
        + **停用** — 防止您的叢集將 DDL 日誌匯出至 Amazon CloudWatch Logs。**Disabled (已停用)** 是預設值。
      + **IAM 角色** - 從清單中選擇 *RDS 服務連結角色*。

   1. 完成 **Tags (標籤)** 區段。
      + **新增標籤** — 在*金鑰*方塊中，輸入叢集的標籤名稱。在 *Value (值)* 方塊中，選擇性地輸入標籤值。標籤會與 AWS Identity and Access Management (IAM) 政策搭配使用，以管理對 Amazon DocumentDB 資源的存取，並控制可套用至資源的動作。

   1. 完成 **Deletion protection (刪除保護)** 區段。
      + **啟用刪除保護** — 保護叢集免於意外刪除。啟用此選項後，您無法刪除叢集。

1. 選擇 **Restore cluster (還原叢集)**。

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

若要使用 從快照還原叢集 AWS CLI，請使用 `restore-db-cluster-from-snapshot`操作搭配下列參數。如需詳細資訊，請參閱[RestoreDBClusterFromSnapshot](API_RestoreDBClusterFromSnapshot.md)。
+ **--db-cluster-identifier** – 必要。這項操作會建立的叢集名稱。執行此操作之前，該叢集名稱不可以存在。

  叢集命名限制條件：
  + 長度為 【1-63】 個字母、數字或連字號。
  + 第一個字元必須是字母。
  + 不能以連字號結尾，或包含兩個連續連字號。
  + 對於每個區域每個 Amazon RDS、Neptune 和 Amazon DocumentDB 的所有叢集 AWS 帳戶，必須是唯一的。
+ **--snapshot-identifier** – 必要。用來還原的快照名稱。此名稱的快照必須存在且位於*可用*狀態。
+ **--engine** – 必要。必須為 `docdb`。
+ **--storage-type standard \$1 iopt1** — 選用。預設：`standard`。
+ **--kms-key-id** — 選用。從未加密快照還原加密快照或加密叢集時要使用的 AWS KMS 金鑰識別符 ARN。提供 AWS KMS 金鑰 ID 會導致還原的叢集使用 AWS KMS 金鑰加密，無論快照是否已加密。

  `--kms-key-id` 的格式是 `arn:aws:kms:<region>:<accountID>:key/<key-id>`。如果您未指定 `--kms-key-id` 參數的值，會發生以下情況：
  + 如果 中的快照`--snapshot-identifier`已加密，則還原的叢集會使用用來加密快照的相同 AWS KMS 金鑰進行加密。
  + 如果 `--snapshot-identifier` 中的快照未加密，則不會加密已還原的叢集。

針對 Linux、macOS 或 Unix：

```
aws docdb restore-db-cluster-from-snapshot \
    --db-cluster-identifier sample-cluster-restore \
    --snapshot-identifier sample-cluster-snapshot \
    --engine docdb \
    --kms-key-id arn:aws:kms:us-east-1:123456789012:key/SAMPLE-KMS-KEY-ID
```

針對 Windows：

```
aws docdb restore-db-cluster-from-snapshot ^
    --db-cluster-identifier sample-cluster-restore ^
    --snapshot-identifier sample-cluster-snapshot ^
    --engine docdb ^
    --kms-key-id arn:aws:kms:us-east-1:123456789012:key/SAMPLE-KMS-KEY-ID
```

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

```
{
    "DBCluster": {
        "AvailabilityZones": [
            "us-east-1c",
            "us-east-1b",
            "us-east-1a"
        ],
        "BackupRetentionPeriod": 1,
        "DBClusterIdentifier": "sample-cluster-restore",
        "DBClusterParameterGroup": "default.docdb4.0",
        "DBSubnetGroup": "default",
        "Status": "creating",
        "Endpoint": "sample-cluster-restore.cluster-node.us-east-1.docdb.amazonaws.com",
        "ReaderEndpoint": "sample-cluster-restore.cluster-node.us-east-1.docdb.amazonaws.com",
        "MultiAZ": false,
        "Engine": "docdb",
        "EngineVersion": "4.0.0",
        "Port": 27017,
        "MasterUsername": "<master-user>",
        "PreferredBackupWindow": "02:00-02:30",
        "PreferredMaintenanceWindow": "tue:09:50-tue:10:20",
        "DBClusterMembers": [],
        "VpcSecurityGroups": [
            {                             
                "VpcSecurityGroupId": "sg-abcdefgh",
                "Status": "active"
            }
        ],               
        "HostedZoneId": "ABCDEFGHIJKLM",
        "StorageEncrypted": true,
        "KmsKeyId": "arn:aws:kms:us-east-1:<accountID>:key/<sample-key-id>",
        "DbClusterResourceId": "cluster-ABCDEFGHIJKLMNOPQRSTUVWXYZ",
        "DBClusterArn": "arn:aws:rds:us-east-1:<accountID>:cluster:sample-cluster-restore",
        "AssociatedRoles": [],
        "ClusterCreateTime": "2020-04-01T01:43:40.871Z",
        "DeletionProtection": true
    }
}
```

當叢集狀態*可用*時，為叢集至少建立一個執行個體。

針對 Linux、macOS 或 Unix：

```
aws docdb create-db-instance \
    --db-cluster-identifier sample-cluster-restore  \
    --db-instance-identifier sample-cluster-restore-instance \
    --availability-zone us-east-1b \
    --promotion-tier 2 \
    --db-instance-class db.r5.large \
    --engine docdb
```

針對 Windows：

```
aws docdb create-db-instance ^
    --db-cluster-identifier sample-cluster-restore  ^
    --db-instance-identifier sample-cluster-restore-instance ^
    --availability-zone us-east-1b ^
    --promotion-tier 2 ^
    --db-instance-class db.r5.large ^
    --engine docdb
```

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

```
{
    "DBInstance": {
        "DBInstanceIdentifier": "sample-cluster-restore-instance",
        "DBInstanceClass": "db.r5.large",
        "Engine": "docdb",
        "DBInstanceStatus": "creating",
        "PreferredBackupWindow": "02:00-02:30",
        "BackupRetentionPeriod": 1,
        "VpcSecurityGroups": [
            {
                "VpcSecurityGroupId": "sg-abcdefgh",
                "Status": "active"
            }
        ],
        "AvailabilityZone": "us-west-2b",
        "DBSubnetGroup": {
            "DBSubnetGroupName": "default",
            "DBSubnetGroupDescription": "default",
            "VpcId": "vpc-6242c31a",
            "SubnetGroupStatus": "Complete",
            "Subnets": [
                {
                    "SubnetIdentifier": "subnet-abcdefgh",
                    "SubnetAvailabilityZone": {
                        "Name": "us-west-2a"
                    },
                    "SubnetStatus": "Active"
                },
                {
                    ...
                }
            ]
        },
        "PreferredMaintenanceWindow": "fri:09:43-fri:10:13",
        "PendingModifiedValues": {},
        "EngineVersion": "4.0.0",
        "AutoMinorVersionUpgrade": true,
        "PubliclyAccessible": false,
        "DBClusterIdentifier": "sample-cluster-restore",
        "StorageEncrypted": true,
        "KmsKeyId": "arn:aws:kms:us-east-1:<accountID>:key/<sample-key-id>",
        "DbiResourceId": "db-ABCDEFGHIJKLMNOPQRSTUVWXYZ",
        "CACertificateIdentifier": "rds-ca-2019",
        "PromotionTier": 2,
        "DBInstanceArn": "arn:aws:rds:us-east-1:<accountID>:db:sample-cluster-restore-instance"
    }
}
```

------

# 還原至某個時間點
<a name="backup_restore-point_in_time_recovery"></a>

您可以使用 AWS 管理主控台 或 AWS Command Line Interface () 將叢集還原至叢集備份保留期間內的任何時間點AWS CLI。

**注意**  
 您無法將 point-in-time還原至 4.0 叢集，但可以從一個叢集版本遷移至另一個叢集版本。如需詳細資訊，請前往 [遷移至 Amazon DocumentDB](docdb-migration.md)。

將叢集還原至某個時間點時，請謹記下列事項。
+ 除非是以預設的參數群組建立新叢集，否則會以與來源叢集相同的組態建立新叢集。若要將新叢集的參數群組設為來源叢集的參數群組，請在叢集狀態變為「可用」**後修改它。如需修改叢集的詳細資訊，請參閱 [修改 Amazon DocumentDB 叢集](db-cluster-modify.md)。

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

您可以藉由使用 AWS 管理主控台完成下列項目，以將叢集還原至其備份保留期間內的某個時間點。

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

1. 在導覽窗格中，選擇**叢集**。在叢集清單中，選擇您要還原之叢集左側的按鈕。
**提示**  
如果畫面左側沒有出現導覽窗格，請選擇頁面左上角的功能表圖示 (![\[Hamburger menu icon with three horizontal lines.\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/docdb-menu-icon.png))。

1. 在 **Actions (動作)** 功能表中，選擇 **Restore to point in time (還原至時間點)**。

1. 填妥 **Restore time (還原時間)** 部分，這裡指定還原的日期和時間。

   1. **還原日期** - 選擇或輸入**最早還原時間和****最晚還原時間**之間的日期。

   1. **還原時間** - 選擇或輸入**最早還原時間和****最晚還原時間**之間的小時、分鐘和秒數。

1. 填妥 **Configuration (組態)** 部分。

   1. **叢集識別符** — 接受預設識別符，或輸入您偏好的識別符。

      叢集命名限制條件：
      + 長度為 【1-63】 個字母、數字或連字號。
      + 第一個字元必須是字母。
      + 不能以連字號結尾，或包含兩個連續連字號。
      + 對於每個區域每個 Amazon RDS、Neptune 和 Amazon DocumentDB 的所有叢集 AWS 帳戶，必須是唯一的。

   1. **執行個體類別** — 從下拉式清單中，選擇您要用於叢集執行個體的執行個體類別。

   1. **執行個體數量** — 從下拉式清單中，選擇您要在叢集還原時建立的執行個體數量。

1. 針對**叢集儲存組態**，選擇儲存選項。
**注意**  
**Amazon DocumentDB I/O 最佳化**儲存組態僅適用於 Amazon DocumentDB 5.0 和 8.0 引擎版本。

1. 選用。若要設定網路設定、叢集選項並啟用日誌匯出，請選擇 **Show advanced settings (顯示進階設定)**，然後完成下列區段。否則，請繼續至下一個步驟。
   + **Network settings (網路設定)**

     1. **Virtual Private Cloud (VPC)** — 從下拉式清單中，選擇您要用於此叢集的 VPC。

     1. **子網路群組** — 從下拉式清單中，選擇此叢集的子網路群組。

     1. **VPC 安全群組** — 從下拉式清單中，選擇此叢集的 VPC 安全群組。

      
   + **Cluster options (叢集選項)**

     1. **連接埠** — 接受預設連接埠 (27017)，或使用向上和向下箭頭設定連接埠以與此叢集通訊。

      
   + **Log exports (日誌匯出)**

     1. **稽核日誌** — 選取此選項可啟用將稽核日誌匯出至 Amazon CloudWatch Logs。如果您選取此選項，則必須在叢集的自訂參數群組中啟用 `audit_logs`。如需詳細資訊，請參閱[稽核 Amazon DocumentDB 事件](event-auditing.md)。

     1. **Profiler 日誌** — 選取此選項可啟用將操作 Profiler 日誌匯出至 Amazon CloudWatch Logs。如果您選取此選項，則還必須在叢集的自訂參數群組中修改下列參數：
        + `profiler` — 設定為 `enabled`。
        + `profiler_threshold_ms` — 設定為值`[0-INT_MAX]`以設定分析操作的閾值。
        + `profiler_sampling_rate` — 設定為值`[0.0-1.0]`，將慢速操作的百分比設定為設定檔。

        如需詳細資訊，請參閱[分析 Amazon DocumentDB 操作](profiling.md)。

     1. **Profiler 日誌** — 將 Profiler 日誌匯出至 Amazon CloudWatch

     1. **IAM 角色** — 從下拉式清單中，選擇 *RDS 服務連結角色*。
   + **Tags** (標籤)

     1. **新增標籤** — 在*金鑰*方塊中，輸入叢集的標籤名稱。在 *Value (值)* 方塊中，選擇性地輸入標籤值。標籤會與 AWS Identity and Access Management (IAM) 政策搭配使用，以管理對 Amazon DocumentDB 資源的存取，並控制可套用至資源的動作。
   + **刪除保護** 

     1. **啟用刪除保護** — 保護叢集免於意外刪除。啟用此選項後，您無法刪除叢集。

1. 若要還原叢集，請選擇 **Create cluster (建立叢集)**。或者，您可以選擇 **Cancel (取消)** 以取消操作。

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

若要將叢集還原至快照備份保留期內的某個時間點，請搭配下列參數使用 `restore-db-cluster-to-point-in-time` 操作。
+ **--db-cluster-identifier**— 必要。要建立之新叢集的名稱。操作前，此叢集不可以存在。參數值必須滿足下列限制條件。

  叢集命名限制條件：
  + 長度為 【1-63】 個字母、數字或連字號。
  + 第一個字元必須是字母。
  + 不能以連字號結尾，或包含兩個連續連字號。
  + 對於每個區域每個 Amazon RDS、Neptune 和 Amazon DocumentDB 的所有叢集 AWS 帳戶，必須是唯一的。
+ **--restore-to-time** — 還原叢集的 UTC 日期和時間。例如 `2018-06-07T23:45:00Z`。

  時間限制：
  + 必須在叢集的最近一次可還原時間之前。
  + 如果未提供 `--use-latest-restorable-time` 參數，則必須指定。
  + 如果 `--use-latest-restorable-time` 參數為 `true`，則無法指定。
  + 如果 `--restore-type` 參數值為 `copy-on-write`，則無法指定。
+ **--source-db-cluster-identifier** — 要從中還原的來源叢集名稱。此叢集必須存在並且為可用。
+ **--use-latest-restorable-time** 或 **--no-use-latest-restorable-time** — 是否還原至最新的可還原備份時間。如果未提供 `--restore-to-time` 參數，則無法指定。
+ **--storage-type standard \$1 iopt1** — 選用。預設：`standard`。

 AWS CLI 操作`restore-db-cluster-to-point-in-time`只會還原叢集，而不是該叢集的執行個體。您必須呼叫 `create-db-instance` 操作，為還原的叢集建立執行個體，並且在 `--db-cluster-identifier` 中指定所還原叢集的識別碼。只有在 `restore-db-cluster-to-point-in-time` 操作完成後，且還原的叢集為*可用*時，您才能建立執行個體。

**Example**  
以下範例會從快照 `sample-cluster-snapshot` 的最近一次可還原時間建立 `sample-cluster-restored`。  
針對 Linux、macOS 或 Unix：  

```
aws docdb restore-db-cluster-to-point-in-time \
    --db-cluster-identifier sample-cluster-restored \
    --source-db-cluster-identifier sample-cluster-snapshot \
    --use-latest-restorable-time
```
針對 Windows：  

```
aws docdb restore-db-cluster-to-point-in-time ^
    --db-cluster-identifier sample-cluster-restored ^
    --source-db-cluster-identifier sample-cluster-snapshot ^
    --use-latest-restorable-time
```

**Example**  
以下範例會從快照 `sample-cluster-snapshot` 的 `sample-cluster` 備份保留期間中的 2018 年 12 月 11 日 03:15 (UTC) 建立 `sample-cluster-restored`。  
針對 Linux、macOS 或 Unix：  

```
aws docdb restore-db-cluster-to-point-in-time \
    --db-cluster-identifier sample-cluster-restore \
    --source-db-cluster-identifier sample-cluster \
    --restore-to-time 2020-05-12T03:15:00Z
```
針對 Windows：  

```
aws docdb restore-db-cluster-to-point-in-time ^
    --db-cluster-identifier sample-cluster-restore ^
    --source-db-cluster-identifier sample-cluster ^
    --restore-to-time 2020-05-12T03:15:00Z
```

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

```
{
    "DBCluster": {
        "AvailabilityZones": [
            "us-east-1c",
            "us-west-2b",
            "us-west-2a"
        ],
        "BackupRetentionPeriod": 1,
        "DBClusterIdentifier": "sample-cluster-restored",
        "DBClusterParameterGroup": "sample-parameter-group",
        "DBSubnetGroup": "default",
        "Status": "creating",
        "Endpoint": "sample-cluster-restored.node.us-east-1.docdb.amazonaws.com",
        "ReaderEndpoint": "sample-cluster-restored.node.us-east-1.docdb.amazonaws.com",
        "MultiAZ": false,
        "Engine": "docdb",
        "EngineVersion": "4.0.0",
        "Port": 27017,
        "MasterUsername": "master-user",
        "PreferredBackupWindow": "02:00-02:30",
        "PreferredMaintenanceWindow": "tue:09:50-tue:10:20",
        "DBClusterMembers": [],
        "VpcSecurityGroups": [
            {
                "VpcSecurityGroupId": "sg-abc0123",
                "Status": "active"
            }
        ],
        "HostedZoneId": "ABCDEFGHIJKLM",
        "StorageEncrypted": true,
        "KmsKeyId": "arn:aws:kms:us-east-1:<accountID^>:key/sample-key",
        "DbClusterResourceId": "cluster-ABCDEFGHIJKLMNOPQRSTUVWXYZ",
        "DBClusterArn": "arn:aws:rds:us-east-1:<accountID>:cluster:sample-cluster-restored",
        "AssociatedRoles": [],
        "ClusterCreateTime": "2020-04-24T20:14:36.713Z",
        "DeletionProtection": false
    }
}
```

------

# 刪除叢集快照
<a name="backup_restore-delete_cluster_snapshot"></a>

手動快照是完整備份，只有在您使用 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** (快照)。
**提示**  
如果畫面左側沒有出現導覽窗格，請選擇頁面左上角的功能表圖示 (![\[Hamburger menu icon with three horizontal lines.\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/docdb-menu-icon.png))。

1. 在快照清單中，找到您要刪除的快照，並選擇左側的按鈕。快照的類型必須為**手動**。

   1. 您可以檢查快照是否列為類型資料欄`automatic`下`manual`，以確認快照的**類型**為**手動**。

1. 在 **Actions (動作)** 選單中，選擇 **Delete (刪除)**。如果 **Delete (刪除)** 選項無法使用，表示您可能選擇了自動快照。

1. 在刪除確認畫面上，選擇 **Delete (刪除)** 來刪除快照。如要保留快照，請選擇 **Cancel (取消)**。

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

Amazon DocumentDB 手動叢集快照是您可以使用 手動刪除的完整備份 AWS CLI。您無法手動刪除自動快照。

若要使用 刪除手動叢集快照 AWS CLI，請使用 `delete-db-cluster-snapshot`操作搭配下列參數。

**Parameters**
+ **--db-cluster-snapshot-identifier** – 必要。要刪除的手動快照名稱。

以下範例會刪除 `sample-cluster-snapshot` 叢集快照。

針對 Linux、macOS 或 Unix：

```
aws docdb delete-db-cluster-snapshot \
    --db-cluster-snapshot-identifier sample-cluster-snapshot
```

針對 Windows：

```
aws docdb delete-db-cluster-snapshot ^
    --db-cluster-snapshot-identifier sample-cluster-snapshot
```

此操作的輸出會列出您刪除之叢集快照的詳細資料。

------