[英]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.