[英]How to remove azure file share old data from the azure storage account?
I have 3 months of old data which is stored on azure storage account ?我有 3 个月的旧数据存储在 azure 存储帐户上? Now i want remove the data if it >= 30days
现在我想删除数据,如果它 >= 30 天
The following script lists files/FileDir recursively in a file share and delete the files older than 30 days.You may give the required day limit.以下脚本以递归方式列出文件共享中的文件/FileDir 并删除超过 30 天的文件。您可以提供所需的天数限制。 Refered from thread here .
从这里的线程引用。
Refer this for the best practices before delete activity.在删除活动之前,请参阅此以获得最佳实践。
$ctx = New-AzStorageContext -StorageAccountName $accountName -StorageAccountKey $key $shareName = <shareName> $DirIndex = 0 $dirsToList = New-Object System.Collections.Generic.List[System.Object] # Get share root Dir $shareroot = Get-AzStorageFile -ShareName $shareName -Path . -context $ctx $dirsToList += $shareroot # List files recursively and remove file older than 14 days While ($dirsToList.Count -gt $DirIndex) { $dir = $dirsToList[$DirIndex] $DirIndex ++ $fileListItems = $dir | Get-AzStorageFile $dirsListOut = $fileListItems | where {$_.GetType().Name -eq "AzureStorageFileDirectory"} $dirsToList += $dirsListOut $files = $fileListItems | where {$_.GetType().Name -eq "AzureStorageFile"} foreach($file in $files) { # Fetch Attributes of each file and output $task = $file.CloudFile.FetchAttributesAsync() $task.Wait() # remove file if it's older than 14 days. if ($file.CloudFile.Properties.LastModified -lt (Get-Date).AddDays(-14)) { ## print the file LMT # $file | Select @{ Name = "Uri"; Expression = { $_.CloudFile.SnapshotQualifiedUri} }, @{ Name = "LastModified"; Expression = { $_.CloudFile.Properties.LastModified } } # remove file $file | Remove-AzStorageFile } } #Debug log # Write-Host $DirIndex $dirsToList.Length $dir.CloudFileDirectory.SnapshotQualifiedUri.ToString() }
(OR) (要么)
Delete activity can be configured from Azure data Factory by following the steps below.This require linking your azure storage account with the ADF by giving accont name, fileshare name and path if needed.可以按照以下步骤从Azure 数据工厂配置删除活动。这需要通过提供帐户名称、文件共享名称和路径(如果需要)将 Azure 存储帐户与 ADF 相关联。
Process is
: We get the metadata of the file shares in storage account selected>Loop through them>configure Delete activity for the files inside them older than 30 days(or say some x days) Process is
:我们在选定的存储帐户中获取文件共享的元数据>遍历它们>为其中超过 30 天(或说一些 x 天)的文件配置删除活动
@adddays(utcnow(),-30)
@adddays(utcnow(),-30)
@activity("Get old files").output.childItems
and click on finish.@activity("Get old files").output.childItems
,然后单击完成。 ( Here Get old files is the name of my get activity created previously ) @dataset().FileName
@dataset().FileName
,为文件路径添加动态内容 Other reference : clean-up-files-by-built-in-delete-activity-in-azure-data-factory/其他参考: clean-up-files-by-built-in-delete-activity-in-azure-data-factory/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.