EBS Snapshots and Backup
Explore Amazon Elastic Block Store (EBS) snapshots and their role in backup, disaster recovery, and resilience by learning to create, manage, and restore snapshots using the AWS Console, CLI, and SDKs.
We'll cover the following...
An Amazon EBS snapshot is a point-in-time backup of the data stored on an EBS volume. It captures the volume’s state at the moment the snapshot is initiated and is stored in Amazon S3, which is managed transparently by AWS. Snapshots are the foundational mechanism for backing up block storage on EC2 instances and are commonly used for compliance, testing, migration, and recovery.
How EBS snapshots work
EBS snapshots are a low-level backup mechanism that creates a point-in-time copy of the data stored on an EBS volume. These snapshots are incremental and highly optimized for performance and cost-efficiency, which is why they are the preferred method for data protection at the block level.
When we take our first snapshot, it is a complete copy of all the data blocks on the volume. However, every subsequent snapshot only captures blocks that have changed since the previous snapshot. This block-level change tracking ensures efficient storage usage, reducing both time and cost.
Note: To restore a volume, we can use any snapshot independently, as AWS automatically assembles the full volume view using the chain of snapshots.
Snapshots can be taken from volumes that are in use, such as those attached to running EC2 instances. In these cases, AWS uses I/O quiescing mechanisms to flush pending writes and ensure snapshot consistency. On Linux systems, fsfreeze
can be used to pause file system activity. On Windows, AWS supports the
Best practice: Use
aws ec2 create-snapshot --volume-id <vol-id> --description "Backup"
alongside I/O quiescing tools to ensure a consistent backup of running applications, especially databases.
Creating snapshots
EBS snapshots can be created manually whenever a consistent backup of an Amazon EBS volume is needed. This is especially useful before performing system updates, configuration changes, or deploying new application versions.
We can create a snapshot using the following AWS CLI command. The AWS CLI provides a scriptable and repeatable way to create snapshots. It is especially valuable in automation workflows:
aws ec2 create-snapshot \--volume-id <Volume_ID> \--description "Manual backup before update" \--tag-specifications 'ResourceType=snapshot,Tags=[{Key=Name,Value=SampleSnapshot}]'
We can also use AWS SDKs to create snapshots. The following code snippet uses Python and boto3
to create a snapshot of the EBS volume and ...