Amazon Elastic Block Store (or EBS for short) is a service for providing block storage to your EC2 instances. In other words, it provides reliable volumes (hard drives) to your cloud servers.
One very useful function of Amazon EBS is creating EBS snapshots of your EBS volumes. EBS snapshots are backups of your EBS volumes. But how do they work, and how can you use them? Let’s take a look.
An EBS snapshot is a point-in-time backup of your EBS volume. It is a “copy” of the data on your EBS volume.
If you are looking for a disaster-recovery solution for your EBS volume, this is the solution.
If you want to “backup” your EC2 instance, then you want to create EBS snapshots of the EBS volumes attached to the instance.
An EBS snapshot is actually both a full backup and an incremental backup.
When an EBS snapshot is created, only the data on the EBS volume that has changed since the last EBS snapshot is stored in the new EBS snapshot. In this way, it’s an incremental backup.
Internally, the EBS snapshots chain together.
When an EBS snapshot is used to restore data, all data from that EBS snapshot can be restored as well as the data from the previous snapshots. In this way, the snapshot is a full backup.
Yes. You can safely delete old EBS snapshots. New EBS snapshots will continue to restore properly.
Source: Deleting an Amazon EBS Snapshot
When you delete an old EBS snapshot, behind the scenes, AWS will consolidate the snapshot data. It will move valid data forward to the next EBS snapshot and it will discard invalid data.
EBS snapshots are block-level backups of your EBS volumes. This means that EBS volumes and EBS snapshots don’t care what software/filesystems/partitions/etc. are being used on the volume. AWS will simply look at each device block, determine if there’s data on it, and include it in the snapshot if there’s data.
When you create an EBS snapshot, any data written to the volume up to the time that the snapshot was started, will be included. This means that you can safely write to your EBS volume after the snapshot has started without affecting the EBS snapshot. Even if the snapshot is in a “pending” state, it is still safe to write to the EBS volume.
Source: Creating an Amazon EBS Snapshot
As your application and databases write data to the local filesystem, they are communicating with your operating system (Linux or Windows). However, for performance reasons, the operating system will decide when to write that data to the actual EBS volume. So it’s possible that data has left your application, but has not arrived at the EBS volume yet.
To handle this, you should flush your filesystem before creating a snapshot. This pushes all cached data out to the EBS volume. How this is done depends on your operating system and file system.
You should also “Lock” your filesystem. This prevents applications and databases from writing more data to your volumes. Again, how your filesystem is locked depends on the operating system and file system.
To safely handle flushing and locking, AWS recommends either:
Source: Creating an Amazon EBS Snapshot
However, in production systems, this isn’t always possible. So when in doubt, create the EBS snapshots anyways. A snapshot that may have missing data is better than not having a snapshot at all.
EBS snapshots are stored in Amazon S3. However, you are not going to find your snapshots in any of your S3 buckets.
AWS uses the S3 infrastructure to store your EBS snapshots, but you cannot access them while they reside in S3.
As mentioned earlier, EBS snapshots are block-level snapshots. This means that it has no knowledge of the file system being used. So it is not possible to access individual files in your EBS snapshot.
To restore data, you must create a fresh EBS volume from your EBS snapshot. That new EBS volume will contain all the data stored in the EBS snapshot. It will be an exact duplicate of the original EBS volume, at the time the EBS snapshot was started.
More information: Restoring an Amazon EBS Volume from a Snapshot
Once you have your new EBS volume, you can:
If your EBS snapshot was from a root EBS volume, then you can:
When you create the EBS volume, the data is copyed from the EBS snapshot to the volume.
So once your EBS volume is ready, you can safely delete the EBS snapshot.
Plan ahead. Backup early and backup often.
EBS snapshots are invaluable when disaster happens.
A few years ago we wrote up some information on EBS snapshots. Some content from this article overlaps that article, but there’s still some good information there.
Skeddly is the leading scheduling service for your AWS account. Using Skeddly, you can: