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

Mark 116 Reputation points
2020-07-14T12:17:13.99+00:00

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
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,683 questions
0 comments No comments
{count} vote

Accepted answer
  1. Mark 116 Reputation points
    2020-08-04T12:22:41.643+00:00

    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://learn.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. :)

    3 people found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Shweta Mathur 27,381 Reputation points Microsoft Employee
    2020-07-14T14:59:08.963+00:00

    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://learn.microsoft.com/en-us/rest/api/storageservices/put-page

    Hope this will help you to resolve your query.

    1 person found this answer helpful.

  2. Sumarigo-MSFT 43,561 Reputation points Microsoft Employee
    2020-07-16T04:16:49.21+00:00

    @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.