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:

# 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.

  1. Go to the Azure portal (opens new window)
  2. Navigate to your Azure Storage account
  3. In the Blob service section, select the Data protection menu
  4. 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)

  1. Let's try it out. Create a new text file and write some text in it, like "Version 1"

(New text file)

  1. In the Azure portal, in the Blob service section, select the Containers menu
  2. Create a new blob container or click on an existing one
  3. Click Upload, select the text file that we've just created, and upload it.
  4. Now open the text file and change the text in it to something like "version 2"
  5. 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
  6. 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
  7. 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)

  1. 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!