

# Restore a table in DynamoDB
<a name="pointintimerecovery_restores"></a>

You can restore a DynamoDB table from your PITR backup or your on-demand backups using the Amazon Web Services Management Console, the Amazon Command Line Interface (Amazon CLI), or the DynamoDB API. The recovery process restores to a new DynamoDB table.

## Restoring a table using point-in-time recovery
<a name="pointintimerecovery-pitr-restore"></a>

You can restore your table to any point in time up till the `EarliestRestoreableDateTime`.

**Important**  
If you disable point-in-time recovery and later enable it on a table, you reset the start time for which you can recover that table. As a result, you can only immediately restore that table using the `LatestRestorableDateTime`.

When you restore using point-in-time recovery, DynamoDB restores your table data to the state based on the selected date and time (day:hour:minute:second) to a new table. You restore a table without consuming any provisioned throughput on the table. You can do a full table restore using point-in-time recovery, or you can configure the destination table settings. You can change the following table settings on the restored table: 
+ Global secondary indexes (GSIs)
+ Local secondary indexes (LSIs)
+ Billing mode
+ Provisioned read and write capacity
+ Encryption settings

**Important**  
When you do a full table restore, the destination table is set with the same provisioned read capacity units and write capacity units that the source table had when the backup was requested. For example, suppose that a table's provisioned throughput was recently lowered to 50 read capacity units and 50 write capacity units. You then restore the table's state to three weeks ago, at which time its provisioned throughput was set to 100 read capacity units and 100 write capacity units. In this case, DynamoDB restores your table data to that point in time with the provisioned throughput from that time (100 read capacity units and 100 write capacity units).

You can also restore your DynamoDB table data across Amazon Web Services Regions such that the restored table is created in a different Region from where the source table resides. You can do cross-Region restores between Amazon commercial Regions, Amazon China Regions, and Amazon GovCloud (US). You pay only for the data you transfer out of the source Region and for restoring to a new table in the destination Region.

**Note**  
Cross-Region restore isn't supported if the source or destination Region is Asia Pacific (Hong Kong) or Middle East (Bahrain).

Restores can be faster and more cost-efficient if you exclude some or all indexes from being created on the restored table. You must manually set the following on the restored table: 
+ Auto scaling policies
+ Amazon Identity and Access Management policies
+ Amazon CloudWatch Events metrics and alarms
+ Tags
+ Stream settings
+ Time to Live (TTL) settings
+ Point-in-time recovery settings

The time it takes you to restore a table varies based on multiple factors and isn't always correlated with the size of the table.

# Restoring a DynamoDB table to a point in time
<a name="PointInTimeRecovery.Tutorial"></a>

Amazon DynamoDB point-in-time recovery (PITR) provides continuous backups of your DynamoDB table data. You can restore a table to a point in time using the DynamoDB console or the Amazon Command Line Interface (Amazon CLI). The point-in-time recovery process restores to a new table.

If you want to use the Amazon CLI, you must configure it first. For more information, see [Accessing DynamoDB](AccessingDynamoDB.md).

