You can enable Blob storage versioning to automatically maintain previous versions of a blob when it is modified or deleted. When blob versioning is enabled, then you can restore an earlier version of a blob to recover your data if it is erroneously modified or deleted.
This article shows how to enable or disable blob versioning for the storage account by using the Azure portal or an Azure Resource Manager template. To learn more about blob versioning, see Blob versioning.
Enable blob versioning
You can enable blob versioning with the Azure portal, PowerShell, Azure CLI, or an Azure Resource Manager template.
To enable blob versioning for a storage account in the Azure portal:
Navigate to your storage account in the portal.
Under Data management, choose Data protection.
In the Tracking section, select Enable versioning for blobs, and then choose whether to keep all versions or delete them after a period of time.
Important
If you set the Delete versions after option, a rule is automatically added to the lifecycle management policy of the storage account. Once that rule is added, the Delete versions after option no longer appears in the Data protection configuration page.
You can make that option reappear in the Data protection page by removing the rule. If your lifecycle management policy contains other rules that delete versions, then you'll have to remove those rules as well before the Delete versions after option can reappear.
To enable blob versioning for a storage account with PowerShell, first install the Az.Storage module version 2.3.0 or later. Then call the Update-AzStorageBlobServiceProperty command to enable versioning, as shown in the following example. Remember to replace the values in angle brackets with your own values:
# Set resource group and account variables.
$rgName = "<resource-group>"
$accountName = "<storage-account>"
# Enable versioning.
Update-AzStorageBlobServiceProperty -ResourceGroupName $rgName `
-StorageAccountName $accountName `
-IsVersioningEnabled $true
To enable blob versioning for a storage account with Azure CLI, first install the Azure CLI version 2.2.0 or later. Then call the az storage account blob-service-properties update command to enable versioning, as shown in the following example. Remember to replace the values in angle brackets with your own values:
To enable blob versioning with a template, create a template with the IsVersioningEnabled property to true. The following steps describe how to create a template in the Azure portal.
In the Azure portal, choose Create a resource.
In Search the Marketplace, type template deployment, and then press ENTER.
Choose Template deployment, choose Create, and then choose Build your own template in the editor.
In the template editor, paste in the following JSON. Replace the <accountName> placeholder with the name of your storage account.
Save the template.
Specify the resource group of the account, and then choose the Purchase button to deploy the template and enable blob versioning.
Navigate to your storage account in the portal, then navigate to the container that contains your blob.
Select the blob for which you want to list versions.
Select the Versions tab to display the blob's versions.
Toggle the Show deleted versions button to display soft-deleted versions. If blob soft delete is enabled for the storage account, then any soft-deleted versions that are still within the soft-delete retention interval will appear in the list.
To list a blob's versions with PowerShell, call the Get-AzStorageBlob command with the -IncludeVersion parameter: