Home > Software engineering >  How to add filter to Container for deleting blobs except some blobs in a virtual folder?
How to add filter to Container for deleting blobs except some blobs in a virtual folder?

Time:04-15

I am having set of folders in container named records (Azure storage account). In general what ever the blobs(folders) present in records container it will be deleted as per lifecycle management rule.

Rule: if blob exists more than 30days than it will delete the blob.

But As per my case, All blobs (folders) should delete except one blob (folder) where the blob(folder) name is Backup in the container.

Is there any way to add a rule for not deleting particular blob(In my case it is folder)? enter image description here So backup folder shouldn't delete when the existing rule run.

CodePudding user response:

Create a lease for the particular blob using the azure portal for example. A lease prevents processes from doing anything with the blob. This includes lifecycle management rules.

enter image description here

You can also acquire or break a lease using the rest api or one of the many storage SKDs.

Another option would be to not use the lifecycle management rules but write a scheduled azure function that deletes blob older than 30 days except the ones having backup in their name.

Please do note: if you have enabled "Hierarchical namespace" then you have the concept of directories, but those cannot be leased. If you did not then you should realise that folders are a virtual construct and as such cannot be leased as they are actually blobs. See the docs. So in that case you have to individually take a lease on each blob or write a script that does it once.

  • Related