Follow dba-ninja.com

Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions

dba-ninja.com Links

Dba_db2_button

Sqlserver_dba_button

Amazon DynamoDB Backup & Restore

15 December,2022 by Rambler

AWS DynamoDB supports On-Demand backups and Point-In-Time-Recovery (PITR) backups.    There is also SYSTEM backups for DynamoDB - for example - these are created when a DynamoDB table is deleted. 

There are two options available for creating and managing DynamoDB on-demand backups:    AWS Backup service & DynamoDB. 

 

Option 1 : Using the DynamoDB  method for a DynamoDB snapshot backup. Using the dynamoDB api 

--create backup to DynamoDB API

aws dynamodb create-backup --table-name <REPLACE_WITH_DYNAMODB_TBL> --backup-name  <REPLACE_WITH_DYNAMODB_TBL_BACKUP_NAME> 

 

Option 2 : Using the AWS Backup method for a snapshot , using the the backup api

aws backup start-backup-job --backup-vault-name <REPLACE_BACKUP_VAULT_NAME> --resource-arn <REPLACE_WITH_DYNAMO_TABLE_ARN> --iam-role-arn <REPLACE_WITH_IAM_ROLE_ARN> --region <REPLACE_WITH_REGION_NAME>

 

 

Notes on DynamoDB backups

1) When PITR is enabled , DynamoDB maintains continuous backups and can restore to any point in time between the EarliestRestorableDateTime and LatestRestorableDateTime

2) PITR needs to be enabled on a DynamoDB table by table basis 

 

How to check the PITR status 

Example 1 : PITR status is enabled

aws dynamodb describe-continuous-backups --table-name abc1

{
    "ContinuousBackupsDescription": {
        "ContinuousBackupsStatus": "ENABLED",
        "PointInTimeRecoveryDescription": {
            "PointInTimeRecoveryStatus": "ENABLED",
            "EarliestRestorableDateTime": "2022-11-02T13:36:19.311000+00:00",
            "LatestRestorableDateTime": "2022-12-07T13:31:19.311000+00:00"
        }
    }
}

Example 2: PITR is disabled

aws dynamodb describe-continuous-backups --table-name abc2


{
    "ContinuousBackupsDescription": {
        "ContinuousBackupsStatus": "ENABLED",
        "PointInTimeRecoveryDescription": {
            "PointInTimeRecoveryStatus": "DISABLED"
        }
    }
}



How to enable PITR on a DynamoDB table

aws dynamodb update-continuous-backups --table-name MyDynamoDBtable --point-in-time-recovery-specification PointInTimeRecoveryEnabled=true

 

How to Restore a DynamoDB to point-in-time  table using AWS CLI

Note: PITR recovery restores to a new table

OPTION 1 : Restore to the latest Restorable times 

aws dynamodb restore-table-to-point-in-time --source-table-name MyDynamoDBtable --target-table-name MyDynamoDBtable-restore  --use-latest-restorable-time

OPTION 2 : Restore to a specific point in time 

Note: To get a specific restore-date-time 

aws dynamodb restore-table-to-point-in-time --source-table-name <replace_with_source_tbl_> --target-table-name <replace_with_target_tbl> --no-use-latest-restorable-time --restore-date-time <replace_with_restore_date_time>

 

How to Restore a DynamoDB when the backup is generated by the SYSTEM . For example , when the backup is created automatically when a DynamoDB table is deleted.

Step 1 : Check for the existence of a SYSTEM DynamoDB table 

aws dynamodb list-backups --table-name <replace_with_the_DynamoDB table>  --backup-type SYSTEM --output table

Step 2 : Use the BackupARN value to restore the database

aws dynamodb restore-table-from-backup --target-table-name <replace_with_table_name> --backup-arn <replace_with_backup_arn>

 

 

 

Along with data, the following settings are also restored to the new DynamoDB table:

Global secondary indexes (GSIs)
Local secondary indexes (LSIs)
Provisioned read and write capacity
Encryption settings


There are a few settings that will need to be manually set up on the restored table and are not copied over:

Auto scaling policies
AWS Identity and Access Management (IAM) policies
AWS CloudWatch metrics and alarms
Tags
Stream settings
Time-to-Live (TTL) settings
Point-in-time recovery settings

 

 

 

 

 

 

How to Restore A DynamoDB Table - assuming the AWS Backup plan is used

--get the DynamoDB table Resource ARN

aws dynamodb describe-table --table-name <replace_with_DynamoDB_table_name> --query Table.TableArn

--get the backup resource ARN .This query will return  1 or more backup recovery points - with date and Recovery PointARN. Select the RecoveryPointARN as required

aws backup list-backup-jobs --by-state COMPLETED --query "BackupJobs[?ResourceArn == '<replace_with_DynamoDB_Resource_ARN>'].[CompletionDate,RecoveryPointArn]"

-- execute the restore command

aws dynamodb restore-table-from-backup --target-table-name  <REPLACE_WITH_TARGET_TBL> --backup-arn  <REPLACE_WITH_BACKUP_RESOURCE_ARN>

 

 

 


Author: Rambler (http://www.dba-ninja.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on Amazon DynamoDB Backup & Restore


dba-ninja.com