0
votes

I realize Azure Blob Storage Life Cycle Management supports only Block blobs. It doesn't support Append or Page blobs.

A solution we are considering is to - do the crude way - of enumerating blobs in each of the containers from a logic app or function app, and deleting based on certain rules similar to Azure's storage Life Cycle Management, say, modified date is n days old.

Has anyone run into a similar requirement of cleaning up storage? Could anyone suggest a better way of implementing this?

Greatly appreciate it.

Thank you Athadu

1
We were aware of how to do it coding wise. My question was more related to doing anything different from enumerating and deleting - like I mentioned - the crude/straight-forward way. Appreciate your response. Thank you AthaduAthadu
I really understand the question. As I mentioned in the answer, besides Life Cycle Management, the only way to do that is enumerating then deleting. I also believe even if the Life Cycle Management itself takes use of the same logic in the backend. As well, Life Cycle Management is planning to support append blobs later in 2020, see this github issue.Ivan Yang
The feature is now available to delete append blobs. Page blobs is on their backlogEmmie
@Emmie Thank you for the update - will look up the support added for Append blob.Athadu

1 Answers

0
votes

The only way I can think of same as you mentioned, create a timer trigger function app or webjob.

Here is the sample:

Blob storage package: Microsoft.Azure.Storage.Blob, version 11.1.3

The sample code:

    static void Main(string[] args)
    {
        var connection_str = "xxxxx";
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connection_str);
        CloudBlobClient cloudBlobClient=storageAccount.CreateCloudBlobClient();

        //list all the containers
        var containers = cloudBlobClient.ListContainers();


        foreach (var container in containers)
        {
            Console.WriteLine(container.Name);

            //find blobs whose type is CloudAppendBlob
            var blobs = container.ListBlobs("", useFlatBlobListing: true).OfType<CloudAppendBlob>();


            if (blobs.ToList().Count() <=0) continue;

            foreach (var blob in blobs)
            {
                Console.WriteLine($"blob name is {blob.Name}");

                //add your own logic here
                //if condition use blob.Properties.LastModified

                blob.Delete();
            }
        }

   }

Hope it helps.