Search code examples
azure-storage-account

How to archive all blobs matching a prefix from all containers in an Azure Storage Account?


I have a storage account where new containers may be created every day. All these containers have the structure and have a folder called photos with some blobs inside.

Ex:

containerA/photos/photoA1
containerA/photos/photoA2
containerB/photos/photoB1

I'd like to create a lifecycle rule to go through all the containers and archive all the blobs inside photos which haven't been updated for 90 days.

Unfortunately, it seems Azure doesn't support regex for the prefixMatch. I couldn't find any API to programmatically add new lifecycle rules when a new container is created...

Otherwise, another option would be to create an Azure function to upload the blob to the archive-tier and delete it. Surely there's an easier solution(?)


Solution

  • I got the answer from Microsoft Support:
    The workaround is to use "Blob index tags" and to create a rule based on this tag.

    Filter set on the rule: Filter Set

    Adding a tag to a blob (manually or programmatically): Blob index tag