TIP
🔥 Help shape the future of Azure Tips and Tricks by telling what you'd like for us to write about here (opens new window).
💡 Learn more : Storage account overview (opens new window).
📺 Watch the video : How to use Blob versioning in Azure Storage (opens new window).
# How to use Blob versioning in Azure Storage
# Protect your data
Azure Storage (opens new window) protects your data in many ways. It stores your data redundantly, so that it is safe, even in case of a datacenter outage and it offers many additional protection features, including Blob Storage versioning (opens new window).
In this post, we'll enable versioning for Azure Storage Blobs and track versions of a file.
# Prerequisites
If you want to follow along, you'll need the following:
- An Azure subscription (If you don't have an Azure subscription, create a free account (opens new window) before you begin)
- An existing Azure Storage V2 General purpose account. Create one with this guide (opens new window)
# Using Blob versioning
Blobs in Azure Storage can have versions. We can use these versions to access pervious blobs or revert to a specific version, so that you never lose any data. To use Blob versioning, we need to first enable it.
- Go to the Azure portal (opens new window)
- Navigate to your Azure Storage account
- In the Blob service section, select the Data protection menu
- Select "Turn on versioning for blobs" and click Save. From now on, Azure Storage will automatically retain versions of every file you upload or modify
(Turn on versioning in the Azure portal)
- Let's try it out. Create a new text file and write some text in it, like "Version 1"
(New text file)
- In the Azure portal, in the Blob service section, select the Containers menu
- Create a new blob container or click on an existing one
- Click Upload, select the text file that we've just created, and upload it.
- Now open the text file and change the text in it to something like "version 2"
- Go back to the Azure portal and the blob container and click Upload again and upload the new version of the text file. Make sure to check the "Overwrite if files already exist" checkbox
- To the right of the blob in the blob container, you'll see three dots. Click on them to open the context menu for the blob
- In the context menu, select the option "View previous versions". This will show all the versions of the blob
(Blob versions in the Azure portal)
- Open the context menu of the version of the blob and select "Download version". This will open the blob text file in another tab in your browser and shows you the previous version of the file
(Previous version of the blob file)
# Conclusion
Being able to download and revert versions of files is incredibly powerful and protects you from losing data. Azure Storage (opens new window) can help with this with Blob versioning (opens new window). Go and check it out!