本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
将 Amazon Keyspaces 表还原到某个时间点。
Amazon Keyspaces(适用于 Apache Cassandra) point-in-time 恢复 (PITR) 允许您将亚马逊 Keyspaces 表数据恢复到过去 35 天内的任何时间点。本教程的第一部分向您展示如何使用 Amazon Keyspaces 控制台、() 和 Cassandra 查询语言Amazon Command Line Interface (CQLAmazon CLI) 将表恢复到某个时间点。第二部分向您展示如何使用Amazon CLI和 CQL 恢复已删除的表。
主题
开始前的准备工作
如果您尚未执行此操作,必须为用户配置相应的权限以还原Amazon Keyspaces 表。在Amazon Identity and Access Management (IAM) 中,Amazon托管策略AmazonKeyspacesFullAccess
包括恢复 Amazon Keyspaces 表的权限。有关实施具有最低所需权限的策略的详细步骤,请参阅还原表所需的权限。
将表还原到某个时间点(控制台)
以下示例演示如何使用 Amazon Keyspaces e 控制台将名为的现有表还原mytable
到某个时间点。
注意
此过程假设已启用 point-in-time 恢复。要为mytable
表格启用 PITR,请按照中的步骤操作使用控制台启用 PITR。
登录并打开 Amazon Keyspaces e 控制台,网址为 https://console.aws.amazon.com/keyspaces/home
。Amazon Web Services Management Console -
在控制台左侧的导航窗格中,选择 Tables (表)。
-
在表的列表中,选择
mytable
表。 -
在
mytable
表的备份选项卡上的 Point-in-time 恢复部分中,选择恢复。 -
对于新表名称,输入
mytable_restored
。 -
要定义还原操作的时间点,可以在两个选项之间进行选择:
选择预配置的最早时间。
选择指定日期和时间并输入要将新表还原到的日期和时间。
注意
您可以还原到最早时间和当前时间中的任何时间点。Amazon Keyspaces e 将您的表日期和时间的状态。
选择 “还原” 开始还原过程。
正在还原的表显示状态为 Restoring (正在还原)。还原过程完成后,
mytable_restored
表的状态更改为 Active (活动)。重要
正在还原时,请勿修改或删除授予 IAM 实体(例如,用户、组或角色)执行还原的权限的 Amazon Identity and Access Management (IAM) 策略。否则,可能会出现意外行为。例如,假设您在恢复表时删除了该表的写入权限。在这种情况下,底层
RestoreTableToPointInTime
操作将无法向表中写入任何还原的数据。您只能在还原操作完成之后修改或删除权限。
使用使用使用将表还原到某个时间点。Amazon CLI
以下过程演示如何使用 Amazon CLI 将名为 myTable
的现有表还原到某个时间点。
在第一步中,创建一个名为的启用了 PITR
myTable
的简单表。为了便于阅读,该命令已分成几行。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'
确认新表的属性并查看
earliestRestorableTimestamp
PITR。aws keyspaces get-table --keyspace-name 'myKeyspace' --table-name 'myTable'
此命令的输出将返回以下内容。
{ "keyspaceName": "myKeyspace", "tableName": "myTable", "resourceArn": "arn:aws:cassandra:us-east-1:111222333444:/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": "" } }
您可以在一秒钟的时间间隔内将活动表恢复到
earliestRestorableTimestamp
与当前时间 point-in-time 之间的任何时间。当前时间是默认时间。-
要将表还原到某个时间点,使用 ISO 8601 格式指定 a
restore_timestamp
。您可以以一秒的间隔选择最近 35 天中的任何时间点。例如,以下命令使表还原到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:111222333444:/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'"
重要
正在还原时,请勿修改或删除授予 IAM 实体(例如,用户、组或角色)执行还原的权限的 Amazon Identity and Access Management (IAM) 策略。否则,可能会出现意外行为。例如,假设您在恢复表时删除了该表的写入权限。在这种情况下,底层 RestoreTableToPointInTime
操作将无法向表中写入任何还原的数据。
您只能在还原操作完成之后修改或删除权限。
使用 CQL 将表还原到某个时间点。
以下过程演示如何使用 CQL 将名为的现有表还原mytable
到某个时间点。
注意
此过程假设已启用 point-in-time 恢复。要在表格上启用 PITR,请按照中的步骤操作使用 CQL 启用 PITR。
-
您可以将活动表恢复到 point-in-time 介于当前时间
earliest_restorable_timestamp
之间。当前时间是默认时间。要确认
mytable
表的 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" } }
-
将表恢复到 ISO 8601 格式
restore_timestamp
中由 a 指定的时间点。在这种情况下,mytable
表还原到当前时间。您可以WITH restore_timestamp = ...
。如果不使用该子句,则使用当前时间戳。RESTORE TABLE mykeyspace.mytable_restored FROM TABLE mykeyspace.mytable;
您还可以还原到特定时间点。您可以指定最近 35 天内的任何时间点。例如,以下命令使表还原到
EarliestRestorableDateTime
。RESTORE TABLE mykeyspace.mytable_restored FROM TABLE mykeyspace.mytable WITH restore_timestamp = '2020-06-30T19:19:21.175Z';
有关完整的语法描述,请参阅恢复表语言参考中的。
要验证表的还原是否成功,请查询system_schema_mcs.tables
以确认表的状态。
SELECT status FROM system_schema_mcs.tables WHERE keyspace_name = 'mykeyspace' AND table_name = 'mytable_restored'
该查询显示以下输出。
status ------ RESTORING
正在还原的表显示状态为 Restoring (正在还原)。还原过程完成后,mytable_restored
表的状态更改为 Active (活动)。
重要
正在还原时,请勿修改或删除授予 IAM 实体(例如,用户、组或角色)执行还原的权限的 Amazon Identity and Access Management (IAM) 策略。否则,可能会出现意外行为。例如,假设您在恢复表时删除了该表的写入权限。在这种情况下,底层 RestoreTableToPointInTime
操作将无法向表中写入任何还原的数据。
您只能在还原操作完成之后修改或删除权限。
使用恢复已删除的表Amazon CLI
以下过程显示如何使用恢复名myTable
为删除时的已删除表。Amazon CLI
注意
此过程假设已在已删除的表上启用了 PITR。
-
删除您在上一教程中创建的表。
aws keyspaces delete-table --keyspace-name 'myKeyspace' --table-name 'myTable'
-
使用以下命令将已删除的表恢复到删除时。
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:111222333444:/keyspace/myKeyspace/table/myTable_restored2" }
使用 CQL 恢复已删除的表
以下过程显示如何使用 CQL 恢复名mytable
为删除时的已删除表。
注意
此过程假设已在已删除的表上启用了 PITR。
-
要确认已为已删除的表启用 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" } }
-
使用以下示例语句将表恢复到删除时。
RESTORE TABLE mykeyspace.mytable_restored FROM TABLE mykeyspace.mytable;