Search code examples
azureazure-blob-storageazure-storage-account

Azure storage deletion policy does not work


I need to delete all blobs residing in a particular container in my storage account after 1 day since creation. To do that I have tried to set a policy but I cant make it work so far.

I have tried to create the policy both by using the azure portal and by using terraform. The policy code view shown in the portal is the following:

{
  "rules": [
    {
      "enabled": true,
      "name": "delete_old_records_csv_files",
      "type": "Lifecycle",
      "definition": {
        "actions": {
          "baseBlob": {
            "delete": {
              "daysAfterCreationGreaterThan": 1
            }
          }
        },
        "filters": {
          "blobTypes": [
            "blockBlob"
          ],
          "prefixMatch": [
            "queryresults"
          ]
        }
      }
    }
  ]
}

I have waited 2 days for the files to get deleted but they did not. Is there something I am doing wrong?

Thanks!


Solution

  • I have waited 2 days for the files to get deleted but they did not. Is there something I am doing wrong?

    • If the blobs are created before the creation of the lifecycle management rule they will not be deleted.
    • To apply policy for existing blobs, you can move or copy them to a new container where the policy will be applied.
    • Make sure If you are updating or new policy it may take up to 48Hrs to complete.

    Portal:

    enter image description here

    • Ensure that the blobs you trying to delete match the prefix "queryresults" as same as in the specified policy.
    • Also check if any restriction is applied to a container or blob like Immutablity policy and the blob is leased.

    enter image description here

    If everything is correct but still not being deleted, you can debug your storage account by using audit logs and if you get warning that will explain why the policy is not working.

    Reference: azure - Lifecycle management rule not working for ADLS Gen2 Storage Account - Stack Overflow by Joel Cochran.