

# 将数据库集群从保留的自动备份还原到指定时间
<a name="aurora-pitr-retained"></a>

如果备份在源集群的保留期内，则可以在删除源数据库集群后，从保留的自动备份中还原数据库集群。该过程类似于从自动备份中还原数据库集群。

**注意**  
您无法使用此过程还原 Aurora Serverless v1 数据库集群，因为不会保留 Aurora Serverless v1 集群的自动备份。

## 控制台
<a name="aurora-pitr-retained.CON"></a>

**将数据库集群还原到指定时间**

1. 登录 AWS 管理控制台 并通过以下网址打开 Amazon RDS 控制台：[https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/)。

1. 在导航窗格中，选择 **Automated backups**（自动备份）。

1. 选择**已保留**选项卡。  
![\[\]](http://docs.aws.amazon.com/zh_cn/AmazonRDS/latest/AuroraUserGuide/images/db-cluster-retained-automated-backups.png)

1. 选择要还原的 数据库集群。

1. 对于 **Actions (操作)**，选择 **Restore to point in time (还原到时间点)**。

   此时会显示**还原到时间点**窗口。

1. 选择**最近可还原时间**以还原到可能的最近时间，或选择**自定义**来选择时间。

   如果选择 **Custom**（自定义），请输入要还原集群的指定日期和时间。
**注意**  
时间以您的本地时区显示，表示为协调世界时 (UTC) 的偏移量。例如，UTC-5 是东部标准时间/中部夏令时。

1. 对于**数据库集群标识符**，请输入还原后的目标数据库集群的名称。名称必须唯一。

1. 根据需要选择其他选项，例如数据库实例类。

   有关每项设置的信息，请参阅 [Aurora 数据库集群的设置](Aurora.CreateInstance.md#Aurora.CreateInstance.Settings)。

1. 选择**还原到时间点**。

## AWS CLI
<a name="aurora-pitr-retained.CLI"></a>

要将数据库集群还原到指定时间，请使用 AWS CLI 命令 [restore-db-cluster-to-point-in-time](https://docs.aws.amazon.com/cli/latest/reference/rds/restore-db-cluster-to-point-in-time.html) 创建新的数据库集群。

您可以指定其他设置。有关每项设置的信息，请参阅 [Aurora 数据库集群的设置](Aurora.CreateInstance.md#Aurora.CreateInstance.Settings)。

此操作支持资源标记。使用 `--tags` 选项时，将忽略源数据库集群标签，并使用提供的标签。否则，将使用源集群中的最新标签。

**Example**  
对于 Linux、macOS 或 Unix：  

```
1. aws rds restore-db-cluster-to-point-in-time \
2.     --source-db-cluster-resource-id cluster-123ABCEXAMPLE \
3.     --db-cluster-identifier mytargetdbcluster \
4.     --restore-to-time 2017-10-14T23:45:00.000Z
```
对于 Windows：  

```
1. aws rds restore-db-cluster-to-point-in-time ^
2.     --source-db-cluster-resource-id cluster-123ABCEXAMPLE ^
3.     --db-cluster-identifier mytargetdbcluster ^
4.     --restore-to-time 2017-10-14T23:45:00.000Z
```

**重要**  
如果您使用控制台将数据库集群还原到指定时间，则 Amazon RDS 会为您的数据库集群自动创建主实例（写入器）。如果您使用 AWS CLI 将数据库集群还原到指定时间，则必须明确为数据库集群创建主实例。主实例是在数据库集群中创建的第一个实例。  
要为数据库集群创建主实例，请调用 [create-db-instance](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html) AWS CLI 命令。包括数据库集群名称以作为 `--db-cluster-identifier` 选项值。

## RDS API
<a name="aurora-pitr-retained.API"></a>

要将数据库集群还原到指定时间，请结合以下参数调用 Amazon RDS API [https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_RestoreDBClusterToPointInTime.html](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_RestoreDBClusterToPointInTime.html) 操作：
+ `SourceDbClusterResourceId`
+ `DBClusterIdentifier`
+ `RestoreToTime`

**重要**  
如果您使用控制台将数据库集群还原到指定时间，则 Amazon RDS 会为您的数据库集群自动创建主实例（写入器）。如果使用 RDS API 将数据库集群还原到指定时间，请确保为数据库集群明确创建主实例。主实例是在数据库集群中创建的第一个实例。  
要为数据库集群创建主实例，请调用 RDS API 操作 [CreateDBInstance](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html)。包括数据库群集的名称作为 `DBClusterIdentifier` 参数值。