Managing Azure Blobs snapshots

Let’s talk a little bit about managing Azure blobs snapshots on storage account.
For those who are not familiar with storage account I reccomend to check Microsoft documentation https://docs.microsoft.com/en-us/azure/storage/storage-dotnet-how-to-use-blobs
Backup management for files stored on blobs it’s not so easy as for other components like for example WebApps, where backup can be configured in Azure portal just by few clicks.
But thankfully we have Powershell 🙂
To start backup (snapshot) creation, login to azure and select proper subscription.

Login-AzureRmAccount
Select-AzureRmSubscription -SubscriptionID "SubscriptionID"

Define rersource group and storageaccountname, it can be useful in next lines of code

$ResourceGroup = "ResourceGroupName"
$StorageAccountName = "StorageAccountName"
$StorageAccount = Get-AzureRmStorageAccount -ResourceGroupName $ResourceGroup -Name $StorageAccountName

To have an access to storage account, you must gather information about storage keys.
Use below command

$StorageAccountKey = Get-AzureRmStorageAccountKey -ResourceGroupName $ResourceGroup -Name $StorageAccountName

Command will return list of available keys, in your guess is decide which key should be use.

In next step correct context for storage account must be created. It enables you to authenticate request without specifying storage account and its access key explicitly.
$StorageAccountKey[0].Value – means that value of first element from list is taken

$StorageContext = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey[0].Value

Get-AzureStorageCotainer command list you all containers allocated in blob storage.

$StorageContainerList = Get-AzureStorageContainer -Context $StorageContext 

Select the blob which you want to backup. Please check if variable $StorageContainerList contains only one object, otherwise you must select which object of containers array you want to select

$blob = Get-AzureStorageBlob -Container $StorageContainerList.Name -Context $StorageContext

Once you will have blob retrived use below command to create snapshot. It will create snapshot only for first element of blob array. If you want to do it for another element, provide correct number.

$blob[0].ICloudBlob.CreateSnapshot()

In result you should see something like this

To verify that snapshot has been created, retrive infomration about blob..

$blob = Get-AzureStorageBlob -Container $StorageContainerList.Name -Context $StorageContext

… and use below command

$blob[0].ICloudBlob.IsSnapshot

If True was returned it means that snapshot has been created correctly.
I hope that it will be useful for some of you.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.