Azure Storage Blobs

Storage Blob Snapshots

Blob snapshots provide a point-in-time read-only copy of a blob. Snapshots are useful for backing up blob data, retaining blob versions for compliance, or troubleshooting. You can create a snapshot of a blob at any time. Once a snapshot is created, it cannot be modified, deleted, or overwritten. The snapshot persists until it is explicitly deleted.

When to Use Blob Snapshots

Creating a Blob Snapshot

You can create a snapshot of a blob using the Azure portal, Azure CLI, PowerShell, or any Azure Storage SDK.

Using Azure CLI

To create a snapshot of a blob using Azure CLI, use the az storage blob snapshot command:

az storage blob snapshot --account-name mystorageaccount --container-name mycontainer --name myblob.txt --snapshot 2023-10-27T10:00:00Z --auth-mode login

Replace mystorageaccount, mycontainer, and myblob.txt with your storage account name, container name, and blob name, respectively. The --snapshot parameter specifies the date-time of the snapshot. If omitted, the current time is used.

Using Azure Portal

  1. Navigate to your storage account in the Azure portal.
  2. Select "Containers" and then the container holding your blob.
  3. Find the blob you want to snapshot.
  4. Click the ellipsis (...) next to the blob name and select "Create snapshot".
  5. Confirm the snapshot creation.

Accessing and Managing Snapshots

Snapshots are accessed via a special URI that includes the snapshot's timestamp.

Snapshot URI

The URI for a blob snapshot has the following format:

<blob-uri>?snapshot=<date-time>

For example:

https://mystorageaccount.blob.core.windows.net/mycontainer/myblob.txt?snapshot=2023-10-27T10:00:00Z

Listing Snapshots

You can list snapshots for a blob or all blobs in a container. For example, to list snapshots of a specific blob using Azure CLI:

az storage blob show --account-name mystorageaccount --container-name mycontainer --name myblob.txt --query snapshots
💡 Note: Snapshots share the same ID as the base blob. When you query for a blob, you will get the latest version of the blob by default. To access a snapshot, you must explicitly use the snapshot URI.

Deleting Snapshots

Snapshots can only be deleted individually or when their associated base blob is deleted.

Deleting a Specific Snapshot

To delete a specific snapshot using Azure CLI:

az storage blob delete --account-name mystorageaccount --container-name mycontainer --name myblob.txt --snapshot 2023-10-27T10:00:00Z --auth-mode login

Deleting a Blob and All its Snapshots

Deleting the base blob also deletes all of its associated snapshots.

az storage blob delete --account-name mystorageaccount --container-name mycontainer --name myblob.txt --delete-snapshots all --auth-mode login
Important: Deleting a blob with the --delete-snapshots all flag will permanently remove the blob and all its snapshots. Ensure you have backups if necessary.

Snapshot Properties

Snapshot Limitations

Blob Type Snapshots

Snapshots can be created for page blobs, block blobs, and append blobs. The behavior and management of snapshots may slightly differ based on the blob type.

  • Block Blobs: The most common type for snapshots. A snapshot captures the entire state of the block blob at the time of creation.
  • Page Blobs: Snapshots capture the state of the page blob. You can use snapshots for page blobs to restore them to a previous state.
  • Append Blobs: Snapshots are supported. A snapshot captures the contents of the append blob at the time the snapshot was taken.

Lease Considerations

A lease on a blob does not affect its snapshots. If a blob has an active lease, you can still create snapshots of it. However, a lease on a blob does not apply to its snapshots. Snapshots themselves cannot be leased.

When you delete a blob that has an active lease, the lease must be broken or expired before the blob and its snapshots can be deleted.

Cost and Billing

Blob snapshots are billed based on the amount of data they store. You are charged for the storage consumed by each snapshot. If a snapshot contains data that is different from the current version of the blob, you are charged for that unique data. If a snapshot shares data with the current blob version, only the unique data is charged.

Deleting a blob and its snapshots will stop all associated storage charges for that data.

💡 Tip: Regularly review your storage account and delete old or unnecessary snapshots to manage costs effectively.