[英]Powershell: Copy file from Azure File Share to Blob Storage account
[英]How to remove azure file share old data from the azure storage account?
我有 3 个月的旧数据存储在 azure 存储帐户上? 现在我想删除数据,如果它 >= 30 天
以下脚本以递归方式列出文件共享中的文件/FileDir 并删除超过 30 天的文件。您可以提供所需的天数限制。 从这里的线程引用。
在删除活动之前,请参阅此以获得最佳实践。
$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() }
(要么)
可以按照以下步骤从Azure 数据工厂配置删除活动。这需要通过提供帐户名称、文件共享名称和路径(如果需要)将 Azure 存储帐户与 ADF 相关联。
Process is
:我们在选定的存储帐户中获取文件共享的元数据>遍历它们>为其中超过 30 天(或说一些 x 天)的文件配置删除活动
@adddays(utcnow(),-30)
@activity("Get old files").output.childItems
,然后单击完成。 (这里获取旧文件是我之前创建的获取活动的名称)@dataset().FileName
,为文件路径添加动态内容其他参考: clean-up-files-by-built-in-delete-activity-in-azure-data-factory/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.