dynobase-icon
Dynobase

DynamoDB Backup & Restore - Step-by-Step Guide

Charlie Fish

Written by Charlie Fish

Published on April 11th, 2022

    Still using AWS console to work with DynamoDB? 🙈

    Time to 10x your DynamoDB productivity with Dynobase [learn more]

    Introduction

    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, including 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 MYTABLE & MYBACKUP with the name of your DynamoDB table and the name you want to give your backup respectively.

    As with almost all AWS commands, you can also call this method through the AWS SDK. In JavaScript this would look something like:

    To restore a backup you can run the following command in the AWS CLI:

    The same code in the AWS SDK in JavaScript would look like:

    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 CreateBackup command 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.

    Point-in-Time Recovery

    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:

    Replacing MYTABLE with your table name.

    The same code in the AWS SDK in JavaScript would look something like:

    To restore a table to a specific point in time, run the following command in the AWS CLI:

    The same code in the AWS SDK in JavaScript would look like:

    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 cannot 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 the 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:

    1. Navigate to the AWS Backup service in your AWS console.
    2. Click the Create on-demand backup button.

    AWS Backup On Demand Backup Button

    1. This will bring you to the wizard to create your backup. Select your settings, and click Create on-demand backup.

    AWS Backup On Demand Backup Wizard

    Your backup will start.

    After your backup is complete, you can copy it to other AWS accounts or regions or restore it.

    AWS Backup Action Buttons (Copy, Delete, Restore)

    First, we will discuss how to copy it to another region or account.

    1. Select your backup.
    2. Click Copy.
    3. This will bring you to the wizard to copy your backup.

    AWS Backup Copy Wizard

    1. Once you choose a region you have the option to copy to another account.

    AWS Backup Copy Cross Account Option

    1. Click Copy.

    Your backup will start copying.

    Now let's discuss how to restore it.

    1. Select your backup.
    2. Click Restore.
    3. Enter a new table name for your restored table.
    4. Choose roles and encryption keys.
    5. Click Restore backup.

    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.

    1. Open your table in Dynobase.
    2. Click the Export button in the bottom right corner.
    3. Select Selection, 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 Whole Table first.
    4. Choose between exporting to a file or exporting to S3 directly.
    5. Click Export Table.

    That's it!

    It's just as easy to import your data into the table.

    1. Open the table you want to import data into in Dynobase.
    2. Click the Import button in the bottom right corner.
    3. Browse your local file system to find the JSON file you wish to import. You can also import CSV files as well.
    4. Choose a merging strategy if the data you are importing already exists in the table. Also, choose a write concurrency value.
    5. Click Import Records.

    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.

    Conclusion

    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.

    Additional Considerations

    When planning your backup strategy, it's important to consider the Recovery Time Objective (RTO) and Recovery Point Objective (RPO) for your application. RTO is the maximum acceptable amount of time to restore the service after a failure, while RPO is the maximum acceptable amount of data loss measured in time. AWS Backup and Point-in-Time Recovery can help you meet these objectives, but understanding your specific requirements will guide you in choosing the right solution. Additionally, regularly testing your backup and restore process is crucial to ensure that you can meet your RTO and RPO targets. This includes verifying the integrity of your backups and ensuring that your team is familiar with the restore procedures.

    Tired of switching accounts and regions? Use Dynobase.

    First 7 days are. No credit card needed.

    Product Features

    Download
    /
    Changelog
    /
    Pricing
    /
    Member Portal
    /
    Privacy
    /
    EULA
    /
    Twitter
    /
    Affiliates & Influencers
    © 2024 Dynobase