liveBook · Manning

EBS snapshot

As explained in Amazon Web Services in Action, Third Edition: An in-depth guide to AWS

An EBS snapshot is a point-in-time, block-level incremental backup of an EBS volume stored by Amazon EBS.

An EBS snapshot is a block-level, incremental backup of an EBS volume. The first snapshot saves the blocks in use; later snapshots save changes. For example, a 5 GiB volume containing 1 GiB of data produces a first snapshot of about 1 GiB. Snapshot storage is charged by the gigabytes used. section 8.1.4

Take snapshots regularly to prepare for volume failure or accidental data loss. To recover, create a new EBS volume from a snapshot; a snapshot does not itself replace an attached volume. section 8.1.4

A practical backup and restore sequence is:

  • Find the EBS volume ID, then create a snapshot with aws ec2 create-snapshot --volume-id $VolumeId. section 8.1.4
  • Check its progress with aws ec2 describe-snapshots --snapshot-ids $SnapshotId. Creation time depends on volume size and changed blocks. section 8.1.4
  • Restore with aws ec2 create-volume --snapshot-id $SnapshotId --availability-zone us-east-1a, choosing the availability zone for the new volume. section 8.1.4
$ aws ec2 create-snapshot --volume-id $VolumeId     #1
{
  "Description": "",
  "Encrypted": false,
  "OwnerId": "163732473262",
  "Progress": "",
  "SnapshotId": "snap-0babfe807decdb918",           #2
  "StartTime": "2022-08-25T07:59:50.717000+00:00",
  "State": "pending",                               #3
  "VolumeId": "vol-043a5516bc104d9c6",
  "VolumeSize": 5,
  "Tags": []
}

The creation response supplies the SnapshotId needed for status checks and restoration. Its initial State is pending. section 8.1.4

Avoid snapshotting an attached, mounted volume while writes remain unflushed: detach the volume or stop its instance first. If it must stay in use, freeze writes with sudo fsfreeze -f /data, start the snapshot, and unfreeze with sudo fsfreeze -u /data once its state is pending. You need not keep writes frozen until completion. section 8.1.4

An EBS volume is available in only one availability zone, while snapshots are stored on S3 and can support recovery by creating a volume in another zone. That makes snapshots useful for recovery, not a substitute for storage that remains available across zones. For a root volume, use an AMI for backup instead; for file storage shared across zones, consider EFS. section 13.2.3 section 16.0

How Amazon Web Services in Action, Third Edition: An in-depth guide to AWS covers it

How deep it goes
Defines incremental block-level backup and walks through CLI creation, status checks, consistency precautions, and volume restoration.
Examples
Uses a partly filled 5 GiB volume, AWS CLI snapshot and restore commands, and fsfreeze on a mounted filesystem.
What it assumes
Assumes access to an EBS volume and the AWS CLI; explains incremental backup before giving commands.
What you can do after
Operate/configure EBS snapshot backups with the AWS CLI and restore a new volume in a chosen availability zone.
How it connects
Links EBS volumes, EC2 instances, availability zones, S3, AMIs, and EFS through backup and recovery choices.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Amazon Web Services in Action, Third Edition: An in-depth guide to AWS. The section links point to the parts of the book it draws on.