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

Azure Storage Account V2 Life cycle management on container deleting all blobs


We have defined a life cycle management rule on one of container to delete blobs as below. blobs not last modified in 120 days will be deleted.

Question here is: will it check each blob under container (recursively) and delete the blobs only which are not last modified in 120 days or it just checks at container level last modified date and deletes all blobs?

Observation from our side: It just deleting all the blobs under container though some blobs are recently added. its not checking blob level last modified date.

Expectation/Requirement: Rule should run for all blobs under container and it should delete the blobs only which are not last modified in 120 days not all blobs under container.

Rule

{
      "enabled": true,
      "name": "120dayfilter",
      "type": "Lifecycle",
      "definition": {
        "actions": {
          "baseBlob": {
            "delete": {
              "daysAfterModificationGreaterThan": 120
            }
          }
        },
        "filters": {
          "blobTypes": [
            "blockBlob"
          ],
          "prefixMatch": [
            "container1",
            "container2"
      
          ]
        }
      }
    }

Solution

  • I tried to reproduce the same in my environment and I got the result successfully:

    Try providing prefix as your policy is deleting all the blobs under container irrespective of last modified date.

    To resolve this issue please apply the rule like below:

    {
    "rules": [
    {
    "enabled": true,
    "name": "rule1",
    "type": "Lifecycle",
    "definition": {
    "actions": {
    "baseBlob": {
    "delete": {
    "daysAfterModificationGreaterThan": 7
    }
    },
    "filters": {
    "blobTypes": [
    "blockBlob"
    ],
    "prefixMatch": [
    "container1/ab,nat,get,di"
    ]
    }
    }
    }
    ]
    

    Note: For each rule you can give up to 10 case-sensitive prefixes and upto 10 blob index tag conditions.

    You can add a common prefix of your blob like below:

    enter image description here

    Code view: enter image description here

    You can make use of filter blobs in the rules using their prefix or blob index matches. In certain areas, the blob index feature is available for public preview. This is basically just a tag that can be found through native Azure storage searches, not like a metadata tag you may have on a blob.

    Reference:

    Configure a lifecycle management policy - Azure Storage | Microsoft Learn