Automating EBS Snapshots for Disaster Recovery
Tags: aws, devops, cloud, tutorial
Published: 2022-12-16 23:15:49

If you use Amazon Web Services (AWS), you are likely familiar with EBS, Elastic Block Store. It is a block-level storage service for EC2 instances, which means it is a persistent storage device that you can attach to your EC2 instances and use like a physical hard drive. If you want to learn more about EBS, check out [**Amazon EBS Basics and Best Practices**](https://newsletter.simpleaws.dev/p/ebs-basics-best-practices?utm_source=blog&utm_medium=dev.to).

In this article, we will focus on EBS snapshots, which are point-in-time copies of your EBS volumes that you can use to back up your data.

## **What are AWS EBS Snapshots**

As mentioned, EBS snapshots are point-in-time copies of your EBS volumes that you can use to back up your data. By creating a backup (an EBS snapshot) of your disk (the EBS volume), you can restore a new EBS volume from that snapshot.

EBS snapshots are incremental, which means they only capture the data that has changed since the last snapshot. For example, if you have a 100 GB volume and you take a snapshot, then make a small change to the volume and take another snapshot, the second snapshot will only contain the data that has changed since the first snapshot. This makes EBS snapshots more efficient and cost-effective than full-volume backups. The size of an EBS snapshot is calculated based on the amount of data stored in the volume at the time the snapshot was taken.

## **Categories of EBS Snapshots**

There are two categories of EBS snapshots: Standard snapshots and Archive snapshots. Standard snapshots are stored in Amazon S3 and are designed for fast recovery of data. They are the default type of snapshot and are suitable for most use cases. Archive snapshots, on the other hand, are stored in Amazon S3 Glacier and are designed for long-term data retention. They are more cost-effective than Standard snapshots, but have retrieval times of a few hours (because they are retrieved from Glacier instead of S3).

## **Using EBS Snapshots for Disaster Recovery**

EBS snapshots are regional, which means they can only be used in the region where they were created. If you need to use an EBS snapshot in another region (e.g., for disaster recovery), you will need to export it. However, it is important to export the snapshot *before* the region becomes unavailable. You can automate EBS snapshot creation and copying to another region using various tools like AWS CLI command, AWS Systems Manager Automation, or Data Lifecycle Manager (DLM).
    

---

Master AWS with Real Solutions and Best Practices. Subscribe to the free newsletter [**Simple AWS**](https://www.simpleaws.dev?utm_source=blog&utm_medium=dev.to). 3000 engineers and tech experts already have.

<iframe src="https://embeds.beehiiv.com/1c90a8a9-57b7-4a3f-ac56-5f05d0121f72?slim=true" style="margin:0;border-radius:0px;background-color:transparent;display:block;margin-left:auto;margin-right:auto" height="55px"></iframe>

---


## **Automating EBS Snapshots in AWS with Amazon DLM**

You can automate the creation and management of EBS snapshots using AWS Data Lifecycle Manager (DLM). With DLM, you can create snapshot policies that specify the schedule, retention, and other settings for snapshot creation.

Amazon DLM allows you to create snapshot policies that specify the schedule, retention, and other settings for snapshot creation. You can create snapshot policies using tags to identify the volumes to include in the snapshot policy. For example, you can create a snapshot policy that applies to all EBS volumes with the tag key "Snapshot" and value "true."

In addition to taking snapshots of EBS volumes, DLM also allows you to enable cross-region copy, which copies the snapshots to another region. This can be useful for disaster recovery or to create a backup of your data in a different location. To enable cross-region copy, you need to specify the destination region and the KMS key to use for encryption in the snapshot policy. Once enabled, DLM will automatically copy the snapshots to the specified region on the specified schedule.

Here's a sample CloudFormation template to automate EBS snapshot creation and copying to another region using DLM. As always, be careful with what you deploy from the internet.

```yaml
---
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
  KmsKeyArn:
    Type: String
    Description: The ARN of the KMS key to use for encrypting cross-Region snapshot copies
  DestinationRegion:
    Type: String
    Description: The destination region to copy the snapshots to
Resources:
  SnapshotPolicy:
    Type: AWS::DLM::LifecyclePolicy
    Properties:
      Description: EBS snapshot policy with cross-Region copy
      PolicyDetails:
        ResourceTypes:
          - VOLUME
        TargetTags:
          -
            Key: Snapshot
            Value: true
        Schedules:
          - Name: DailySnapshot
            CopyTags: true
            CreateRule:
              Interval: 1
              IntervalUnit: DAYS
            RetainRule:
              Count: 7
        Parameters:
          ExcludeBootVolume: true
          RestorablePeriod: 0
          CrossRegionCopy:
            DestinationRegion: !Ref DestinationRegion
            Encrypted: true
            KmsKeyArn: !Ref KmsKeyArn
```

## How to Restore from an EBS Snapshot

You can create a new EBS volume from the snapshot and attach it to an EC2 instance like a regular EBS volume. The process is straightforward for Standard snapshots, and the volume is ready for use as soon as it's created. However, for Archive snapshots, you need to retrieve the snapshot from Amazon S3 Glacier and then create the volume from the snapshot, which can take several hours, depending on the size of the snapshot and the retrieval tier you choose.

The pricing for restoring an Archive EBS snapshot is based on the size of the snapshot. In the us-east-1 region, Archive snapshot restores are priced at $0.03 per GB of data retrieved. For example, if you need to restore a 200 GB Archive snapshot, the cost would be 200 \* $0.03 = $6.

## **Cost Analysis of EBS Snapshots**

EBS snapshots are priced per GB-month of data stored, and there are two types of EBS snapshots available: Standard and Archive. In the us-east-1 region, Standard snapshots are priced at $0.05 per GB-month, while Archive snapshots are priced at $0.0125 per GB-month. This means that Archive snapshots are a lot cheaper than Standard snapshots. However, keep in mind that Archive snapshots have long retrieval times.

For example, a 200 GB Standard snapshot that's stored for 30 days would cost 200 \* $0.05 *\** 30 = $30. Storing a 200 GB Archive snapshot for 30 days would cost 200 \* $0.0125 \* 30 = $7.

## **Comparing EBS Snapshots with Amazon S3 Glacier**

Amazon S3 Glacier is another AWS storage service designed for long-term, low-cost storage. It is used for data archiving and long-term backups, but unlike EBS snapshots, it is not tied to EBS volumes. If you need to store large amounts of data for long periods, you might consider using Amazon S3 Glacier instead of EBS snapshots.

Amazon S3 Glacier stores data in archives, which are organized into vaults. You can upload data to a vault and then download it later when you need it. The retrieval time for Amazon S3 Glacier is several hours, similar to Archive EBS snapshots, but the cost is typically lower. In the us-east-1 region, Amazon S3 Glacier storage costs $0.004 per GB-month, compared to $0.0125 per GB-month for Archive EBS snapshots.

However, EBS snapshots offer several advantages over Amazon S3 Glacier, such as the ability to restore EBS volumes directly from the snapshot and the incremental backup feature. If your primary use case is to back up EBS volumes, EBS snapshots are generally more convenient and easier to manage.

## **Best Practices for Automating EBS Snapshots**

Here are some best practices to help you optimize your EBS snapshot strategy:

1. **Schedule regular snapshots**: To minimize data loss, create a schedule for taking snapshots regularly, such as daily or weekly. This will help ensure that you always have a recent backup of your data.
    
2. **Use tags to identify important volumes**: Use tags to mark EBS volumes that should be included in snapshot policies. This makes it easy to manage snapshots for multiple volumes.
    
3. **Enable cross-region copy for disaster recovery**: To protect your data in case of a regional outage, enable cross-region copy for your EBS snapshots. This will automatically copy your snapshots to another region, ensuring that you have a backup available even if your primary region becomes unavailable.
    
4. **Delete old snapshots**: To save on storage costs, regularly delete old snapshots that are no longer needed. You can use Amazon DLM to automatically retain a certain number of snapshots and delete the rest.
    
5. **Monitor snapshot usage and costs**: Keep an eye on your snapshot usage and costs to ensure that you're not spending more than necessary. You can use Amazon CloudWatch and AWS Budgets to monitor your EBS snapshot usage and set up alerts if your costs exceed a certain threshold.
    

In conclusion, EBS snapshots are a powerful tool for backing up your data on AWS. By understanding the different types of snapshots, automating their creation and management, and following best practices, you can effectively protect your data and ensure a robust disaster recovery plan.

---

Master AWS with Real Solutions and Best Practices.  
Join over 3000 devs, tech leads, and experts learning real AWS solutions with the [Simple AWS newsletter](https://www.simpleaws.dev?utm_source=blog&utm_medium=dev.to).

* Analyze real-world scenarios
    
* Learn the why behind every solution
    
* Get best practices to scale and secure them
    

Simple AWS is **free**. [Start mastering AWS!](https://www.simpleaws.dev?utm_source=blog&utm_medium=dev.to)

<iframe src="https://embeds.beehiiv.com/1c90a8a9-57b7-4a3f-ac56-5f05d0121f72?slim=true" style="margin:0;border-radius:0px;background-color:transparent;display:block;margin-left:auto;margin-right:auto" height="55px"></iframe>

If you'd like to know more about me, you can find me [on LinkedIn](https://www.linkedin.com/in/guilleojeda/) or at [www.guilleojeda.com](https://www.guilleojeda.com?utm_source=blog&utm_medium=dev.to)

<script type="text/javascript" async src="https://embeds.beehiiv.com/attribution.js"></script>