Time to 10x your DynamoDB productivity with Dynobase [learn more]
Backing up data is critical to ensuring that data is safe in the event of a disaster. However, as important as it is to backup data, it is also critical to ensure that restoring data is easy and efficient. Luckily AWS makes both of these actions incredibly easy for DynamoDB. In this post we will walk through two options AWS provides to backup and restore data from DynamoDB.
The first of which is on-demand backup and restore. This takes a snapshot of your DynamoDB table data at a specific point in time.
Additionally, AWS offers Point-in-Time Recovery. This allows you to restore your DynamoDB table data to a specific point in time without having to manage snapshots and restore points.
AWS also provides a service called AWS Backup that allows you to backup and restore data across many AWS services. One of which being DynamoDB. This option has some added benefits such as better control of cross-region backups, cross-account backups, scheduled backups, and more.
On-Demand Backup and Restore
As mentioned previously, On-Demand Backup and Restore is an option that allows you to take a snapshot of your DynamoDB table data and restore it at a later time. This means that if you create an On-Demand Backup, modify the table data, then a catastrophic disaster occurs, you can only restore data to the point of that On-Demand Backup and the modifications that took place after the fact will be lost.
You can create an On-Demand Backup snapshot by running the following command in the AWS CLI:
Of course, replacing
MYBACKUP with the name of your DynamoDB table and the name you want to give your backup respectively.
To restore a backup you can run the following command in the AWS CLI:
Few pointers when using this method:
- All restores must occur to a new table.
- There is no limit to the number of backups you can create.
- Backups are created asynchronously.
- Backup requests are processed instantly and become ready for restore within a few minutes.
- You can call the
CreateBackupcommand at a maximum rate of 50 requests per second.
- No provisioned throughput capacity is consumed when you create a backup.
- Backups are guaranteed to contain all data committed to the minute before the backup was requested. Backups will not contain any data committed a minute after the backup was requested. All data committed between those two times might be included.
- All data, indexes, streams, and provisioned read & write capacity will be included in the backup.
As of the time of writing this post, in the US East AWS Region the cost for this backup method is $0.10/GB/mo for your backups + $0.15/GB when restoring your data. As always, you should review the AWS pricing for your region on the AWS website as pricing can change at any time.
The next method is called Point-in-Time Recovery. The major benefit of this method is that you don't have to worry about taking backups/snapshots of your table. Simply enable Point-in-Time Recovery on your DynamoDB table, and AWS handles everything for you automatically. When restoring, you simply provide the timestamp of the state you want to restore to.
To enable Point-in-Time recovery on a DynamoDB table run the following command in the AWS CLI:
MYTABLE with your table name.
To restore a table to a specific point in time, run the following command in the AWS CLI:
Couple of things to keep in mind with this solution:
- All restores must be made to a new DynamoDB Table.
- You can restore to any point in time within the last 35 days.
- You can not restore prior to enabling Point-in-Time Recovery on your table.
- Any given account can perform up to 4 concurrent restores at any given time.
- Indexes, provisioned capacity, and encryption settings will be applied from the source table at time of the restore request, not at the time you are restoring to.
As of the time of writing this post, in the US East AWS Region the cost for this backup method is $0.20/GB/mo for your backups + $0.15/GB when restoring your data. As always, you should review the AWS pricing for your region on the AWS website as pricing can change at any time.
DynamoDB Cross-Region & Cross-Account Backup + Restore w/ AWS Backup
AWS Backup is an AWS service that lets you backup and restore many AWS resources. We are only going to scratch the surface of the functionality and capabilities of AWS Backup. There is luckily a lot of great documentation on how to take full advantage of AWS Backup.
To make a backup using AWS Backup:
- Navigate to the AWS Backup service in your AWS console.
- Click the
Create on-demand backupbutton.
- This will bring you to the wizard to create your backup. Select your settings, and click
Create on-demand backup.
Your backup will start.
After your backup is complete, you can copy it to other AWS accounts or regions or restore it.
First we will discuss how to copy it to another region or account.
- Select your backup.
- This will bring you to the wizard to copy your backup.
- Once you choose a region you have the option to copy to another account.
Your backup will start copying.
Now let's discuss how to restore it.
- Select your backup.
- Enter a new table name for your restored table.
- Choose roles and encryption keys.
Your backup will now start to be restored.
Backup Using Dynobase
Finally, one of the features included in Dynobase is the ability to easily export/import your data. Although this isn't integrated directly into the AWS platform, it has a few key benefits. One of which is being able to backup directly to S3, which in some cases can lead to drastic savings compared to the AWS provided solutions. Another is the ability to export directly to a JSON file, which can then be stored on any platform (even outside of AWS). This gives you additional security in not having to rely on the AWS platform exclusively.
It's also extremely easy to backup your data using Dynobase.
- Open your table in Dynobase.
- Click the
Exportbutton in the bottom right corner.
Current Results, or
Whole Table. This is an added benefit over the AWS solutions because you can choose which data you want to export. With AWS, backups are all or nothing. Dynobase gives you more flexibility in this regard. Although there might be reasons you want to export a subset of your data, it's probably recommended to consider
- Choose between exporting to a file or exporting to S3 directly.
It's just as easy to import your data into the table.
- Open the table you want to import data into in Dynobase.
- Click the
Importbutton in the bottom right corner.
- Browse your local file system to find the JSON file you wish to import. You can also import CSV files as well.
- Choose a merging strategy if the data you are importing already exists in the table. Also, choose a write concurrency value.
Another benefit to this method is the ability to restore/import your data into an existing DynamoDB table, which is not possible with the AWS-provided methods.
Everyone should be backing up their data. Data loss can lead to catastrophic situations for companies and projects. It is critical you have a solid backup strategy in place. With these methods, you can easily deploy a simple backup strategy using the power of AWS.
Frequently Asked Questions
Where are DynamoDB backups stored?
DynamoDB backups are stored within the AWS region that your table is located within. Since it is a fully managed feature from AWS, all of the complexity of storage is handled for you behind the scenes.
Is it possible to restore a deleted table in DynamoDB?
All of the options explained in this guide allow for restoring a deleted table, with the exception of Point-in-Time Recovery.
Are DynamoDB backups encrypted?
Due to DynamoDB backups being a fully managed service from AWS, all backups are automatically encrypted. Additionally, this means that although the backups are encrypted, this is transparent to you, so you don't have to worry about this process and the decryption side of things.