

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

# 備份與還原 Amazon RDS Custom for Oracle DB 資料庫執行個體
<a name="custom-backup"></a>

就像是 Amazon RDS 一樣，RDS Custom 會在資料庫執行個體的備份時段建立並儲存 RDS Custom for Oracle 資料庫執行個體的自動備份。您也可以手動備份您的資料庫執行個體。

程序與擷取 Amazon RDS 資料庫執行個體的快照相同。RDS Custom 資料庫執行個體的第一個快照會包含完整的資料庫執行個體資料。後續快照是增量。

使用 AWS 管理主控台 或 AWS CLI 還原資料庫快照。

**Topics**
+ [建立 RDS Custom for Oracle 快照](custom-backup.creating.md)
+ [從 RDS Custom for Oracle 資料庫快照還原](custom-backup.restoring.md)
+ [將 RDS Custom for Oracle 執行個體還原至某個時間點](custom-backup.pitr.md)
+ [刪除 RDS Custom for Oracle 快照](custom-backup.deleting.md)
+ [刪除 RDS Custom for Oracle 自動備份](custom-backup.deleting-backups.md)

# 建立 RDS Custom for Oracle 快照
<a name="custom-backup.creating"></a>

RDS Custom for Oracle 會建立資料庫執行個體的儲存體磁碟區快照，因此會備份整個資料庫執行個體，而不只是個別的資料庫。當您的資料庫執行個體包含容器資料庫 (CDB) 時，執行個體的快照會包含根 CDB 和所有 PDB。

建立 RDS Custom for Oracle 快照時，請指定要備份哪個 RDS Custom 資料庫執行個體。為快照命名，稍後即可從該快照進行還原。

建立快照時，RDS Custom for Oracle 會為連接到資料庫執行個體的每個磁碟區建立 Amazon EBS 快照。RDS Custom for Oracle 會使用根磁碟區的 EBS 快照來註冊新的 Amazon Machine Image (AMI)。為了讓快照更容易與特定資料庫執行個體產生關聯，它們透過 `DBSnapshotIdentifier`、`DbiResourceId` 和`VolumeType` 加上標籤。

建立資料庫快照會導致短暫的輸入/輸出暫停。根據資料庫執行個體的大小和類別，暫停時間會持續幾秒鐘至幾分鐘。快照建立時間會隨著資料庫的大小而有所不同。由於快照包括整個儲存體磁碟區，所以檔案大小 (例如暫存檔案) 也會影響建立快照建立時間。若要進一步了解建立快照，請參閱 [為 Amazon RDS 的單一可用區域資料庫執行個體建立資料庫快照](USER_CreateSnapshot.md)。

使用主控台或 AWS CLI 建立 RDS Custom for Oracle 快照。

## 主控台
<a name="USER_CreateSnapshot.CON"></a>

**若要建立 RDS Custom 快照**

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

1. 在導覽窗格中，選擇 **Databases** (資料庫)。

1. 在 RDS Custom 資料庫執行個體清單中，選擇您要建立快照的執行個體。

1. 針對 **Actions** (動作)，選擇 **Take snapshot** (建立快照)。

   **Take DB Snapshot** (建立資料庫快照) 視窗隨即顯示。

1. 在 **Snapshot name (快照名稱)** 中輸入快照的名稱。

1. 選擇 **Take Snapshot** (擷取快照)。

## AWS CLI
<a name="USER_CreateSnapshot.CLI"></a>

您可以使用 [create-db-snapshot](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-snapshot.html) AWS CLI 命令來建立 RDS Custom 資料庫執行個體的快照。

指定下列選項：
+ `--db-instance-identifier` – 識別您要備份的 RDS Custom 資料庫執行個體
+ `--db-snapshot-identifier` – 為您的 RDS Custom 快照命名以便稍後從該快照還原

在此範例中，您會為名稱為 `my-custom-instance` 的 RDS Custom 資料庫執行個體建立名稱為 *`my-custom-snapshot`* 的資料庫快照。

