

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

# 還原至某個時間點
<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
    }
}
```

------