Search code examples
azure-blob-storageazure-storage

Azure file deletion not working with life cycle management rule


We have a requirement to delete the files after certain days from storage container folders.

I have set a rule to delete them as per below. But looks like this rule is not getting triggered. Please advice.

"rules": [
{
"enabled": true,
"name": "test",
"type": "Lifecycle",
"definition": {
"actions": {
"baseBlob": {
"delete": {
"daysAfterModificationGreaterThan": 1
}
}
},
"filters": {
"blobTypes": [
"blockBlob"
],
"prefixMatch": [
"raw / BV/ landing / BV-data-to-Data-Lake-Integration/events",
"raw / BV/ landing / BV-data-to-Data-Lake-Integration/event_",
"raw / BV/ landing / BV-data-to-Data-Lake-Integration/sensors"
]
}
}
}
]
}```` 
     

Solution

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

    I have set a rule to delete them as per below. But looks like this rule is not getting triggered.

    • If you not getting deleted, make sure the folder or files are already present before creation of the lifecycle management rule.
    • The rule applies only to files created after it was created. before if it is present, it will not be deleted.
    • Make sure If you are updating or new policy it may takes up to 48Hrs to complete.

    Portal:

    enter image description here

    Code view:

      "rules": [
        {
          "enabled": true,
          "name": "rule1",
          "type": "Lifecycle",
          "definition": {
            "actions": {
              "baseBlob": {
                "delete": {
                  "daysAfterModificationGreaterThan": 1
                }
              }
            },
            "filters": {
              "blobTypes": [
                "blockBlob"
              ],
              "prefixMatch": [
                "test/folder1/scores.json",
                "test1/folder1/file.json"
              ]
            }
          }
        }
      ]
    }
    

    Also check the any restrictions in place for the container or the blobs like Immutability policies or the blob is leased.

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