How do I calculate the Amazon EBS snapshot size?

4 minute read
0

I created an Amazon Elastic Block Store (Amazon EBS) snapshot of my Amazon EBS volume and want to find the size of data backed up by the snapshot.

Short description

Amazon EBS snapshots create point-in-time copies to provide backup of your Amazon EBS volumes. Amazon EBS snapshots are incremental and consist of only blocks that have changed since the most recent snapshot. The first snapshot is a full snapshot that contains the updated blocks and new blocks written at the time of snapshot creation. The data backed up determines the size of an Amazon EBS snapshot and the cost associated with a snapshot. The size of the source Amazon EBS volume doesn't determine the size and cost.

Resolution

Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshoot AWS CLI errors. Also, make sure that you're using the most recent AWS CLI version.

Use Amazon EBS direct APIs to create snapshots, read data on snapshots, write data to snapshots, and find the difference between two snapshots. Amazon EBS direct APIs are charged per request. For more information, see Amazon EBS pricing website.

Find the size of full snapshots

To show the index and token of blocks in a snapshot, use the API ListSnapshotBlocks. This API returns up to 10,000 blocks in a single call along with the token to be used for subsequent calls. Each block is 512 KiB. The BlockIndex of the last block returned by ListSnapshotBlocks shows the number of blocks in the snapshot. The number of blocks multiplied by 512 KiB is an approximation of your full snapshot size.

To find the size of the EBS snapshot, run the following AWS CLI list-snapshot-blocks command:

aws ebs list-snapshot-blocks --snapshot-id <snapshot id> --region <region>

This command shows all of the data blocks in the snapshot with their block indices and block tokens. Note that the API doesn't directly give you the total number of blocks. The API returns the first 10,000 blocks in the snapshot. If the snapshot has more than 10,000 blocks, then the output includes a NextToken.

The following NextToken command can be used in the subsequent commands:

aws ebs list-snapshot-blocks --snapshot-id <snapshot id> --next-token <value> --region <region>

Repeat this command until the NextToken is no longer in the output. This means that the API has completed the list of all the blocks in the snapshot.

Size of EBS full snapshot in KiB = BlockIndex of the last block returned * 512 KiB

Find the size of incremental snapshots

Subsequent Amazon EBS snapshots contain only the blocks that are changed from the previous snapshot and references to the blocks in the previous snapshot. The number of changed blocks in an incremental snapshot gives its size. To determine the unique blocks in an incremental snapshot or the blocks changed between the current and previous snapshots, use Amazon EBS direct API ListChangedBlocks.

To find the size of an incremental EBS snapshot, run the following AWS CLI list-changed-blocks command.

aws ebs list-changed-blocks --first-snapshot-id <first snapshot id> --second-snapshot-id <second snapshot id> --region <region>

This command shows all the data blocks that have changed between the two snapshots with their block indices and block tokens. Count the number of blocks returned. Note that the API doesn't directly give you the total number of blocks. You have to count the number of blocks returned based on either the block tokens or block indices. The API returns the first 10,000 blocks in the snapshot. If the snapshot has more than 10,000 blocks, then the output includes a NextToken.

The following NextToken command can be used in the subsequent commands:

aws ebs list-changed-blocks --first-snapshot-id <first snapshot id> --second-snapshot-id <second snapshot id> --next-token <value> --region <region>

Repeat this command until the NextToken is no longer in the output. This means that the API completed the list of all the changed blocks in the snapshot.

To calculate the size of data, multiply the total number of blocks changed by 512.

Size of EBS incremental snapshot in KiB = Total number of blocks changed in the snapshot * 512 KiB

Support tool

To manage your Amazon EBS, use the Flexible Snapshot Proxy Python tool. For more information, see Flexible Snapshot Proxy on the AWS GitHub website.

Related information

Amazon EBS snapshots

EBS client

AWS OFFICIAL
AWS OFFICIALUpdated 12 days ago