Automating EBS Snapshots for Disaster Recovery: Everything You Need to Know
6 min read
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. EBS volumes are priced at $0.10 per GB-month in the us-east-1 region, and there are multiple volume types, each with its own pricing and use cases. If you want to learn more about EBS, check out this issue of Simple AWS with tips and best practices for EBS.
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 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.
Two 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).
Automating EBS Snapshots 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.
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 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.
Understanding the Cost 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.50.
Alternatives to EBS Snapshots
If you're using EBS but only need to back up a part of the data, you can set up two EBS volumes: one for the OS and one for data that needs to be backed up. You can then use automated EBS snapshots for the second volume.
Alternatively, you can set up a script that copies data to an S3 bucket that has Cross-Region Replication (XRR) enabled. While this is easier to set up than automated EBS snapshots, it can be harder to maintain in the long run.
In conclusion, AWS EBS snapshots are an efficient and cost-effective way to back up your data on Amazon Web Services. By capturing point-in-time copies of your EBS volumes, you can quickly restore your data in case of loss or corruption. With two categories of EBS snapshots, Standard and Archive, you can choose the right one for your use case. And with automation tools like AWS DLM, you can simplify snapshot creation and management. So don't wait until it's too late – start using EBS snapshots today and protect your valuable data on AWS.
Thanks for reading!
Cloud solutions are often much more complicated than they need to be. The Simple AWS newsletter is about removing that complexity. Join hundreds of software experts learning how to solve complex problems in AWS with simple solutions, and how to scale and secure them with best practices.
Every issue starts with a real scenario, presents the simplest solution possible, and discusses best practices, always considering the context and tradeoffs.
If you'd like to know more about me, you can find me at www.guilleojeda.com