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
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
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. :)
Thank you!
In my case, storage account has network restrictions and private endpoint is setup. Will this function still work?
If yes, what changes will be required to do so?
Hi Tony, sorry, I have no idea whether you'll need to make any changes. We implemented this once and haven't touched it since — it's still working, though. All our other backups from SQL use block blobs. You should probably just try the script and see if it works for you. If not, hopefully it will at least be a starting point. Good luck. :)
Hey Mark,
I'm also planning to shift to block blobs for SQL backups so I can use Lifecycle services to delete them after certain days but I've read they don't go above 200 GB.
Also testing out this function as well. Will update here what worked.
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.
@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.
@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.
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
@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.
@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.
35 people are following this question.