

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

# 建立資料庫叢集匯出任務
<a name="export-cluster-data.Exporting"></a>

建立匯出任務，將資料從 Aurora 資料庫叢集匯出至 Amazon S3 儲存貯體。您每個 AWS 帳戶最多可以有五個正在同時進行的資料庫叢集匯出任務。

**注意**  
匯出資料庫叢集資料可能需要一段時間，取決於您的資料庫類型和大小。匯出任務會先複製和擴展整個資料庫，然後再將資料擷取到 Amazon S3。此階段期間的工作進度會顯示為**STARTING (開始)**。當任務切換到將資料匯出到 S3 時，進度會顯示為 **In progress (進行中)**。  
匯出完成所需的時間取決於儲存在資料庫中的資料。例如，如果資料表有分散均勻的數值主索引鍵或索引資料欄，則匯出速度最快。未包含適用於資料分割之資料欄的資料表，以及在字串型資料欄上只有一個索引的資料表，因為匯出使用較慢的單一執行緒程序，所以將會需要更長的時間。

您可以使用 AWS 管理主控台、AWS CLI 或 RDS API，將資料庫叢集資料匯出至 Amazon S3。

如果您使用 Lambda 函數匯出資料庫叢集資料，請將 `kms:DescribeKey` 動作新增至 Lambda 函數政策。如需詳細資訊，請參閱 [AWS Lambda 許可](https://docs.aws.amazon.com/lambda/latest/dg/lambda-permissions.html)。

## 主控台
<a name="export-cluster-data.ExportConsole"></a>

**Export to Amazon S3** (匯出至 Amazon S3) 主控台選項僅會針對可匯出至 Amazon S3 的資料庫叢集顯示。由於下列原因，資料庫叢集可能無法匯出：
+ S3 匯出不支援此資料庫引擎。
+ S3 匯出不支援資料庫叢集版本。
+ 已建立資料庫叢集的 AWS 區域不支援 S3 匯出。

**匯出資料庫叢集資料**

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

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

1. 選擇您要匯出其資料的資料庫叢集。

1. 針對 **Actions** (動作)，選擇 **Export to Amazon S3** (匯出至 Amazon S3)。

   隨即出現 **Export to Amazon S3 (匯出至 Amazon S3)** 視窗。

1. 針對 **Export identifier (匯出識別符)**，輸入名稱以識別匯出任務。這個值也會用來做為在 S3 儲存貯體中建立的檔案名稱。

1. 選擇匯出的資料：
   + 選擇 **All** (全部) 來匯出資料庫叢集中的所有資料。
   + 選擇 **Partial** (部分) 來匯出資料庫叢集的特定部分。若要識別要匯出的叢集部分，請針對 **Identifier (識別符)** 輸入一或多個資料庫、結構描述或表格，並以空格分隔。

     使用下列格式：

     ```
     database[.schema][.table] database2[.schema2][.table2] ... databasen[.scheman][.tablen]
     ```

     例如：

     ```
     mydatabase mydatabase2.myschema1 mydatabase2.myschema2.mytable1 mydatabase2.myschema2.mytable2
     ```

1. 針對 **S3 bucket (S3 儲存貯體)**，選擇要匯出的儲存貯體。

   如要將匯出資料指派給 S3 儲存貯體中的資料夾路徑，請針對 **S3 prefix (S3 字首)** 輸入選用的路徑。

1. 針對 **IAM role (IAM 角色)**，您可選擇授予對您所選擇 S3 儲存貯體寫入存取權限的角色，或建立新角色。
   + 如果您透過遵循 [使用 IAM 角色提供對 Amazon S3 儲存貯體的存取權](export-cluster-data.Setup.md#export-cluster-data.SetupIAMRole) 中的步驟建立了角色，請選擇該角色。
   + 如果您沒有建立授予您所選擇 S3 儲存貯體寫入存取權限的角色，請選擇 **Create a new role** (建立新角色) 以自動建立角色。接下來，為 **IAM 角色名稱 (IAM role name)** 中的角色輸入名稱。

1. 針對 **KMS key** (KMS 金鑰)，輸入金鑰的 ARN 以加密匯出的資料。

1. 選擇 **Export to Amazon S3 (匯出至 Amazon S3)**。

## AWS CLI
<a name="export-cluster-data.ExportCLI"></a>

若要使用 AWS CLI 將資料庫叢集資料匯出至 Amazon S3，請搭配下列必要選項使用 [start-export-task](https://docs.aws.amazon.com/cli/latest/reference/rds/start-export-task.html) 命令：
+ `--export-task-identifier`
+ `--source-arn` – 資料庫叢集的 Amazon Resource Name (ARN)。
+ `--s3-bucket-name`
+ `--iam-role-arn`
+ `--kms-key-id`

在下列範例中，匯出任務名為 *my-cluster-export*，其會將資料匯出至名為 *amzn-s3-demo-destination-bucket* 的 S3 儲存貯體。

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

```
1. aws rds start-export-task \
2.     --export-task-identifier my-cluster-export \
3.     --source-arn arn:aws:rds:us-west-2:123456789012:cluster:my-cluster \
4.     --s3-bucket-name amzn-s3-demo-destination-bucket \
5.     --iam-role-arn iam-role \
6.     --kms-key-id my-key
```
在 Windows 中：  

```
1. aws rds start-export-task ^
2.     --export-task-identifier my-DB-cluster-export ^
3.     --source-arn arn:aws:rds:us-west-2:123456789012:cluster:my-cluster ^
4.     --s3-bucket-name amzn-s3-demo-destination-bucket ^
5.     --iam-role-arn iam-role ^
6.     --kms-key-id my-key
```
範例輸出如下。  

```
{
    "ExportTaskIdentifier": "my-cluster-export",
    "SourceArn": "arn:aws:rds:us-west-2:123456789012:cluster:my-cluster",
    "S3Bucket": "amzn-s3-demo-destination-bucket",
    "IamRoleArn": "arn:aws:iam:123456789012:role/ExportTest",
    "KmsKeyId": "my-key",
    "Status": "STARTING",
    "PercentProgress": 0,
    "TotalExtractedDataInGB": 0,
}
```
若要為資料庫叢集匯出提供 S3 儲存貯體中的資料夾路徑，請在 [start-export-task](https://docs.aws.amazon.com/cli/latest/reference/rds/start-export-task.html) 命令中包含 `--s3-prefix` 選項。

## RDS API
<a name="export-cluster-data.ExportAPI"></a>

若要使用 Amazon RDS API 將資料庫叢集資料匯出至 Amazon S3，請搭配下列必要參數使用 [StartExportTask](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_StartExportTask.html) 操作：
+ `ExportTaskIdentifier`
+ `SourceArn` – 資料庫叢集的 ARN。
+ `S3BucketName`
+ `IamRoleArn`
+ `KmsKeyId`