Sunday, June 30, 2024

Promote Azure Snapshot with Azure CLI

Azure Storage account blobs facilitate versioning through two mechanisms, blob versioning and blob snapshots. Blob versioning creates a new version with each edit, while blob snapshots allow you to take a snapshot of the current blob and make changes to it. Both mechanisms enable users to revert to a previous version or a created snapshot if needed and recover the data.

This blog explains how to revert to a blob snapshot using an automated script.

Prerequisite: Azure DevOps blob

Use the following command to create a snapshot of the current version and get the snapshot ID. This snapshot ID will be used to identify the correct snapshot in the revert step.

az storage blob snapshot --name <<blobname>> --container-name <<containername>> --account-name <<storageaccount>> --account-key <<accesskey>>


The created Snapshot will be listed under snapshots of the relevant blob.



After taking the snapshot, upload a new version of the blob or make changes to the blob. As a change, all the content has been removed from the blob.



Use the following script to revert to the previous snapshot (version). Use the same blob, container, and storage account as source and destination values.

az storage blob copy start --account-name <<storageaccount>> --destination-blob <<blobname>> --destination-container <<container>> --source-blob <<blobname>> --source-container <<container>> --source-account-name <<storageaccount>> --source-snapshot <<snapshotid>> --account-key <<accesskey>>


No comments:

Post a Comment