简体   繁体   English

Azure容器的保留策略?

[英]Retention Policy for Azure Containers?

I'm looking to set up a policy for one of my containers so it deletes or only retains data for x days. 我正在为我的一个容器设置一个策略,以便它删除或仅保留x天的数据。 So if x is 30, that container should only contain files that are less than 30 days old. 因此,如果x为30,则该容器应仅包含少于30天的文件。 If the files are sitting in the container for more than 30 days it should discard them. 如果文件在容器中放置了30天以上,则应将其丢弃。 Is there any way I can configure that? 有什么办法可以配置吗?

Currently such kind of thing is not supported by Azure Blob Storage. 当前,Azure Blob存储不支持这种事情。 You would need to write something of your own that would run periodically to do this check and delete old blobs. 您需要编写自己的某些内容,这些内容会定期运行以进行此检查并删除旧的Blob。

On a side note, this feature has been long pending (since 2011): https://feedback.azure.com/forums/217298-storage/suggestions/2474308-provide-time-to-live-feature-for-blobs . 顺便提一句,此功能早已待定(自2011年起): https : //feedback.azure.com/forums/217298-storage/suggestions/2474308-provide-time-to-live-feature-for-blobs

UPDATE 更新

If you need to do it yourself, there are two things to consider: 如果您需要自己执行此操作,则需要考虑两件事:

  1. Code to fetch the list of blobs, find out the blobs that need to be deleted and then delete those blobs. 代码获取Blob列表,找出需要删除的Blob,然后删除这些Blob。 To do this, you can use Azure Storage SDK. 为此,可以使用Azure存储SDK。 Azure Storage SDK is available for many programming languages like .Net, Java, Node, PHP etc. You just need to use the one that you're comfortable with. Azure存储SDK可用于多种编程语言,例如.Net,Java,Node,PHP等。您只需要使用自己喜欢的一种即可。
  2. Schedule this code to run once on a daily basis: To do this, you can use one of the many services available in Azure. 安排此代码每天运行一次:为此,可以使用Azure中可用的许多服务之一。 You can use Azure WebJobs, Functions, Schedular, Azure Automation etc. 您可以使用Azure WebJobs,Functions,Schedular,Azure Automation等。

If you decide to use Azure Automation, there's a Runbook already available for you that you can use (no need to write your code). 如果您决定使用Azure自动化,则已经有一个可供您使用的Runbook(无需编写代码)。 You can find more details about this here: https://gallery.technet.microsoft.com/scriptcenter/Remove-Storage-Blobs-that-aae4b761 . 您可以在此处找到关于此的更多详细信息: https : //gallery.technet.microsoft.com/scriptcenter/Remove-Storage-Blobs-that-aae4b761

Azure Blob storage Lifecycle (Preview) is now available and using that we create Policies with different rules. Azure Blob存储生命周期(预览)现已可用,并使用它来创建具有不同规则的策略。

Here is the rule to delete the blobs which are older than 30 days 这是删除超过30天的Blob的规则

 {
  "version": "0.5",
  "rules": [
    {
      "name": "expirationRule",
      "type": "Lifecycle",
      "definition": {
        "filters": {
          "blobTypes": [ "blockBlob" ]
        },
        "actions": {
          "baseBlob": {
            "delete": { "daysAfterModificationGreaterThan": 30}
          }
        }
      }
    }
  ]
}

For more details refer this Azure Blob storage Lifecycle 有关更多详细信息,请参考此Azure Blob存储生命周期

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure Container Registry 保留策略 - Azure Container Registry retention policy Azure 表存储保留策略 - Azure table storage Retention Policy 查找与备份策略关联的Azure备份/保留 - Find Azure backup/retention associated with backup policy Azure 策略存储帐户保留策略未标记资源 - Azure Policy Storage Accounts retention policy not flagging the resource Azure WORM/旧容器上的不可变保留锁 java SDK - Azure WORM/ immutable retention lock on containers for legacy java SDK (Azure)如何在Recoveryservices保管库中更改每个策略的保留期限 - (Azure)How to change retention period of each policy in Recoveryservices vault 如何使用 deployIfNotExists 策略强制在 Azure 存储上配置删除保留? - How to enforce that Delete Retention is configured on Azure Storage by using a deployIfNotExists policy? 在Azure上更改Blob容器访问策略 - Changing blob containers access policy on azure 使用C#为Azure SQL数据库设置长期保留策略 - Set Long Term Retention Policy for Azure SQL Database using C# 是否可以创建 Azure 策略以将资源组中每个资源的日志转发到具有特定保留时间的 Azure 监视器/日志分析 - Can I create a Azure policy to forward logs for every resource in a resource group to Azure monitor/log analytics with a specific retention
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM