简体   繁体   English

如何从 azure 存储帐户中删除 azure 文件共享旧数据?

[英]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 相关联。

  • Deploy an ADF if not already configured:如果尚未配置,请部署 ADF:

f1

  • Open ADF and create a PipeLine with any name.打开 ADF 并创建一个任意名称的 PipeLine。

f2

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 天)的文件配置删除活动

    1. Search for get meta data >> select and drag to place in the area shown and name the file.搜索获取元数据>>选择并拖动以放置在显示的区域中并命名文件。 2) Then navigate to Dataset(This data set points to the files in storage account),select new . 2)然后导航到数据集(此数据集指向存储帐户中的文件),选择新的。 So select azure file storage>Name it 3) >>Select the format as csv 4)>>Link your account by setting up the properties>give the file path.所以选择azure file storage>Name it 3) >>选择格式为csv 4)>>通过设置属性链接您的帐户>给出文件路径。

f3

  • To get files older than or equals 30 days you can configure endtime as @adddays(utcnow(),-30)要获取早于或等于 30 天的文件,您可以将结束时间配置为@adddays(utcnow(),-30)

在此处输入图片说明

  • Now we have to use foreach loop to iterate through the array of files.现在我们必须使用 foreach 循环来遍历文件数组。 Drag and drop foreach loop from activities and connect it with get metadata.从活动中拖放 foreach 循环并将其与获取元数据连接。

f5

  • In settings ,Tick mark sequential box to iterate files in sequential order.在设置中,勾选标记顺序框以按顺序迭代文件。 childItems is the property of getmetadata output JSON which has array of objects . childItems 是具有对象数组的 getmetadata 输出 JSON 的属性。 So select Dynamic content for Items and configure as @activity("Get old files").output.childItems and click on finish.因此,为 Items 选择 Dynamic content 并配置为@activity("Get old files").output.childItems ,然后单击完成。 ( Here Get old files is the name of my get activity created previously ) (这里获取旧文件是我之前创建的获取活动的名称)

f6

  • In the Foreach activity ,edit the activities and set a delete activity as below.在 Foreach 活动中,编辑活动并设置删除活动,如下所示。

在此处输入图片说明 在此处输入图片说明

  • Go to the dataset where we previously linked our file storage account.转到我们之前链接文件存储帐户的数据集。

f9

  • Create a file name parameter and link it to delete activity by adding dynamic content for file path by selecting that filepath as @dataset().FileName创建文件名参数并将其链接到删除活动,方法是选择该文件路径为@dataset().FileName ,为文件路径添加动态内容

f10

  • Then go to the delete pipeline and add the file name as shown.然后转到删除管道并添加文件名,如图所示。

在此处输入图片说明

  • You may also add logging setting to link account and see the activity happening after the path is debugged.您还可以将日志设置添加到链接帐户并查看路径调试后发生的活动。

在此处输入图片说明

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.

相关问题 Powershell:将文件从 Azure 文件共享复制到 Blob 存储帐户 - Powershell: Copy file from Azure File Share to Blob Storage account 如何通过Azure DevOps从Azure删除存储帐户 - How to remove a storage account from Azure through Azure DevOps 备份Azure存储帐户文件共享 - Backup of azure storage account file share 如何将文件从 React 应用程序上传到存储帐户下的 azure 文件共享? - How to upload files from a react application to azure file share under storage account? 如何使用 .net 核心从不同存储帐户的 Azure 文件共享(不是 blob)复制文件 - How to copy files from Azure File-Share (not blob) of different storage account using .net core 如何从azure中的存储帐户中查找谁删除了文件共享文件夹 - How to find who has deleted the file share folder from the storage account in azure 使用 Azure DevOps 中的 Azure 文件复制任务将数据从存储帐户复制到存储帐户 - Using Azure File Copy Task in Azure DevOps to Copy Data from Storage Account to Storage Account 如何从Azure订阅中删除当前存储帐户? - How to remove current storage account from Azure Subscription? 如何从另一个订阅访问 Azure 存储 NFS 文件共享 - How to Access Azure Storage NFS File Share from another Subscription 为 Azure 文件共享存储帐户部署模板时面临的问题 - Facing Issues on Deploying template for Azure File Share Storage Account
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM