Restoring an Amazon Keyspaces Table to a Point in Time - Amazon Keyspaces (for Apache Cassandra)

Restoring an Amazon Keyspaces Table to a Point in Time

Amazon Keyspaces (for Apache Cassandra) point-in-time recovery (PITR) provides continuous backups of your Amazon Keyspaces table data. This tutorial shows you how to restore a table to a point in time by using the Amazon Keyspaces console or Cassandra Query Language (CQL), and how to restore a deleted table using CQL.

Restoring a Table to a Point in Time (console)

The following example demonstrates how to use the Amazon Keyspaces console to restore an existing table named mytable to a point in time.

Note

This procedure assumes that you have enabled point-in-time recovery. To enable PITR for the mytable table, follow the steps in Enabling PITR with the AWS Management Console.

  1. Sign in to the AWS Management Console, and open the Amazon Keyspaces (for Apache Cassandra) console at https://console.aws.amazon.com/keyspaces/home.

  2. In the navigation pane on the left side of the console, choose Tables.

  3. In the list of tables, choose the mytable table.

  4. On the Backups tab of the mytable table, in the Point-in-time recovery section, choose Restore.

  5. For the new table name, enter mytable_restored.

  6. To define the point in time for the restore operation, you can choose between two options:

    • Select the preconfigured Earliest time.

    • Select Specify date and time and enter the date and time you want to restore the new table to.

    Note

    You can restore to any point in time within Earliest time and the current time. Amazon Keyspaces restores your table data to the state based on the selected date and time (day:hour:minute:second).

  7. Choose Restore to start the restore process.

    The table that is being restored is shown with the status Restoring. After the restore process is finished, the status of the mytable_restored table changes to Active.

    Important

    While a restore is in progress, don't modify or delete the AWS Identity and Access Management (IAM) policies that grant the IAM entity (for example, user, group, or role) permission to perform the restore. Otherwise, unexpected behavior can result. For example, suppose that you removed write permissions for a table while that table was being restored. In this case, the underlying RestoreTableToPointInTime operation can't write any of the restored data to the table.

    You can modify or delete permissions only after the restore operation is completed.

Restoring a Table to a Point in Time with CQL

The following procedure shows how to use CQL to restore an existing table named mytable to a point in time.

Note

This procedure assumes that you have enabled point-in-time recovery. To enable PITR on the table, follow the steps in Enabling PITR Programmatically.

  1. You can restore an active table to a point-in-time between earliest_restorable_timestamp and the current time. Current time is the default.

    To confirm that point-in-time recovery is enabled for the mytable table, query the system_schema_mcs.tables as follows.

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

    Point-in-time recovery is enabled as shown in the following sample output.

    custom_properties ----------------- { ..., "point_in_time_recovery": { "earliest_restorable_timestamp":"2020-06-30T19:19:21.175Z" "status":"enabled" } }
  2. Restore the table to a point in time. In this case, the mytable table is restored to the current time. You can omit the WITH restore_timestamp = ... clause. Without the clause, the current timestamp is used.

    RESTORE TABLE mykeyspace.mytable_restored FROM TABLE mykeyspace.mytable;

    You can also restore to a specific point in time. You can specify any point in time during the last 35 days. For example, the following command restores the table to the EarliestRestorableDateTime.

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

    For a full syntax description, see RESTORE TABLE in the language reference.

To verify that the restore of the table was successful, query the system_schema_mcs.tables to confirm the status of the table.

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

The query shows the following output.

status ------ RESTORING

The table that is being restored is shown with the status Restoring. After the restore process is finished, the status of the mytable_restored table changes to Active.

Important

While a restore is in progress, don't modify or delete the AWS Identity and Access Management (IAM) policies that grant the IAM entity (for example, user, group, or role) permission to perform the restore. Otherwise, unexpected behavior can result. For example, suppose that you removed write permissions for a table while that table was being restored. In this case, the underlying RestoreTableToPointInTime operation can't write any of the restored data to the table.

You can modify or delete permissions only after the restore operation is completed.

Restoring a Deleted Table with CQL

The following procedure shows how to use CQL to restore a deleted table named mytable to the time of deletion.

Note

This procedure assumes that PITR was enabled on the deleted table.

  1. To confirm that point-in-time recovery is enabled for a deleted table, query the system table. Only tables with point-in-time recovery enabled are shown.

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

    The query shows the following output.

    custom_properties ------------------ { ..., "point_in_time_recovery":{ "restorable_until_time":"2020-08-04T00:48:58.381Z", "status":"enabled" } }
  2. Restore the table to the time of deletion with the following sample statement.

    RESTORE TABLE mykeyspace.mytable_restored FROM TABLE mykeyspace.mytable;