**Example**  
對於 Linux、macOS 或 Unix：  

```
1. aws rds create-db-snapshot \
2.     --db-instance-identifier my-custom-instance \
3.     --db-snapshot-identifier my-custom-snapshot
```
在 Windows 中：  

```
1. aws rds create-db-snapshot ^
2.     --db-instance-identifier my-custom-instance ^
3.     --db-snapshot-identifier my-custom-snapshot
```

# 從 RDS Custom for Oracle 資料庫快照還原
<a name="custom-backup.restoring"></a>

還原 RDS Custom for Oracle 資料庫執行個體時，您要提供資料庫快照的名稱和新執行個體的名稱。您無法從快照還原至現有的 RDS Custom 資料庫執行個體。還原時，會建立新的 RDS Custom for Oracle 資料庫執行個體。

還原程序與在 Amazon RDS 中還原的方式有以下不同：
+ 還原快照之前，RDS Custom for Oracle 會先備份現有的組態檔案。這些檔案可以在目錄 `/rdsdbdata/config/backup` 中的還原執行個體上取得。RDS Custom for Oracle 會使用預設參數還原資料庫快照，並使用現有的資料庫組態檔案覆寫先前的資料庫組態檔案。因此，還原的執行個體不會保留自訂參數和對資料庫組態檔案的變更。
+ 還原的資料庫名稱與快照中的名稱相同。您無法指定不同的名稱。(對於 RDS Custom for Oracle，預設值為 `ORCL`。)

## 主控台
<a name="custom-backup.restoring.console"></a>

**若要從資料庫快照還原 RDS Custom 資料庫執行個體**

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

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

1. 選擇想要從中還原的資料庫執行個體。

1. 針對 **Actions** (動作)，選擇 **Restore snapshot** (還原快照)。

1. 在 **Restore DB Instance** (還原資料庫執行個體) 頁面上，針對 **DB Instance Identifier (資料庫執行個體識別符)**，輸入您還原的 RDS Custom 資料庫執行個體的名稱。

1. 選擇 **Restore DB instance** (還原資料庫執行個體)。

## AWS CLI
<a name="custom-backup.restoring.CLI"></a>

