jayaprakash R
jayaprakash R

Reputation: 192

Azure lifecycle policy for container is not working

I have configured azure lifecycle policy for container as below,

{
  "rules": [
    {
      "enabled": true,
      "name": "name",
      "type": "Lifecycle",
      "definition": {
        "actions": {
          "baseBlob": {
            "delete": {
              "daysAfterModificationGreaterThan": 30
            }
          }
        },
        "filters": {
          "blobTypes": [
            "blockBlob"
          ],
          "prefixMatch": [
            "storageaccount/container"
          ]
        }
      }
    }
  ]
}

So it will delete the blobs which was modified before 30 days. I am putting backups in the container so I want to delete the old backups which is 30 days older.

I configured this policy before 2 days before. Yet old backup files are not removed from the container

I analyzed and as per below links after the new policy configuration it will take up 24 hrs to take effect for new policy and policy update

ref:https://learn.microsoft.com/en-us/azure/storage/blobs/lifecycle-management-overview?tabs=azure-portal#faq

Lifecycle management policy not working on Azure Data Lake Gen 2

I cant find many documents regarding this issue also

I configured Firewalls and virtual networks as 'all networks'. why i am mention this because according to below documents his solution works,

https://learn.microsoft.com/en-us/answers/questions/107954/lifecycle-mangement-isn39t-doing-anything.html

Yet there is no update in containers. So anyone know the reason and troubleshoots to resolve this? thank you!

Upvotes: 1

Views: 2111

Answers (1)

kavya Saraboju
kavya Saraboju

Reputation: 10831

Please check if below points can help:

Things to check:

  1. Please check if there any immutability policies configured for blob versions .

If version-level immutability support is enabled for a container and the container contains one or more blobs, then you must delete all blobs in the container before you can delete the container, even if there are no immutability policies in effect for the container or its blobs.

  1. Please check if last access time tracking is enabled, because every time the blobs are accessed they move to hot tier and may change its modified time. You need to make sure you are using a V2 storage account: optionally-enable-access-time-tracking

Work around :

Use az cli to add life cycle policy to delete the blobs in the container whose last modification time is more than 30 days.

Note: (Try simply specifying the container name as blob prefixcontainer name in prefixmatch instead of storageaccount/container)

Ex policy.json :

 "rules": [
    {
      "name": "expirationRule1",
      "enabled": true,
      "type": "Lifecycle",
      "definition": {
        "filters": {
          "blobTypes": [ "blockBlob" ],
          "prefixMatch": [ "containername" ]
        },
        "actions": {
          "baseBlob": {
            "delete": { "daysAfterModificationGreaterThan": 30 }
          }
        }
      }
    }
  ]
}

Try to create this lifecycle management policy (policy.son) using the az cli command:

az storage account management-policy create --account-name youraccountname --policy @policy.json --resource-group myresourcegroup

References:

  1. lifecycle - Unable to add new rule in Storage Management Policy on Azure - Stack Overflow
  2. How to automatically delete old Azure Blob Storage containers - Stack Overflow

Upvotes: 3

Related Questions