Blob versioning helps to maintain the last modified version of an object (Files, Images or Videos, etc), if the same object is updated by any operation. If blob versioning is enabled, then any available previous copy can be restored. We should use blob versioning to maintain previous versions to enable another layer of data protection.
Blob versioning feature is available for general-purpose V2, block blob, and Blob storage accounts. If this feature is enabled, then it applies to all blobs in the storage account. The storage account automatically creates another version when there are any changes in any existing blobs or uploading the same file again and again.
This feature only enables to protect data inside blob container, but if you the delete storage account or container then, data cannot be recover.
Some points about blob versioning are below —
- When blob versioning is enabled and some operation modifies the blob, then a new version of blob gets to create, which is a copy of the same blob just before any update or delete.
- The new version of the blob is assigned with a new Version ID and would become the base version. This version ID is used to access a specific blob to perform a read, edit, or delete operation. This version ID remains the same for the lifetime of the version.
- Blob versions are immutable which means you cannot edit a blob version.
How to enable Blob Versioning
We need an Azure Storage account to enable blob versioning. So, let’s first create a storage account by login into Azure Portal with your subscription. Your storage account details may vary. After providing all the details, I will click on Create to create the storage account.
This storage account uses Locally-redundant storage replication, just for demo purpose. But, this replication may not suitable for a production environment. You may choose ZRS (Zone Redundant Storage) or GRS (Geo Redundant Storage) if want to enable blob versioning in a production environment.
Once Storage Account is ready, go to Resource Group > Storage Account > (Left Blade) Blob Service > Data Protection.
Now, it’s time to enable Blob Versioning by checking “Turn on versioning for blob” and Save the setting. Same settings can be enabled while creating the storage account from the Data Protection tab.
So, the blob version is enabled for the Azure storage account. Now, the next step is to upload some file and see the behavior.
Blob Versioning Behavior
Let’s perform the below steps to understand the behavior.
- Create a container <container1>
- Create one file <BlobVersioning.txt>, enter some text, and save this file to your computer.
- Upload the same file to blob container by modifying some text.
- While uploading check the option “Overwrite if files already exist”.
I have uploaded the same file three times, so there would one base version and two previous versions. To verify the versions, select the file “BlobVersioning.txt” from the container , then select the Versions tab from the open window.
One real time application that I can correlate with blob versioning is source code repositories (VSTS or GIT), where we maintain many versions of source code files.
So, we have seen that how to enable blob versioning and how it works in Azure. In this post, we have enabled blob versioning and seen the different versions of a blob file from the Azure portal, but the same thing can be achieved using Azure CLI, Azure PowerShell, and programming languages.
If you have any suggestions/feedback, please put them in the comment box.
Happy Learning 🙂