0
votes

Azure Storage Contains 4 main data storage components: Containers, File Shares, Queues and Tables. To periodically delete files in Containers: We have (Storage Life Cycle management for Blobs(Containers)) https://docs.microsoft.com/en-us/azure/storage/blobs/storage-lifecycle-management-concepts?tabs=azure-portal . Also many questions on SO and documentations are only relevant for azure blobs.

But same I couldn't find for Azure file share. As of now I can see 2 approaches: Run a cron job with credentials of storage account and periodically delete the files inside the fileshare, or spin up a logic app with the condition to delete old files.

Do we have any simpler way to do it in azure file share especially something like Lifecycle management that we have for blobs or are these two the only approaches ?

1
Currently there's no lifecycle management for Azure Files. You will have to pick one of the two approaches you mentioned above. You can use a Timer Triggered Function or Timer Triggered Logic App for that.Gaurav Mantri

1 Answers

1
votes

As stated by @Gaurav Mantri, Currently there is no lifecycle management for Azure Files.

You can follow below steps to achieve your requirement

  1. You can create an time triggered Function app.

    reference : https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-scheduled-function

  2. then use the below az cli script to delete the file share content.

    (This example deletes files which are not modified in last 90 days. You can change it to according to your requirements)

     $myshare = "<<Share Name>>"
     $accountName = "<<Storage Account Name>>"
     $accountKey = "<<Storage Account Access Key1>>"
    
     $filelist = az storage file list -s $myshare --account-name $accountName --account-key $accountKey
    
     $fileArray = $filelist | ConvertFrom-Json
     foreach ($file in $fileArray | Where-Object {$_.properties.lastModified.DateTime -lt ((Get-Date).AddDays(-90))})
         {
             $removefile = $file.name
             if ($removefile -ne $null)
             {
                 Write-Host "Removing file $removefile"
                 az storage file delete -s $myshare -p $removefile --account-name $accountName --account-key $accountKey
             }
         }