您可以使用 [restore-db-instance-from-db-snapshot](https://docs.aws.amazon.com/cli/latest/reference/rds/restore-db-instance-from-db-snapshot.html) AWS CLI 命令來還原 RDS Custom 資料庫快照。

如果您要從中還原的快照適用於私有資料庫執行個體，請務必指定正確的 `db-subnet-group-name` 和 `no-publicly-accessible`。否則，資料庫執行個體預設為可公開存取。下列選項是必要的：
+ `db-snapshot-identifier` – 識別要從中進行還原的快照
+ `db-instance-identifier` – 指定要從資料庫快照建立之 RDS Custom 資料庫執行個體的名稱
+ `custom-iam-instance-profile` – 指定與 RDS Custom 資料庫執行個體的基礎 Amazon EC2 執行個體關聯的執行個體設定檔。

下列程式碼會為 `my-custom-instance` 還原名稱為 `my-custom-snapshot` 的快照。

**Example**  
對於 Linux、macOS 或 Unix：  

```
aws rds restore-db-instance-from-db-snapshot \
  --db-snapshot-identifier my-custom-snapshot \
  --db-instance-identifier my-custom-instance \
  --custom-iam-instance-profile AWSRDSCustomInstanceProfileForRdsCustomInstance \
  --no-publicly-accessible
```
在 Windows 中：  

```
aws rds restore-db-instance-from-db-snapshot ^
  --db-snapshot-identifier my-custom-snapshot ^
  --db-instance-identifier my-custom-instance ^
  --custom-iam-instance-profile AWSRDSCustomInstanceProfileForRdsCustomInstance ^
  --no-publicly-accessible
```

# 將 RDS Custom for Oracle 執行個體還原至某個時間點
<a name="custom-backup.pitr"></a>

您可以將資料庫執行個體還原至特定時間點 (PITR)，建立新的資料庫執行個體。若要支援 PITR，您的資料庫執行個體必須將備份保留設定為非零值。

RDS Custom for Oracle 資料庫執行個體的最晚可還原時間取決於許多因素，但通常是目前時間的 5 分鐘內。若要查看資料庫執行個體的最新可還原時間，請使用 AWS CLI [describe-db-instances](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-instances.html) 命令，並查看在資料庫執行個體的 `LatestRestorableTime` 欄位內傳回的值。若要在 Amazon RDS 主控台中查看每個資料庫執行個體的最新可還原時間，請選擇**自動備份**。

您可以還原至備份保留期間內的任何時間點。若要查看每個資料庫執行個體的最早可還原時間，請在 Amazon RDS 主控台中選擇**自動備份**。

如需 PITR 的一般資訊，請參閱 [將 Amazon RDS 的資料庫執行個體還原至指定時間](USER_PIT.md)。

**Topics**
+ [RDS Custom for Oracle 的 PITR 考量](#custom-backup.pitr.oracle)

## RDS Custom for Oracle 的 PITR 考量
<a name="custom-backup.pitr.oracle"></a>

在 RDS Custom for Oracle 中，PITR 與 Amazon RDS 中的 PITR 有以下的重要不同：
+ 還原的資料庫名稱與來源資料庫執行個體中的名稱相同。您無法指定不同的名稱。預設值為 `ORCL`。
+ `AWSRDSCustomIamRolePolicy` 需要新許可。如需更多詳細資訊，請參閱 [步驟 2：將存取政策新增至 AWSRDSCustomInstanceRoleForRdsCustomInstance](custom-setup-orcl.md#custom-setup-orcl.iam.add-policy)。
+ 所有 RDS Custom for Oracle 資料庫執行個體都必須將備份保留設定為非零值。
+ 如果您變更作業系統或資料庫執行個體時區，PITR 可能無法運作。如需變更時區的相關資訊，請參閱 [Oracle 時區](custom-managing.timezone.md)。
+ 如果您將自動化設定為 `ALL_PAUSED`，RDS Custom 會暫停封存重做日誌檔案的上傳，包括在最近一次可還原時間 (LRT) 之前建立的日誌。我們建議您暫停自動化一段時間。

  舉例來說，假設您的 LRT 是 10 分鐘前。您暫停自動化。暫停期間，RDS Custom 不會上傳封存的重做日誌。如果您的資料庫執行個體當機，您只能復原到暫停時存在的 LRT 之前的時間。當您繼續自動化時，RDS Custom 會繼續上傳日誌。LRT 會繼續。套用一般 PITR 規則。
+ 在 RDS Custom 中，您可以手動指定保留封存的重做日誌的任意時數，以便在 RDS Custom 上傳後刪除之前保留這些封存的重做日誌。請如下指定小時數：

  1. 建立名為 `/opt/aws/rdscustomagent/config/redo_logs_custom_configuration.json` 的文字檔案。

  1. 以下列格式新增 JSON 物件：`{"archivedLogRetentionHours" : "num_of_hours"}`。數字必須是介於 1—840 範圍內的整數。
+ 假設您將非 CDB 插入容器資料庫 (CDB) 作為 PDB，然後嘗試 PITR。只在您先前已備份 PDB 時，操作才會成功。建立或修改 PDB 之後，建議您一律將其備份。
+ 我們建議您不要自訂資料庫初始化參數。例如，修改下列參數會影響 PITR：
  + `CONTROL_FILE_RECORD_KEEP_TIME` 會影響上傳和刪除日誌的規則。
  + `LOG_ARCHIVE_DEST_n` 不支援多個目的地。
  + `ARCHIVE_LAG_TARGET` 會影響最新的可還原時間。`ARCHIVE_LAG_TARGET` 設定為 `300`，因為復原點目標 (RPO) 為 5 分鐘。為了實現此目標，RDS 每隔 5 分鐘就會切換線上重做日誌，並將其存放在 Amazon S3 儲存貯體中。如果日誌切換太頻繁而導致 RDS Custom for Oracle 資料庫的效能問題，您可以將資料庫執行個體和儲存體擴展為具有更高 IOPS 和輸送量的項目。如果對於您的復原計畫有必要，您可以將 `ARCHIVE_LAG_TARGET` 初始化參數的設定調整為 60 到 7200 的值。
+ 如果您自訂資料庫初始化參數，我們強烈建議您只自訂下列項目：
  + `COMPATIBLE` 
  + `MAX_STRING_SIZE`
  + `DB_FILES` 
  + `UNDO_TABLESPACE` 
  + `ENABLE_PLUGGABLE_DATABASE` 
  + `CONTROL_FILES` 
  + `AUDIT_TRAIL` 
  + `AUDIT_TRAIL_DEST` 

  針對其他所有初始化參數，RDS Custom 會還原預設值。如果您修改不在上述清單中的參數，它可能會對 PITR 產生不良影響，並導致無法預期的結果。例如，`CONTROL_FILE_RECORD_KEEP_TIME` 會影響上傳和刪除日誌的規則。

您可以使用 AWS 管理主控台、AWS CLI 或 RDS API 將 RDS Custom 資料庫執行個體還原至某個時間點。

## 主控台
<a name="custom-backup.pitr2.CON"></a>

**若要將 RDS Custom 資料庫執行個體還原至指定時間**

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

1. 在導覽窗格中，選擇 **Automated backups** (自動備份)。

1. 選擇您想要還原的 RDS Custom 資料庫執行個體。

1. 針對 **Actions** (動作)，選擇 **Restore to point in time** (還原至時間點)。

   **Restore to point in time (還原到時間點)** 視窗隨即出現。

1. 選擇 **Latest restorable time (最近的可還原時間)** 以還原最近一次的可能時間，或選擇 **Custom (自訂)** 以選擇一個時間。

   如果您選擇 **Custom (自訂)**，請輸入您希望執行個體叢集還原到什麼日期和時間。

   會以您的當地時區顯示時間，根據國際標準時間 (UTC) 的時差來表示。例如，UTC-5 是東部標準時間/中部日光節約時間。

1. 對於 **DB Instance Identifier** (資料庫執行個體識別符)，輸入目標還原 RDS Custom 資料庫執行個體的名稱。名稱必須是唯一的。

1. 視需要選擇其他選項，例如資料庫執行個體類別。

1. 選擇 **Restore to point in time (還原至時間點)**。

## AWS CLI
<a name="custom-backup.pitr2.CLI"></a>

您可以使用 [ restore-db-instance-to-point-in-time](https://docs.aws.amazon.com/cli/latest/reference/rds/restore-db-instance-to-point-in-time.html) AWS CLI 命令來建立新的 RDS Custom 資料庫執行個體，將資料庫執行個體還原至指定時間。

使用下列其中一個選項來指定要從中還原的備份：
+ `--source-db-instance-identifier mysourcedbinstance`
+ `--source-dbi-resource-id dbinstanceresourceID`
+ `--source-db-instance-automated-backups-arn backupARN`

`custom-iam-instance-profile` 選項為必要項目。

下列範例會將 `my-custom-db-instance` 還原至名稱為 `my-restored-custom-db-instance` 的新資料庫執行個體，截至指定的時間。

**Example**  
對於 Linux、macOS 或 Unix：  

```
1. aws rds restore-db-instance-to-point-in-time \
2.     --source-db-instance-identifier my-custom-db-instance\
3.     --target-db-instance-identifier my-restored-custom-db-instance \
4.     --custom-iam-instance-profile AWSRDSCustomInstanceProfileForRdsCustomInstance \
5.     --restore-time 2022-10-14T23:45:00.000Z
```
在 Windows 中：  

```
1. aws rds restore-db-instance-to-point-in-time ^
2.     --source-db-instance-identifier my-custom-db-instance ^
3.     --target-db-instance-identifier my-restored-custom-db-instance ^
4.     --custom-iam-instance-profile AWSRDSCustomInstanceProfileForRdsCustomInstance ^
5.     --restore-time 2022-10-14T23:45:00.000Z
```

# 刪除 RDS Custom for Oracle 快照
<a name="custom-backup.deleting"></a>

當您不再需要時，可以刪除由 RDS Custom for Oracle 管理的資料庫快照。Amazon RDS 與 RDS Custom 資料庫執行個體的刪除程序相同。

二進位和根磁碟區的 Amazon EBS 快照會在您的帳戶中保留較長的時間，因為這些快照可能會連結到您帳戶中執行的某些執行個體或其他 RDS Custom for Oracle 快照。這些 EBS 快照不再與任何現有 RDS Custom for Oracle 資源 (資料庫執行個體或備份) 相關之後，會自動刪除這些快照。

## 主控台
<a name="USER_DeleteSnapshot.CON"></a>

**若要刪除 RDS Custom 資料庫執行個體的快照**

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

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

1. 選擇想要刪除的資料庫快照。

1. 針對 **Actions** (動作)，選擇 **Delete Snapshot** (刪除快照)。

1. 在確認頁面上，選擇 **Delete (刪除)**。

## AWS CLI
<a name="USER_DeleteSnapshot.CLI"></a>

若要刪除 RDS Custom 快照，請使用 AWS CLI 命令 [delete-db-snapshot](https://docs.aws.amazon.com/cli/latest/reference/rds/delete-db-snapshot.html)。

下列選項是必要的：
+ `--db-snapshot-identifier` – 要刪除的快照

以下範例會刪除 `my-custom-snapshot` 資料庫快照。

**Example**  
對於 Linux、macOS 或 Unix：  

```
1. aws rds delete-db-snapshot \  
2.   --db-snapshot-identifier my-custom-snapshot
```
在 Windows 中：  

```
1. aws rds delete-db-snapshot ^
2.   --db-snapshot-identifier my-custom-snapshot
```

# 刪除 RDS Custom for Oracle 自動備份
<a name="custom-backup.deleting-backups"></a>

不再需要保留 RDS Custom for Oracle 的自動備份時，刪除即可。該程序與刪除 Amazon RDS 備份的程序相同。

## 主控台
<a name="USER_WorkingWithAutomatedBackups-Deleting.CON"></a>

**刪除保留的自動備份**

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

1. 在導覽窗格中，選擇 **Automated backups** (自動備份)。

1. 選擇 **Retained (已保留)**。

1. 選擇您要刪除的已保留自動備份。

1. 對於 **Actions** (動作)，請選擇 **Delete** (刪除)。

1. 在確認頁面上，輸入 **delete me**，然後選擇 **Delete (刪除)**。

## AWS CLI
<a name="USER_WorkingWithAutomatedBackups-Deleting.CLI"></a>

您可以使用 AWS CLI 命令 [delete-db-instance-automated-backup](https://docs.aws.amazon.com/cli/latest/reference/rds/delete-db-instance-automated-backup.html) 刪除保留的自動備份。

下列選項用來刪除保留的自動備份：
+ `--dbi-resource-id` – 來源 RDS Custom 資料庫執行個體的資源識別符。

  您可以使用 AWS CLI 命令 [describe-db-instance-automated-backups](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-instance-automated-backups.html)，刪除已保留自動備份的來源資料庫執行個體的來源識別符。

下列範例刪除來源資料庫執行個體識別符為 `custom-db-123ABCEXAMPLE` 的已保留自動備份。

**Example**  
對於 Linux、macOS 或 Unix：  

```
1. aws rds delete-db-instance-automated-backup \
2.     --dbi-resource-id custom-db-123ABCEXAMPLE
```
在 Windows 中：  

```
1. aws rds delete-db-instance-automated-backup ^
2.     --dbi-resource-id custom-db-123ABCEXAMPLE
```