Search code examples
azureazure-storageazure-blob-storagesoft-delete

Find permanent deletion date for soft deleted blobs in Azure Storage


I deleted a lot of blobs (50TB+) several weeks ago in my Azure Storage account that is protected with soft delete. The soft delete was configured with 14 days retention, which I later changed to 7 days.

However, 14 days have passed and the blobs are still not permanently deleted, as I can still see them when selecting 'Show deleted blobs' in the Azure Portal. This also means I am still being charged for storage.

Is there a way to find out the actual deletion date of a blob? I also see under Insights that the used capacity is still unchanged.


Solution

  • If you're using REST API, when you list the blobs with deleted as one of the values for include parameter (so that the listing results contain soft deleted blobs), you can find this information by inspecting two properties in the result:

    • Deleted-Time: It will tell you the date/time when the blob was deleted.
    • RemainingRetentionDays: It will tell you the number of days remaining after which the blob will be permanently deleted from storage.

    From this link:

    For version 2017-07-29 and above, Deleted, DeletedTime and RemainingRetentionDays appear when this operation includes the include={deleted} parameter. These elements do not appear if this blob was not deleted. These elements appear for blob or snapshot that are deleted with DELETE operation when soft delete feature was enabled. Deleted element is set to true for blobs and snapshots that are soft deleted. Deleted-Time corresponds to time when the blob was deleted. RemainingRetentionDays indicates number of days after which soft deleted blob will be permanently deleted by blob service.

    If you're using Azure.Storage.Blobs (.Net SDK), you will find this information in the following properties: BlobItemProperties.DeletedOn and BlobItemProperties.RemainingRetentionDays.

    For other languages, you can search for similar properties in the respective SDKs.

    UPDATE

    Please try the following:

    $context = New-AzStorageContext -StorageAccountName account-name -StorageAccountKey account-key
    $blobs = Get-AzStorageBlob -Container 001-000 -IncludeDeleted -Context $context
    $blobs.ICloudBlob.Properties | ConvertTo-Json
    

    Output will be something like the following. The first blob below is not deleted thus DeletedTime and RemainingDaysBeforePermanentDelete will be null. The second blob is soft-deleted and it will have these values populated.

    {
        "CacheControl":  null,
        "ContentDisposition":  null,
        "ContentEncoding":  null,
        "ContentLanguage":  null,
        "Length":  89,
        "ContentMD5":  "nax+W2kkfQqP8+K6dj2uFw==",
        "ContentType":  "image/svg+xml",
        "ETag":  "\"0x8D951D0C90A29CA\"",
        "Created":  "\/Date(1627481141000)\/",
        "LastModified":  "\/Date(1627481141000)\/",
        "BlobType":  2,
        "LeaseStatus":  2,
        "LeaseState":  1,
        "LeaseDuration":  0,
        "PageBlobSequenceNumber":  null,
        "AppendBlobCommittedBlockCount":  null,
        "IsServerEncrypted":  true,
        "IsIncrementalCopy":  false,
        "StandardBlobTier":  null,
        "RehydrationStatus":  null,
        "PremiumPageBlobTier":  null,
        "BlobTierInferred":  null,
        "BlobTierLastModifiedTime":  null,
        "DeletedTime":  null,
        "RemainingDaysBeforePermanentDelete":  null
    },
    {
        "CacheControl":  null,
        "ContentDisposition":  null,
        "ContentEncoding":  null,
        "ContentLanguage":  null,
        "Length":  98024,
        "ContentMD5":  "/uZucSqKCO71gFpGiSkyrQ==",
        "ContentType":  "application/font-woff",
        "ETag":  "\"0x8D951D0C90AC631\"",
        "Created":  "\/Date(1627481141000)\/",
        "LastModified":  "\/Date(1627481141000)\/",
        "BlobType":  2,
        "LeaseStatus":  0,
        "LeaseState":  0,
        "LeaseDuration":  0,
        "PageBlobSequenceNumber":  null,
        "AppendBlobCommittedBlockCount":  null,
        "IsServerEncrypted":  true,
        "IsIncrementalCopy":  false,
        "StandardBlobTier":  null,
        "RehydrationStatus":  null,
        "PremiumPageBlobTier":  null,
        "BlobTierInferred":  null,
        "BlobTierLastModifiedTime":  null,
        "DeletedTime":  "\/Date(1627481162000)\/",
        "RemainingDaysBeforePermanentDelete":  9
    }