Blob versioning is a feature that automatically creates a new version of a blob every time the blob is overwritten or deleted. This allows you to recover previous versions of a blob. This article describes how to enable and manage blob versioning.
How Blob Versioning Works
When blob versioning is enabled for a container, every write operation on a blob creates a new numbered version. The most recent version is the current active version. Older versions are retained and can be accessed directly using their version ID.
Enabling Blob Versioning
Blob versioning can be enabled at the storage account level. Once enabled, it applies to all containers in the account. You can enable versioning via the Azure portal, Azure CLI, or PowerShell.
Using Azure Portal
- Navigate to your storage account in the Azure portal.
- Under Data management, select Data protection.
- In the Versioning section, toggle Enable versioning for blobs to On.
- Click Save.
Using Azure CLI
az storage account update \
--name mystorageaccount \
--resource-group myresourcegroup \
--set properties.allowBlobPublicAccess=true \
--enable-versioning true
Using Azure PowerShell
Set-AzStorageAccount -ResourceGroupName "myresourcegroup" -AccountName "mystorageaccount" -EnableBlobVersioning $true
Managing Blob Versions
Once versioning is enabled, you can manage blob versions through various Azure tools.
Accessing Previous Versions
You can retrieve a specific version of a blob by providing its version ID in your request. The version ID is a GUID generated by Azure Storage.
Deleting Old Versions
To manage storage costs, it's recommended to implement a lifecycle management policy to automatically delete older blob versions that are no longer needed. You can define rules based on version age or number of versions.
Key Considerations
- Versioning incurs storage costs for each version of a blob.
- Versioning is enabled at the storage account level and cannot be disabled once enabled for a specific storage account.
- It is recommended to use lifecycle management policies in conjunction with versioning to control costs.