Azure Blob Versioning and AzCopy

Azure Blob Versioning when enabled is a feature that will automatically maintain previous versions of an object.  This allows you to restore an earlier version to recover your data if it was modified or deleted by mistake.   Which is a great feature to be able to have access to for organizations or even for home use.  Being able to quickly recover a previous version of a file without having to engage your whole process/tool will save a lot of pain and time.

You can enable blob versioning when you create an Azure account in the portal or via an ARM template.

Azure PortalAzure Portal
Azure PortalAzure Portal

I have an Azure Account with a Blob Container and some files stores within it, just some simple text files.  I have versioning turned on that account.

You can see with my music.txt file that I have the ability to see the different saved versions of that file.  Each version of the file is given a version ID to help you identify it.

For each version of the file I have a lot of options, I can download it, make it the current version (ultimately restoring it), delete it, generate a shared access signature (SAS) for that blob or even change the access tier that that version is stored in.

Azure PortalAzure Portal

Now you don't just have to use the Azure Portal to interact with the versions of the files.  AzCopy supports interacting with them as well.

If I launch AzCopy and issue the AzCopy Copy command, which will copy files from one location to another.  In this case I want to copy the different versions of my “music.txt” from Azure down to my local machine.

The command starts off with the copy instruction and the source and destination locations, then I add on the switch that will allow me to download the file versions:

Azcopy copy “C:userssaleandownloadsazurestorage” –list-of-versions=”versions.txt”

Copy code snippet

For the list of versions switch to work I need to pass in a file listing the version IDs of all the versions that I want to download. Each version ID needs to be placed in a separate line.

And when I run the command AzCopy will download the relevant files for me.

Windows Terminal and commandsWindows Terminal and commands


This article was originally published by Microsoft's ITOps Talk Blog. You can find the original article here.