

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用 Amazon Keyspaces 的 point-in-time恢复功能备份和还原数据
<a name="PointInTimeRecovery"></a>

Point-in-time 恢复 (PITR) 通过为您提供表数据的连续备份，帮助保护您的 Amazon Keyspaces 表免受意外写入或删除操作的影响。

例如，假设测试脚本意外写入生产 Amazon Keyspaces 表中。通过 point-in-time恢复，您可以将该表的数据恢复到过去 35 天内启用 PITR 以来的任意一秒钟。如果您删除启用了 point-in-time恢复功能的表，则可以查询已删除表的数据 35 天（不收取额外费用），然后将其恢复到删除前的状态。

您可以使用控制台、软件开发工具包和 () 或 Cassandra 查询语言 AWS Command Line Interface (CQL AWS CLI) 将 Amazon AWS Keyspaces 表恢复到某个时间点。有关更多信息，请参阅 [在 Amazon Keyspaces 中使用 point-in-time恢复功能](PointInTimeRecovery_Tutorial.md)。

Point-in-time 操作对基表的性能或可用性没有影响，恢复表也不会消耗额外的吞吐量。

有关 PITR 限额的更多信息，请参阅 [Amazon Keyspaces（Apache Cassandra 兼容）限额](quotas.md)。

有关定价的信息，请参阅 [Amazon Keyspaces（Apache Cassandra 兼容）定价](https://aws.amazon.com/keyspaces/pricing)。

**Topics**
+ [Amazon Keyspaces 中 point-in-time恢复的工作原理](PointInTimeRecovery_HowItWorks.md)
+ [在 Amazon Keyspaces 中使用 point-in-time恢复功能](PointInTimeRecovery_Tutorial.md)

# Amazon Keyspaces 中 point-in-time恢复的工作原理
<a name="PointInTimeRecovery_HowItWorks"></a>

本节概述了 Amazon Keyspaces point-in-time 恢复 (PITR) 的工作原理。有关定价的更多信息，请参阅 [Amazon Keyspaces（Apache Cassandra 兼容）定价](https://aws.amazon.com/keyspaces/pricing)。

**Topics**
+ [PITR 连续备份的时段](#howitworks_backup_window)
+ [PITR 还原设置](#howitworks_backup_settings)
+ [使用 PITR 还原加密表](#howitworks_backup_encryption)
+ [使用 PITR 还原多区域表](#howitworks_backup_multiRegion)
+ [PITR 还原用户定义类型的表 () UDTs](#howitworks_backup_udt)
+ [使用 PITR 还原表所需的时间](#howitworks_restore_time)
+ [Amazon Keyspaces PITR 以及与服务的集成 AWS](#howitworks_integration)

## PITR 连续备份的时段
<a name="howitworks_backup_window"></a>

Amazon Keyspaces PITR 使用两个时间戳来维护表中可还原备份的可用时间范围。
+ 最早可还原时间：标记最早可还原备份的时间。最早的可还原备份最长可追溯到 35 天或启用 PITR 时（以较晚者为准）。最长备份期限为 35 天，无法修改。
+ 当前时间：最新可还原备份的时间戳为当前时间。如果在还原期间未提供时间戳，则使用当前时间。

启用 PITR 后，您可以还原到 `EarliestRestorableDateTime` 和 `CurrentTime` 之间的任意时间点。您只能将表数据还原到启用 PITR 的时间。

如果您禁用 PITR，然后再次将其重新启用，则系统会将第一个可用备份的开始时间重置为重新启用 PITR 的时间。这意味着，禁用 PITR 会删除您的备份历史记录。

**注意**  
对表的数据定义语言 (DL) 操作（如架构更改）是异步执行的。您只能在还原的表数据中看到已完成的操作，但如果还原时正在进行其他操作，则您可能会在源表上看到这些操作。有关 DDL 语句列表，请参阅 [Amazon Keyspaces 中的 DDL 语句（数据定义语言）](cql.ddl.md)。

表不一定要处于活动状态才能还原。如果对已删除的表启用了 PITR，并且删除操作发生在备份时段内（或最近 35 天内），您还可以还原已删除的表。

**注意**  
如果使用与先前删除的表相同的限定名称（例如 mykeyspace.mytable）创建了新表，则已删除的表将无法再还原。如果您尝试从控制台执行此操作，则系统会显示警告。

## PITR 还原设置
<a name="howitworks_backup_settings"></a>

当您使用 PITR 还原表时，Amazon Keyspaces 会根据新表中选择的时间戳 (`day:hour:minute:second`) 将源表的架构和数据还原到相应状态。PITR 不会覆盖现有表。

除了表的架构和数据外，PITR 还会从源表中还原 `custom_properties`。表的数据是根据所选时间戳（在最早还原时间和当前时间之间）进行还原的，与此不同的是，自定义属性始终根据截至当前时间的表设置进行还原。

还原后的表的设置与源表的设置以及启动还原时的时间戳相匹配。如果要在还原期间覆盖这些设置，则可以使用 `WITH custom_properties` 来执行此操作。自定义属性包括以下设置：
+ 读取/写入容量模式
+ 预置的吞吐容量设置
+ PITR 设置

如果表处于预置容量模式且启用了自动扩缩，则还原操作还会还原表的自动扩缩设置。您可以在 CQL 中使用 `autoscaling_settings` 参数或结合 CLI 使用 `autoScalingSpecification` 来覆盖它们。有关自动扩缩的更多信息，请参阅[使用 Amazon Keyspaces 自动扩缩自动管理吞吐能力](autoscaling.md)。

执行完整表还原时，还原表的所有表设置都来自还原时源表的当前设置。

例如，假设一个表的预配置的吞吐量最近下降到 50 个读取容量单位和 50 个写入容量单位。然后，您将表的状态还原到三周前的状态。表在该时间的预置吞吐量为 100 个读取容量单位和 100 个写入容量单位。在这种情况下，Amazon Keyspaces restores 将表数据还原到该时间点，但使用当前预置吞吐量设置（50 个读取容量单位和 50 个写入容量单位）。

以下设置不会还原，您必须手动为新表配置这些设置。
+ Amazon Keyspaces 更改数据捕获 (CDC) 流
+ AWS Identity and Access Management (IAM) 策略
+ Amazon CloudWatch 指标和警报
+ 标签（可以使用 `WITH TAGS` 将其添加到 CQL `RESTORE` 语句中）

## 使用 PITR 还原加密表
<a name="howitworks_backup_encryption"></a>

当您使用 PITR 还原表时，Amazon Keyspaces 会还原源表的加密设置。如果使用 AWS 拥有的密钥 （默认）对表进行加密，则会使用相同的设置自动恢复表。如果您要还原的表是使用客户自主管理型密钥加密的，那么 Amazon Keyspaces 需要能够访问相同的客户自主管理型密钥才能还原表数据。

您可以在还原时更改表的加密设置。要从客户管理的密钥更改 AWS 拥有的密钥 为客户管理的密钥，您需要在恢复时提供有效且可访问的客户托管密钥。

如果您想从客户管理的密钥更改为 AWS 拥有的密钥，请确认 Amazon Keyspaces 有权访问源表的客户托管密钥以使用恢复表。 AWS 拥有的密钥有关表的静态加密设置的更多信息，请参阅 [静态加密：它在 Amazon Keyspaces 中如何运作](encryption.howitworks.md)。

**注意**  
如果表是因为 Amazon Keyspaces 无法访问您的客户自主管理型密钥而被删除，则在尝试还原表之前，您需要确保 Amazon Keyspaces 能够访问客户自主管理型密钥。如果 Amazon Keyspaces 无权访问该密钥，则无法还原使用客户自主管理型密钥加密的表。有关更多信息，请参阅《 AWS Key Management Service 开发人员指南》中的[密钥访问疑难解答](https://docs.aws.amazon.com/kms/latest/developerguide/policy-evaluation.html)。

## 使用 PITR 还原多区域表
<a name="howitworks_backup_multiRegion"></a>

您可以使用 PITR 还原多区域表。要使恢复操作成功，必须在源表的所有副本上启用 PITR，并且必须将源表和目标表都复制到同一个副本。 AWS 区域

Amazon Keyspaces 会在属于键空间的每个复制区域中还原源表的设置。您还可以在还原操作期间覆盖设置。有关可在还原期间更改的设置的更多信息，请参阅 [PITR 还原设置](#howitworks_backup_settings)。

有关多区域复制的更多信息，请参阅[在 Amazon Keyspaces 中如何进行多区域复制](multiRegion-replication_how-it-works.md)。

## PITR 还原用户定义类型的表 () UDTs
<a name="howitworks_backup_udt"></a>

您可以恢复使用的表 UDTs。要使还原操作成功，引用的 UDTs 内容必须在密钥空间中存在且有效。

如果您在尝试恢复表时缺少任何必需的 UDT，Amazon Keyspaces 会尝试自动恢复 UDT 架构，然后继续恢复该表。

如果您删除并重新创建了 UDT，Amazon Keyspaces 会使用新的 UDT 架构恢复 UDT，并拒绝使用原始 UDT 架构恢复表的请求。在这种情况下，如果您希望使用旧 UDT 架构恢复表，则可以将该表恢复到新的密钥空间。删除并重新创建 UDT 时，即使重新创建的 UDT 的架构与已删除的 UDT 的架构相同，重新创建的 UDT 也被视为新的 UDT。在这种情况下，Amazon Keyspaces 会拒绝使用旧 UDT 架构恢复表的请求。

如果 UDT 丢失且 Amazon Keyspaces 尝试恢复 UDT，则如果您已达到该地区账户的最大 UDTs 数量，则尝试将失败。

有关 UDT 配额和默认值的更多信息，请参见[Amazon Keyspaces 中用户定义类型 (UDTs) 的配额和默认值](quotas.md#quotas-udts)。有关使用的更多信息 UDTs，请参阅[Amazon Keys UDTs paces 中的用户定义类型 ()](udts.md)。

## 使用 PITR 还原表所需的时间
<a name="howitworks_restore_time"></a>

还原表所需的时间取决于多种因素，并且并不是始终与表的大小直接相关。

以下是还原用时的一些注意事项。
+ 将备份还原到新表。执行用于创建新表和启动还原流程的所有操作可能最多需要 20 分钟（即使表是空的）。
+ 具有分布良好的数据模型的大型表的还原时间可能是几个小时或更长时间。
+ 如果源表包含严重偏斜的数据，则还原时间可能会增加。例如，如果表的主键使用一年中的月份作为分区键，而您的所有数据均来自 12 月，那么就出现了偏斜数据。

规划灾难恢复的最佳做法是定期记录平均还原完成时间，并确定这些时间对整个恢复时间目标的影响。

## Amazon Keyspaces PITR 以及与服务的集成 AWS
<a name="howitworks_integration"></a>

使用以下 PITR 操作进行记录 AWS CloudTrail ，以实现持续监控和审计。
+ 创建启用或禁用 PITR 的新表。
+ 为现有表启用或禁用 PITR。
+ 还原活动或已删除的表。

有关更多信息，请参阅 [使用记录 Amazon Keyspaces API 调用 AWS CloudTrail](logging-using-cloudtrail.md)。

您可以使用 CloudFormation执行以下 PITR 操作。
+ 创建启用或禁用 PITR 的新表。
+ 为现有表启用或禁用 PITR。

有关更多信息，请参阅《[CloudFormation 用户指南](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/)》中的 [Cassandra 资源类型参考](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/AWS_Cassandra.html)。

# 在 Amazon Keyspaces 中使用 point-in-time恢复功能
<a name="PointInTimeRecovery_Tutorial"></a>

使用 Amazon Keyspaces（适用于 Apache Cassandra），您可以使用恢复 (PITR) 将表 Point-in-Time还原到特定的时间点。PITR 使您能够将表还原到最近 35 天内的先前状态，从而提供数据保护和恢复功能。在意外删除数据、应用程序错误或想要进行测试的情况下，此特征非常有用。您可以快速有效地恢复数据，从而最大限度地减少停机时间和数据丢失。以下各节将指导您完成在 Amazon Keyspaces 中使用 PITR 还原表的过程，确保数据完整性和业务连续性。

**Topics**
+ [为 Amazon Keyspaces PITR 配置还原表 IAM 权限](howitworks_restore_permissions.md)
+ [在 Amazon Keyspaces 中为表配置 PITR](configure_PITR.md)
+ [关闭 Amazon Keyspaces 表的 PITR](disable_PITR.md)
+ [在 Amazon Keyspaces 中将表从备份还原到指定的时间点](restoretabletopointintime.md)
+ [使用 Amazon Keyspaces PITR 还原已删除的表](restoredeleted.md)

# 为 Amazon Keyspaces PITR 配置还原表 IAM 权限
<a name="howitworks_restore_permissions"></a>

本节总结了如何为 AWS Identity and Access Management (IAM) 委托人配置恢复 Amazon Keyspaces 表的权限。在 IAM 中， AWS 托管式策略 `AmazonKeyspacesFullAccess` 包括还原 Amazon Keyspaces 表所需的权限。要实施具有最低所需权限的自定义策略，请考虑下一节中概述的要求。

要成功还原表，IAM 主体需要以下最低权限：
+ `cassandra:Restore`：需要执行还原操作才能还原目标表。
+ `cassandra:Select`：需要执行选择操作才能从源表中读取数据。
+ `cassandra:TagResource`：标签操作是可选的，只有在还原操作添加标签时才需要执行此操作。

下面举例说明了向用户授予还原键空间 `mykeyspace` 中的表所需的最低权限的策略。

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement":[
      {
         "Effect":"Allow",
         "Action":[
            "cassandra:Restore",
            "cassandra:Select"
         ],
         "Resource":[
            "arn:aws:cassandra:us-east-1:111122223333:/keyspace/mykeyspace/*",
            "arn:aws:cassandra:us-east-1:111122223333:/keyspace/system*"
         ]
      }
   ]
}
```

根据选定的其他功能，可能需要其他权限才能还原表。例如，如果使用客户自主管理型密钥对源表进行静态加密，则 Amazon Keyspaces 必须有权访问源表的客户自主管理型密钥才能成功还原表。有关更多信息，请参阅 [使用 PITR 还原加密表](PointInTimeRecovery_HowItWorks.md#howitworks_backup_encryption)。

如果您使用带有[条件键](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html)的 IAM 策略来限制特定源的传入流量，则必须确保 Amazon Keyspaces 有权代表您的主体执行还原操作。如果您的策略将传入流量限制为以下任一项，则您必须将 `aws:ViaAWSService` 条件键添加到 IAM 策略：
+ 具有 `aws:SourceVpce` 的 VPC 端点
+ 使用 `aws:SourceIp` 的 IP 范围
+ VPCs 与 `aws:SourceVpc`

`aws:ViaAWSService` 条件键允许在任何 AWS 服务使用主体的凭证发出请求时进行访问。有关更多信息，请参阅《IAM 用户指南》**中的 [IAM JSON 策略元素：条件键](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html)。

以下是将源流量限制到特定 IP 地址并允许 Amazon Keyspaces 代表主体还原表的策略示例。

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement":[
      {
         "Sid":"CassandraAccessForCustomIp",
         "Effect":"Allow",
         "Action":"cassandra:*",
         "Resource":"*",
         "Condition":{
            "Bool":{
               "aws:ViaAWSService":"false"
            },
            "ForAnyValue:IpAddress":{
               "aws:SourceIp":[
                  "123.45.167.89"
               ]
            }
         }
      },
      {
         "Sid":"CassandraAccessForAwsService",
         "Effect":"Allow",
         "Action":"cassandra:*",
         "Resource":"*",
         "Condition":{
            "Bool":{
               "aws:ViaAWSService":"true"
            }
         }
      }
   ]
}
```

 有关使用 `aws:ViaAWSService` 全局条件键的策略示例，请参阅 [VPC 终端节点策略和 Amazon Keyspaces point-in-time 恢复 (PITR)](vpc-endpoints.md#VPC_PITR_restore)。

# 在 Amazon Keyspaces 中为表配置 PITR
<a name="configure_PITR"></a>

您可以通过控制台、CQL 和 AWS CLI，使用 PITR 在 Amazon Keyspaces 中为备份和还原操作配置表。

使用 CQL 或创建新表时 AWS CLI，必须在创建表语句中明确启用 PITR。使用控制台创建新表时，PITR 将默认处于启用状态。

要了解如何还原表，请参阅[在 Amazon Keyspaces 中将表从备份还原到指定的时间点](restoretabletopointintime.md)。

------
#### [ Console ]

**使用控制台为表配置 PITR**

1. [登录并在家中打开 Amazon Keyspaces 控制台。 AWS 管理控制台 https://console.aws.amazon.com/keyspaces/](https://console.aws.amazon.com/keyspaces/home)

1. 在导航窗格中，选择**表**，然后选择要编辑的表。

1. 在**备份**选项卡上，选择**编辑**。

1. 在 **“编辑 point-in-time恢复设置”** 部分中，选择 “**启用 Point-in-time恢复**”。

1. 选择**保存更改**。

------
#### [ Cassandra Query Language (CQL) ]

**使用 CQL 为表配置 PITR**

1. 您可以使用 `point_in_time_recovery` 自定义属性管理表的 PITR 设置。

   要在创建新表时启用 PITR，必须将 `point_in_time_recovery` 的状态设置为 `enabled`。例如，您可以使用以下 CQL 命令：

   ```
   CREATE TABLE "my_keyspace1"."my_table1"(
   	"id" int,
   	"name" ascii,
   	"date" timestamp,
   	PRIMARY KEY("id"))
   WITH CUSTOM_PROPERTIES = {
   	'capacity_mode':{'throughput_mode':'PAY_PER_REQUEST'}, 
   	'point_in_time_recovery':{'status':'enabled'}
   }
   ```
**注意**  
如果未指定 point-in-time恢复自定义属性，则默认情况下会禁用 point-in-time恢复。

1. 要使用 CQL 为现有表启用 PITR，请运行以下 CQL 命令。

   ```
   ALTER TABLE mykeyspace.mytable
   WITH custom_properties = {'point_in_time_recovery': {'status': 'enabled'}}
   ```

------
#### [ CLI ]

**使用以下命令为表格配置 PITR AWS CLI**

1. 您可以使用 `UpdateTable` API 管理表的 PITR 设置。

   要在创建新表时启用 PITR，必须在创建表命令中包含 `point-in-time-recovery 'status=ENABLED'`。例如，您可以使用以下 AWS CLI 命令。为了提高可读性，该命令已分成不同的行。

   ```
   aws keyspaces create-table --keyspace-name 'myKeyspace' --table-name 'myTable' 
               --schema-definition 'allColumns=[{name=id,type=int},{name=name,type=text},{name=date,type=timestamp}],partitionKeys=[{name=id}]' 
               --point-in-time-recovery 'status=ENABLED'
   ```
**注意**  
如果未指定 point-in-time恢复值，则默认情况下会禁用 point-in-time恢复。

1. 要确认表的 point-in-time恢复设置，可以使用以下 AWS CLI 命令。

   ```
   aws keyspaces get-table --keyspace-name 'myKeyspace' --table-name 'myTable'
   ```

1. 要使用为现有表启用 PITR AWS CLI，请运行以下命令。

   ```
   aws keyspaces update-table --keyspace-name 'myKeyspace' --table-name 'myTable' --point-in-time-recovery 'status=ENABLED'
   ```

------

# 关闭 Amazon Keyspaces 表的 PITR
<a name="disable_PITR"></a>

您可以随时使用控制台、CQL 或 AWS CLI关闭 Amazon Keyspaces 表的 PITR。

**重要**  
禁用 PITR 会立即删除您的备份历史记录，即使您在 35 天内为表重新启用 PITR 也是如此。

要了解如何还原表，请参阅[在 Amazon Keyspaces 中将表从备份还原到指定的时间点](restoretabletopointintime.md)。

------
#### [ Console ]

**使用控制台禁用表的 PITR**

1. [登录并在家中打开 Amazon Keyspaces 控制台。 AWS 管理控制台 https://console.aws.amazon.com/keyspaces/](https://console.aws.amazon.com/keyspaces/home)

1. 在导航窗格中，选择**表**，然后选择要编辑的表。

1. 在**备份**选项卡上，选择**编辑**。

1. 在 **“编辑 point-in-time恢复设置”** 部分中，清除 “**启用 Point-in-time恢复” 复**选框。

1. 选择**保存更改**。

------
#### [ Cassandra Query Language (CQL) ]

**使用 CQL 禁用表的 PITR**
+ 要为现有表禁用 PITR，请运行以下 CQL 命令。

  ```
  ALTER TABLE mykeyspace.mytable
  WITH custom_properties = {'point_in_time_recovery': {'status': 'disabled'}}
  ```

------
#### [ CLI ]

**使用以下命令对表格禁用 PITR AWS CLI**
+ 要对现有表禁用 PITR，请运行以下 AWS CLI 命令。

  ```
  aws keyspaces update-table --keyspace-name 'myKeyspace' --table-name 'myTable' --point-in-time-recovery 'status=DISABLED'
  ```

------

# 在 Amazon Keyspaces 中将表从备份还原到指定的时间点
<a name="restoretabletopointintime"></a>

下面一节演示了如何将现有 Amazon Keyspaces 表还原到指定的时间点。

**注意**  
此过程假设您正在使用的表已配置为 point-in-time恢复功能。要为表启用 PITR，请参阅[在 Amazon Keyspaces 中为表配置 PITR](configure_PITR.md)。

**重要**  
 在恢复过程中，请勿修改或删除授予 IAM 委托人（例如用户、群组或角色）执行恢复权限的 (IAM) 策略。 AWS Identity and Access Management 否则，可能会出现意外行为。例如，如果在还原表时删除表的写入权限，则底层 `RestoreTableToPointInTime` 操作将无法向表中写入任何还原的数据。  
您只能在还原操作完成之后修改或删除权限。

------
#### [ Console ]

**使用控制台将表还原到指定的时间点。**

1. [登录并在家中打开 Amazon Keyspaces 控制台。 AWS 管理控制台 https://console.aws.amazon.com/keyspaces/](https://console.aws.amazon.com/keyspaces/home)

1. 在控制台左侧的导航窗格中，选择**表**。

1. 在表列表中，选择要还原的表。

1. 在该表的 “**备份**” 选项卡上，在 “**Point-in-time 恢复**” 部分中，选择 “**恢复**”。

1. 对于新表名，为已还原的表输入一个新名称，例如 **mytable\$1restored**。

1. 要定义还原操作的时间点，可以在两个选项之间进行选择：
   + 选择预配置的**最早**时间。
   + 选择**指定日期和时间**并输入要将新表还原到的日期和时间。
**注意**  
您可以还原到**最早**时间和当前时间之间的任何时间点。Amazon Keyspaces 会根据所选日期和时间 (day:hour:minute:second) 将表数据还原到相应状态。

1. 选择**还原**，启动还原过程。

   正在还原的表显示状态为 **Restoring (正在还原)**。还原过程完成后，已还原表的状态更改为**活动**。

------
#### [ Cassandra Query Language (CQL) ]

**使用 CQL 将表还原到某个时间点**

1. 您可以将活动表恢复到介于当前时间 point-in-time`earliest_restorable_timestamp`之间。默认值为当前时间。

   要确认该表已启用 point-in-time恢复，请查询，`system_schema_mcs.tables`如本示例所示。

   ```
   SELECT custom_properties
   FROM system_schema_mcs.tables
   WHERE keyspace_name = 'mykeyspace' AND table_name = 'mytable';
   ```

   Point-in-time 恢复已启用，如以下示例输出所示。

   ```
   custom_properties
   -----------------
   {
     ...,
       "point_in_time_recovery": {
       "earliest_restorable_timestamp":"2020-06-30T19:19:21.175Z"
       "status":"enabled"
     }
   }
   ```

1. 
   + 将表还原到当前时间。如果省略 `WITH restore_timestamp = ...` 子句，系统将使用当前时间戳。

     ```
     RESTORE TABLE mykeyspace.mytable_restored
     FROM TABLE mykeyspace.mytable;
     ```
   + 也可以还原到以 ISO 8601 格式的 `restore_timestamp` 定义的特定时间点。您可以指定最近 35 天内的任何时间点。例如，以下命令使表还原到 `EarliestRestorableDateTime`。

     ```
     RESTORE TABLE mykeyspace.mytable_restored
     FROM TABLE mykeyspace.mytable
     WITH restore_timestamp = '2020-06-30T19:19:21.175Z';
     ```

     有关完整的语法描述，请参阅语言参考中的 [RESTORE TABLE](cql.ddl.table.md#cql.ddl.table.restore)。

1. 要验证表的还原是否成功，请查询 `system_schema_mcs.tables`，确认表的状态。

   ```
   SELECT status
   FROM system_schema_mcs.tables
   WHERE keyspace_name = 'mykeyspace' AND table_name = 'mytable_restored'
   ```

   该查询会显示以下输出。

   ```
   status
   ------
   RESTORING
   ```

   正在还原的表显示状态为 **Restoring (正在还原)**。还原过程完成后，表的状态更改为**活动**。

------
#### [ CLI ]

**使用将表还原到某个时间点 AWS CLI**

1. 创建一个名为 `myTable` 且启用了 PITR 的简单表。为了便于阅读，该命令已分成不同的行。

   ```
   aws keyspaces create-table --keyspace-name 'myKeyspace' --table-name 'myTable' 
               --schema-definition 'allColumns=[{name=id,type=int},{name=name,type=text},{name=date,type=timestamp}],partitionKeys=[{name=id}]' 
               --point-in-time-recovery 'status=ENABLED'
   ```

1. 确认新表的属性并查看 PITR 的 `earliestRestorableTimestamp`。

   ```
   aws keyspaces get-table --keyspace-name 'myKeyspace' --table-name 'myTable'
   ```

   该命令的输出返回了以下内容。

   ```
   {
       "keyspaceName": "myKeyspace",
       "tableName": "myTable",
       "resourceArn": "arn:aws:cassandra:us-east-1:111122223333:/keyspace/myKeyspace/table/myTable",
       "creationTimestamp": "2022-06-20T14:34:57.049000-07:00",
       "status": "ACTIVE",
       "schemaDefinition": {
           "allColumns": [
               {
                   "name": "id",
                   "type": "int"
               },
               {
                   "name": "date",
                   "type": "timestamp"
               },
               {
                   "name": "name",
                   "type": "text"
               }
           ],
           "partitionKeys": [
               {
                   "name": "id"
               }
           ],
           "clusteringKeys": [],
           "staticColumns": []
       },
       "capacitySpecification": {
           "throughputMode": "PAY_PER_REQUEST",
           "lastUpdateToPayPerRequestTimestamp": "2022-06-20T14:34:57.049000-07:00"
       },
       "encryptionSpecification": {
           "type": "AWS_OWNED_KMS_KEY"
       },
       "pointInTimeRecovery": {
           "status": "ENABLED",
           "earliestRestorableTimestamp": "2022-06-20T14:35:13.693000-07:00"
       },
       "defaultTimeToLive": 0,
       "comment": {
           "message": ""
       }
   }
   ```

1. 
   + 要将表还原到某个时间点，请指定 ISO 8601 格式的 `restore_timestamp`。您可以选择最近 35 天中的任何时间点，时间间隔为 1 秒。例如，以下命令使表还原到 `EarliestRestorableDateTime`。

     ```
     aws keyspaces restore-table --source-keyspace-name 'myKeyspace' --source-table-name 'myTable' --target-keyspace-name 'myKeyspace' --target-table-name 'myTable_restored' --restore-timestamp "2022-06-20 21:35:14.693"
     ```

     此命令的输出会返回已还原的表的 ARN。

     ```
     {
         "restoredTableARN": "arn:aws:cassandra:us-east-1:111122223333:/keyspace/myKeyspace/table/myTable_restored"
     }
     ```
   + 要将该表还原到当前时间，可以省略 `restore-timestamp` 参数。

     ```
     aws keyspaces restore-table --source-keyspace-name 'myKeyspace' --source-table-name 'myTable' --target-keyspace-name 'myKeyspace' --target-table-name 'myTable_restored1'"
     ```

------

# 使用 Amazon Keyspaces PITR 还原已删除的表
<a name="restoredeleted"></a>

以下过程展示了如何将已删除的表从备份中还原到删除时的状态。您可以使用 CQL 或. AWS CLI

**注意**  
此过程假定您已为删除的表启用 PITR。



------
#### [ Cassandra Query Language (CQL) ]

**使用 CQL 还原已删除的表**

1. 要确认已对已删除的表启用了 point-in-time恢复，请查询系统表。仅显示启用了 point-in-time恢复功能的表。

   ```
   SELECT custom_properties
   FROM system_schema_mcs.tables_history 
   WHERE keyspace_name = 'mykeyspace' AND table_name = 'my_table';
   ```

   该查询会显示以下输出。

   ```
   custom_properties
   ------------------
   {
       ...,
      "point_in_time_recovery":{
         "restorable_until_time":"2020-08-04T00:48:58.381Z",
         "status":"enabled"
      }
   }
   ```

1. 使用以下示例语句将表还原到删除时的状态。

   ```
   RESTORE TABLE mykeyspace.mytable_restored
   FROM TABLE mykeyspace.mytable;
   ```

------
#### [ CLI ]

**使用恢复已删除的表 AWS CLI**

1. 删除您之前创建且启用了 PITR 的表。以下命令是一个示例。

   ```
   aws keyspaces delete-table --keyspace-name 'myKeyspace' --table-name 'myTable'
   ```

1. 使用以下命令将已删除的表还原到删除时的状态。

   ```
   aws keyspaces restore-table --source-keyspace-name 'myKeyspace' --source-table-name 'myTable' --target-keyspace-name 'myKeyspace' --target-table-name 'myTable_restored2'
   ```

   此命令的输出会返回已还原的表的 ARN。

   ```
   {
       "restoredTableARN": "arn:aws:cassandra:us-east-1:111122223333:/keyspace/myKeyspace/table/myTable_restored2"
   }
   ```

------