question

Mark-8346 avatar image
0 Votes"
Mark-8346 asked Mark-8346 answered

How can we automatically delete page blobs from Azure storage after a set time period?

Hi, we're backing up directly from SQL Server 2016 to an Azure storage account. This uses page blobs, which means we cannot use Lifecycle Management to automatically delete files after seven days. Is there another way to achieve this?

Thanks, Mark

azure-storage-accounts
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Mark-8346 avatar image
1 Vote"
Mark-8346 answered

For anyone else looking to do this, I eventually used an Azure Function App on a timer, which runs Powershell commands to delete anything older than 168 hours (seven days). The basics of setting this up are here:

https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-scheduled-function

I then used the following Powershell script:

 param($TimerBlob)
    
 $CleanupTime = [DateTime]::UtcNow.AddHours(-168)
 $context = New-AzStorageContext -StorageAccountName <MyStorageAccount> -StorageAccountKey <MyAccessKey>
 Get-AzStorageBlob -Container "<MyContainerName>" -Context $context | 
 Where-Object { $_.LastModified.UtcDateTime -lt $CleanupTime -and $_.BlobType -eq "PageBlob" -and $_.Name -like "*.bak"} |
 Remove-AzStorageBlob

$TimerBlob is the name of the associated timer object.

It's been running for a couple of weeks now and seems to be working well. I hope this helps someone out there. :)

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ShwetaMathur avatar image
1 Vote"
ShwetaMathur answered Mark-8346 commented

Hi @Mark-8346 , thanks for the question.


Life cycle management only supports block blob type, so as mentioned by you as well it is not possible to delete page blob through life cycle management.


However, REST API provide Put page operation to writes a range of pages to page blob. You can you the clear option with put page to release the storage space used by specified page. Pages that have been cleared are no longer tracked as part of the page blob.


Pages that have been cleared no longer incur a charge against the storage account, as their storage resources have been released. The only exception to this is if there are existing snapshots of the page blob; pages in snapshots incur a charge if those same pages no longer exist as part of the source blob.


You can specify the ranges of pages you want to clear based on last-modified response or on specific time.


Please check the below documentation for better understanding:


https://docs.microsoft.com/en-us/rest/api/storageservices/put-page


Hope this will help you to resolve your query.



· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Mark-8346 Just checking in to see if the above answer helped. If this answers your question, please don’t forget to "Accept the answer" and Up-Vote as this might be beneficial to other community members reading this thread. If you have any further questions please let us know.


0 Votes 0 ·

@Mark-8346 Just checking in to see if the above answer helped. If this answers your question, please don’t forget to "Accept the answer" and Up-Vote as this might be beneficial to other community members reading this thread. If you have any further questions please let us know.

0 Votes 0 ·

Hi, sorry for the delay. Is the only way of doing this through the API then? It strikes me as a little odd that the Lifecycle Management feature wouldn't extend to page blobs. What is the reason for this and are there any plans to update it?

Thanks, Mark

0 Votes 0 ·
Sumarigo-MSFT avatar image
0 Votes"
Sumarigo-MSFT answered Sumarigo-MSFT commented

@Mark-8346 Thanks for the feedback. There is no plan to support page blob as of now. . This request helps us to keep an eye on this and consider it for the next planning milestone.


If you wish you may leave your feedback here All the feedback you share in these forums will be monitored and reviewed by the Microsoft engineering teams responsible for building Azure.


Hope this helps!


Kindly let us know if the above helps or you need further assistance on this issue.




Please don’t forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.




· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Mark-8346 Just checking in to see if the above answer helped. If this answers your query, please don’t forget to "Accept the answer" and Up-Vote for the same, which might be beneficial to other community members reading this thread. And, if you have any further query do let us know.

0 Votes 0 ·