gpt4 book ai didi

azure - 如何从 Blob 容器中删除超过 30 天的文件?

转载 作者:行者123 更新时间:2023-12-02 22:54:19 25 4
gpt4 key购买 nike

我正在寻找一种方法来删除名为 reports 的 Blob 容器中超过 30 天的存储文件,或设置任何其他有意义的保留策略

据我所知,微软只写了有关日志和元数据的保留策略。这可能吗?如何实现这一目标?

最佳答案

您可以使用Storage Lifecycle policy来实现这一目标。

#Initialize the following with your resource group and storage account names
$rgname = ""
$accountName = ""

#Create a new action object
$action = Add-AzStorageAccountManagementPolicyAction -BaseBlobAction Delete -daysAfterModificationGreaterThan 2555
$action = Add-AzStorageAccountManagementPolicyAction -InputObject $action -BaseBlobAction TierToArchive -daysAfterModificationGreaterThan 90
$action = Add-AzStorageAccountManagementPolicyAction -InputObject $action -BaseBlobAction TierToCool -daysAfterModificationGreaterThan 30
$action = Add-AzStorageAccountManagementPolicyAction -InputObject $action -SnapshotAction Delete -daysAfterCreationGreaterThan 90

# Create a new filter object
# PowerShell automatically sets BlobType as “blockblob” because it is the only available option currently
$filter = New-AzStorageAccountManagementPolicyFilter -PrefixMatch ab,cd

#Create a new rule object
#PowerShell automatically sets Type as “Lifecycle” because it is the only available option currently
$rule1 = New-AzStorageAccountManagementPolicyRule -Name Test -Action $action -Filter $filter

#Set the policy
$policy = Set-AzStorageAccountManagementPolicy -ResourceGroupName $rgname -StorageAccountName $accountName -Rule $rule1

https://learn.microsoft.com/en-us/azure/storage/blobs/storage-lifecycle-management-concepts?tabs=azure-portal#add-or-remove-a-policy

关于azure - 如何从 Blob 容器中删除超过 30 天的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59896614/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com