**Topics**
+ [Restoring a DynamoDB table to a point in time (console)](#restoretabletopointintime_console)
+ [Restoring a table to a point in time (Amazon CLI)](#restorepointintime_cli)

## Restoring a DynamoDB table to a point in time (console)
<a name="restoretabletopointintime_console"></a>

The following example demonstrates how to use the DynamoDB console to restore an existing table named `Music` to a point in time.

**Note**  
This procedure assumes that you have enabled point-in-time recovery. To enable it for the `Music` table, on the **Backups** tab, in the **Point-in-time recovery (PITR)** section, choose **Edit** and then check the box next to **Enable point-in-time-recovery**.

**To restore a table to a point in time**

1. Sign in to the Amazon Web Services Management Console and open the DynamoDB console at [https://console.amazonaws.cn/dynamodb/](https://console.amazonaws.cn/dynamodb/).

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

1. In the list of tables, choose the `Music` table.

1. On the **Backups** tab of the `Music` table, in the **Point-in-time recovery (PITR)** section, choose **Restore**.

1. For the new table name, enter **MusicMinutesAgo**.
**Note**  
You can restore the table to the same Amazon Region or to a different Region from where the source table resides. You can also exclude secondary indexes from being created on the restored table. In addition, you can specify a different encryption mode.

1. To confirm the restorable time, set the restore date and time to **Earliest**. Then 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 `MusicMinutesAgo` table changes to **Active**.

## Restoring a table to a point in time (Amazon CLI)
<a name="restorepointintime_cli"></a>

The following procedure shows how to use the Amazon CLI to restore an existing table named `Music` to a point in time.

**Note**  
This procedure assumes that you have enabled point-in-time recovery. To enable it for the `Music` table, run the following command.  

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



**To restore a table to a point in time**

1. Confirm that point-in-time recovery is enabled for the `Music` table by using the `describe-continuous-backups` command.

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

   Continuous backups (automatically enabled on table creation) and point-in-time recovery are enabled.

   ```
   {
       "ContinuousBackupsDescription": {
           "PointInTimeRecoveryDescription": {
               "PointInTimeRecoveryStatus": "ENABLED", 
               "EarliestRestorableDateTime": 1519257118.0, 
               "LatestRestorableDateTime": 1520018653.01
           }, 
           "ContinuousBackupsStatus": "ENABLED"
       }
   }
   ```

1. Restore the table to a point in time. In this case, the `Music` table is restored to the `LatestRestorableDateTime` (\$15 minutes ago) to the same Amazon Region.

   ```
   aws dynamodb restore-table-to-point-in-time \
       --source-table-name Music \
       --target-table-name MusicMinutesAgo \
       --use-latest-restorable-time
   ```
**Note**  
 You can also restore to a specific point in time. To do this, run the command using the `--restore-date-time` argument, and specify a timestamp. You can specify any point in time within the configured recovery period, which can be set to any value between 1 and 35 days. For example, the following command restores the table to the `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
   ```
 Specifying the `--no-use-latest-restorable-time` argument is optional when restoring to a specific point in time.

1. Restore the table to a point in time with custom table settings. In this case, the `Music` table is restored to the `LatestRestorableDateTime` (\$15 minutes ago).

   You can specify a different encryption mode for the restored table, as follows.
**Note**  
The `sse-specification-override` parameter takes the same values as the `sse-specification-override` parameter used in the `CreateTable` command. To learn more, see [Managing encrypted tables in DynamoDB](encryption.tutorial.md).

   ```
   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
   ```

   You can restore the table to a different Amazon Region from where the source table resides.
**Note**  
The `sse-specification-override` parameter is mandatory for cross-Region restores but optional for restores to the same Region as the source table.
The `source-table-arn` parameter must be provided for cross-Region restores.
When performing a cross-Region restore from the command line, you must set the default Amazon Region to the desired destination Region. To learn more, see [Command line options](https://docs.amazonaws.cn/cli/latest/userguide/cli-configure-options.html) in the *Amazon Command Line Interface User Guide*.

   ```
   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
   ```

   You can override the billing mode and the provisioned throughput for the restored table.

   ```
   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
   ```

   You can exclude some or all secondary indexes from being created on the restored table.
**Note**  
Restores can be faster and more cost-efficient if you exclude some or all secondary indexes from being created on the new restored table.

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

   You can use a combination of different overrides. For example, you can use a single global secondary index and change provisioned throughput at the same time, as follows.

   ```
   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
   ```

To verify the restore, use the `describe-table` command to describe the `MusicEarliestRestorableDateTime` table.

```
aws dynamodb describe-table --table-name MusicEarliestRestorableDateTime
```

The table that is being restored is shown with the status **Creating** and restore in progress as **true**. After the restore process is finished, the status of the `MusicEarliestRestorableDateTime` table changes to **Active**.

**Important**  
While a restore is in progress, don't modify or delete the Amazon 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 remove write permissions for a table while that table is being restored. In this case, the underlying `RestoreTableToPointInTime` operation can't write any of the restored data to the table. IAM policies involving source IP restrictions for accessing the target restore table can similarly cause issues.  
You can modify or delete permissions only after the restore operation is completed.