Enable and manage blob versioning

Microsoft Docs

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.

Note: Blob versioning is different from blob snapshots. Snapshots are point-in-time read-only copies of a blob, while versions are automatically created by overwrite or delete operations.

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

  1. Navigate to your storage account in the Azure portal.
  2. Under Data management, select Data protection.
  3. In the Versioning section, toggle Enable versioning for blobs to On.
  4. 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.

Tip: Use Azure Blob Storage lifecycle management policies to automate the deletion of older blob versions and optimize costs.

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.

Further Reading