将 DynamoDB 表还原到某个时间点 - Amazon DynamoDB
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

将 DynamoDB 表还原到某个时间点

Amazon DynamoDB 时间点恢复 (PITR) 提供 DynamoDB 表数据的持续备份。您可以使用 DynamoDB 控制台或 Amazon Command Line Interface (Amazon CLI) 将表还原到某个时间点。时间点恢复过程始终还原到新表。

如果要使用 Amazon CLI,必须先配置。有关更多信息,请参阅 访问 DynamoDB

将 DynamoDB 表还原到某个时间点(控制台)

以下示例演示如何使用 DynamoDB 控制台将名为 Music 的现有表还原到某个时间点。

注意

此过程假定已启用时间点恢复。要为 Music 表启用该功能,在 Backups (备份) 选项卡上的 Point-in-time recovery (PITR) (时间点恢复 (PITR)) 部分,选择 Edit (编辑),然后选中 Enable point-in-time-recovery (启用时间点恢复) 旁边的复选框。

将表还原到某个时间点
  1. 登录 Amazon Web Services Management Console,打开 DynamoDB 控制台:https://console.aws.amazon.com/dynamodb/

  2. 在控制台左侧的导航窗格中,选择 Tables (表)

  3. 在表的列表中,选择 Music 表。

  4. Music 表的 Backups (备份) 选项卡的 Point-in-time recovery (PITR) (时间点恢复 (PITR)) 部分,选择 Restore (还原)

  5. 对于新表名称,输入 MusicMinutesAgo

    注意

    您可以将表还原到同一 Amazon 区域或源表所在的其他区域。您还可以阻止在还原的表上创建二级索引。此外,您可以指定其他加密模式。

  6. 要确认可还原时间,请将还原日期和时间设置为 Earliest (最早)。然后选择 Restore (还原) 来启动还原过程。

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

将表还原到某个时间点(Amazon CLI)

以下过程演示如何使用 Amazon CLI 将名为 Music 的现有表还原到某个时间点。

注意

此过程假定已启用时间点恢复。要为 Music 表启用,请运行下面的命令。

aws dynamodb update-continuous-backups \ --table-name Music \ --point-in-time-recovery-specification PointInTimeRecoveryEnabled=True

将表还原到某个时间点
  1. 通过使用 Music 命令来确认已为 describe-continuous-backups 表启用时间点恢复。

    aws dynamodb describe-continuous-backups \ --table-name Music

    已启用持续备份 (在创建表时自动启用) 和时间点恢复。

    { "ContinuousBackupsDescription": { "PointInTimeRecoveryDescription": { "PointInTimeRecoveryStatus": "ENABLED", "EarliestRestorableDateTime": 1519257118.0, "LatestRestorableDateTime": 1520018653.01 }, "ContinuousBackupsStatus": "ENABLED" } }
  2. 使表还原到某个时间点。在此示例中,对于同一 Amazon 区域,Music 表将还原到 LatestRestorableDateTime(约 5 分钟前)。

    aws dynamodb restore-table-to-point-in-time \ --source-table-name Music \ --target-table-name MusicMinutesAgo \ --use-latest-restorable-time
    注意

    您还可以还原到特定时间点。为此,请运行使用 --restore-date-time 参数的命令,并指定时间戳。您可以指定最近 35 天内的任何时间点。例如,以下命令使表还原到 EarliestRestorableDateTime

    aws dynamodb restore-table-to-point-in-time \ --source-table-name Music \ --target-table-name MusicEarliestRestorableDateTime \ --no-use-latest-restorable-time \ --restore-date-time 1519257118.0

    在还原到特定时间点时,指定 --no-use-latest-restorable-time 参数是可选的。

  3. 使用自定义表设置将表还原到某个时间点。在此示例中,Music 表还原到 LatestRestorableDateTime (~5 分钟前)。

    您可以为还原的表指定其他加密模式,如下所示。

    注意

    sse-specification-override 参数采用与 CreateTable 命令中使用的 sse-specification-override 参数相同的值。要了解更多信息,请参阅 管理 DynamoDB 中的加密表

    aws dynamodb restore-table-to-point-in-time \ --source-table-name Music \ --target-table-name MusicMinutesAgo \ --use-latest-restorable-time \ --sse-specification-override Enabled=true,SSEType=KMS,KMSMasterKeyId=abcd1234-abcd-1234-a123-ab1234a1b234

    可以将表还原到源表所在的其他 Amazon 区域。

    注意
    • sse-specification-override 参数对于跨区域还原是必需的,但对于到与源表相同的区域的还原是可选的。

    • 必须为跨区域还原提供 source-table-arn 参数。

    • 在从命令行执行跨区域还原时,您必须将默认 Amazon 区域设置为所需的目标区域。要了解更多信息,请参阅《Amazon Command Line Interface 用户指南》中的命令行选项

    aws dynamodb restore-table-to-point-in-time \ --source-table-arn arn:aws:dynamodb:us-east-1:123456789012:table/Music \ --target-table-name MusicMinutesAgo \ --use-latest-restorable-time \ --sse-specification-override Enabled=true,SSEType=KMS,KMSMasterKeyId=abcd1234-abcd-1234-a123-ab1234a1b234

    您可以覆盖已还原表的计费模式和预配置的吞吐量。

    aws dynamodb restore-table-to-point-in-time \ --source-table-name Music \ --target-table-name MusicMinutesAgo \ --use-latest-restorable-time \ --billing-mode-override PAY_PER_REQUEST

    您可以阻止在还原的表上创建部分或所有二级索引。

    注意

    如果您阻止在新的还原表上创建部分或所有二级索引,则还原操作会更快且更具成本效益。

    aws dynamodb restore-table-to-point-in-time \ --source-table-name Music \ --target-table-name MusicMinutesAgo \ --use-latest-restorable-time \ --global-secondary-index-override '[]'

    您可以组合使用不同的替代方式。例如,您可以使用单个全局二级索引并同时更改预配置的吞吐量,如下所示。

    aws dynamodb restore-table-to-point-in-time \ --source-table-name Music \ --target-table-name MusicMinutesAgo \ --billing-mode-override PROVISIONED \ --provisioned-throughput-override ReadCapacityUnits=100,WriteCapacityUnits=100 \ --global-secondary-index-override IndexName=singers-index,KeySchema=["{AttributeName=SingerName,KeyType=HASH}"],Projection="{ProjectionType=KEYS_ONLY}",ProvisionedThroughput="{ReadCapacityUnits=50,WriteCapacityUnits=50}" \ --sse-specification-override Enabled=true,SSEType=KMS \ --use-latest-restorable-time

要验证还原,请使用 describe-table 命令来描述 MusicEarliestRestorableDateTime 表。

aws dynamodb describe-table --table-name MusicEarliestRestorableDateTime

正在还原的表显示状态为 Creating (正在创建),并且正在还原为 true。还原过程完成后,MusicEarliestRestorableDateTime 表的状态更改为 Active (活动)

重要

正在还原时,请勿修改或删除授予 IAM 实体(例如,用户、组或角色)执行还原的权限的 Amazon Identity and Access Management (IAM) 策略。否则,可能会出现意外行为。例如,假设您在还原表时删除了对该表的写入权限。在这种情况下,底层 RestoreTableToPointInTime 操作将无法向表中写入任何还原的数据。请注意,涉及有关访问目标还原表的源 IP 限制的 IAM policy 也可能同样导致问题。

您只能在还原操作完成之后修改或删除权限。