-
Notifications
You must be signed in to change notification settings - Fork 222
How to use blob versioning feature in AzCopy
Blob versioning is a feature, which when enabled on your Azure storage account, can help restore an earlier version of a blob to recover your data if it is erroneously modified or deleted. After you enable blob versioning for a storage account, Azure Storage automatically maintains versions for every blob in the storage account. Please refer to the public documentation for more information.
We support downloading & deleting specific versions of a blob using AzCopy. To specify list of versions which you wish to download/delete, you have to provide list-of-versions
flag which will contain path of a file. Now that file contains version ids of the blob listed on a separate line.
This is how the AzCopy command will look like :-
azcopy copy "https://[srcaccount].blob.core.windows.net/[containername]/[blobname]" "/path/to/destination/directory" --list-of-versions="/path/to/file/containing/listOfVersionIds"
For example :-
azcopy copy "https://myaccount.blob.core.windows.net/testcontainer/testblob" "D:\\destination" --list-of-versions="D:\\versionids.txt"
The above command will fetch version ids from versionids.txt
file and download those specified versions of blob in D:\destination
folder.
This is how versionids.txt file should look like.
- The source (
https://[srcaccount].blob.core.windows.net/[containername]/[blobname]
) must be a valid blob. - The destination (
"D:\\dest"
) must be a valid folder. -
versionIds.txt
file can have one or more version Ids of the same blob. As for the delimiter, place each version id in the separate line and that's it.
There are many ways to get version ids of a blob. One such way is through Azure Portal
Files will be downloaded in the D:\destination
folder and as for the nomenclature, files will be named based on their version-ids. For example: If the version id of the blob testblob
is 2020-08-05T17:09:40.5019067Z
then the name of downloaded version will look like 2020-08-05T17-09-40.5019067Z-testblob
. Notice that the colons (":") have been replaced by hyphen ('-') and blob name has been appended in the name if the downloaded file.