I have 3 months of old data which is stored on azure storage account ? Now i want remove the data if it >= 30days. some thing like retention period
I have 3 months of old data which is stored on azure storage account ? Now i want remove the data if it >= 30days. some thing like retention period
@BalaKrishna-2429
Azure Files does not currently have this functionality built-in. Please comment and upvote this existing feedback item. You could create automation from the client side which deletes the files from the directory or create a script using Azure functions or PowerShell. This thread has a PowerShell script which might be helpful.
Hope this helps! Let us know if you have further questions or issues.
Please don’t forget to "Accept the answer" and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.
@deherman-MSFT i tried the solution that you have mentioned in the other thread, but i think its keep on running into infinite loop and stops the execution after 3 hours. Am also checking for a way to delete the directories if they are empty.
The script is not checking inside the directory recursively . Script only checking the current or root directory . But i want to remove the data along with folder recursively if it's older than 30 days . Here am i added the script
List files recursively and remove file older than 30 days
$Subscription="XXXXXXXXXXXXXXXX"
$StorageAccountName="xxxxxxxxxxxxxxxxxxxxxxxxx"
$ResourceGroupName="xxxxxxx"
$fileshareName = "folder"
$StorageAccountAccessKey = Get-AzStorageAccountKey -ResourceGroupName $ResourceGroupName -AccountName $StorageAccountName | Where-Object
{$_.KeyName -eq "key1"}
$ctx = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountAccessKey.Value
$DirIndex = 0
$dirsToList = New-Object System.Collections.Generic.List[System.Object]
$shareroot = Get-AzStorageFile -ShareName $fileshareName -context $ctx
$dirsToList += $shareroot
Write-Host "DirIndex: "$DirIndex
Write-Host "dirsToList: "$dirsToList.Count
$dir = $dirsToList[$DirIndex]
$DirIndex ++
$fileListItems = $dir | Get-AzStorageFile -ShareName $fileshareName
$dirsListOut = $fileListItems | where {$_.GetType().Name -eq "AzureStorageFileDirectory"}
$files = $fileListItems | where {$_.GetType().Name -eq "AzureStorageFile"}
foreach($file in $files)
{
Write-Host "Current fileName: "$file.Name
# Fetch Attributes of each file and output
$task = $file.CloudFile.FetchAttributesAsync()
$task.Wait()
# remove file if it's older than 30 days.
if ($file.CloudFile.Properties.LastModified -lt (Get-Date).AddDays(-30))
{
Write-Host "file :",$file.Name "is older than 35 days so removing it ..!"
Remove-AzStorageFile -ShareName $fileshareName -Path $file.Name -Context $ctx
}
}
9 people are following this question.