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
- Backup and Restore: Create snapshots before making significant changes to a blob to ensure you can restore the previous state if needed.
- Data Retention Policies: Maintain historical versions of data for compliance or auditing purposes.
- Troubleshooting: Capture the state of a blob at a specific moment to diagnose issues.
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
- Navigate to your storage account in the Azure portal.
- Select "Containers" and then the container holding your blob.
- Find the blob you want to snapshot.
- Click the ellipsis (...) next to the blob name and select "Create snapshot".
- 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
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
--delete-snapshots all flag will permanently remove the blob and all its snapshots. Ensure you have backups if necessary.
Snapshot Properties
- Snapshots are read-only.
- Snapshots are billed for the space they occupy, just like regular blob data.
- Snapshots are associated with their base blob and share the same name.
- You can have multiple snapshots for a single blob, each representing a different point in time.
Snapshot Limitations
- Snapshots cannot be updated.
- Snapshots cannot be changed from read-only to read-write.
- You cannot create a snapshot of a snapshot.
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.