How to delete files in Azure blob which is older than XX days

Leong, HoeySiang 0 Reputation points
2024-08-20T09:21:14.32+00:00

How to delete files older than XX days inside the Azure blob storage? I do not want to delete the blob but i want to delete the files inside. Thank you.

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,782 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Pritam Ghatak 231 Reputation points
    2024-08-20T09:48:40.76+00:00

    Hi,

    You can configure Azure storage LifeCycle policy to delete the file automatically.

    https://learn.microsoft.com/en-us/azure/storage/blobs/lifecycle-management-policy-configure?tabs=azure-portal

    0 comments No comments

  2. Pritam Ghatak 231 Reputation points
    2024-08-20T09:52:06.96+00:00

    Hi @Leong, HoeySiang,

    You can try to use Azure storage lifecycle policy to achieve this. Please find the link below where it is mentioned about lifecycle policy and steps to enable the same.

    https://learn.microsoft.com/en-us/azure/storage/blobs/lifecycle-management-policy-configure?tabs=azure-portal

    0 comments No comments

  3. Nehruji R 7,131 Reputation points Microsoft Vendor
    2024-08-21T07:32:21.1566667+00:00

    Hello Leong, HoeySiang,

    Greetings! Welcome to Microsoft Q&A Platform.

    To delete older files from each folder in Azure Blob Storage, you have a couple of options:

    #1. Blob Lifecycle Management (Recommended): Azure Storage provides a feature called Blob Lifecycle Management. With this, you can define policies to automatically delete blobs based on criteria such as their age (e.g., older than 30 days). Go to your Azure Storage Account.Navigate to Blob Service > Lifecycle Management. Define a policy to delete blobs older than your desired threshold (e.g., 14 days). Azure Storage will handle the deletion for you.

    #2. Azure Functions: You can create an Azure Function that periodically checks each folder and deletes files older than a specified duration. Here’s a high-level approach: Create a Timer Trigger function. Fetch the list of blobs from the corresponding Blob Container. Check the LastModified property of each blob. Delete the blobs that don’t meet your criteria (e.g., older than 14 days).

    Remember to test any deletion process on a test folder first to avoid accidental data loss. Adjust the path and days as needed for each folder.

    Hope this answer helps! Please let us know if you have any further queries. I’m happy to assist you further.


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.