azure - 设置 Azure 中 BLOB 存储的保留期

标签 azure azure-storage azure-blob-storage

我想手动设置保留期,以便在保留期结束后我可以删除我的存档数据。请向我建议任何可以帮助我的链接或方式。请建议我如何在我的门户中编写代码来设置它。

最佳答案

我已成功配置 lifecycle management policy ,它完全可以使用 ARM 模板完成您想要做的事情。这是最小的工作示例:

 }
  "type": "Microsoft.Storage/storageAccounts",
  "apiVersion": "2021-04-01",
  "name": "[variables('storageAccountName']",
  "location": "[resourceGroup().location]",
  "sku": {
    "name": "Standard_LRS",
    "tier": "Standard"
  },
  "kind": "StorageV2",
  "properties": {
    "minimumTlsVersion": "TLS1_2"
  }
},
{
  "type": "Microsoft.Storage/storageAccounts/blobServices",
  "apiVersion": "2021-02-01",
  "name": "[concat(variables('storageAccountName'), '/', 'default')]",
  "dependsOn": ["[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"],
  "properties": {
    "lastAccessTimeTrackingPolicy": {
      "blobType": [ "string" ],
      "enable": true,
      "name": "AccessTimeTracking",
      "trackingGranularityInDays": 1
    }
  }
},
{
  "type": "Microsoft.Storage/storageAccounts/managementPolicies",
  "apiVersion": "2021-02-01",
  "name": "[concat(variables('storageAccountName'), '/', 'default')]",
  "dependsOn": ["[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"],
  "properties": {
    "policy": {
      "rules": [
        {
          "name": "expirationRule",
          "enabled": true,
          "type": "Lifecycle",
          "definition": {
            "filters": {
              "blobTypes": [ "blockBlob" ]
            },
            "actions": {
              "baseBlob": {
                "delete": { "daysAfterModificationGreaterThan": 90 }
              }
            }
          }
        }
      ]
    }
  }
}

在此示例中,我使用 trackingGranularityInDays 字段将搜索设置为每天进行一次,并在 90 天后删除 BLOB。

关于azure - 设置 Azure 中 BLOB 存储的保留期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50952681/

相关文章:

azure - 为什么 azure-active-directory-spring-boot-starter 需要访问 Microsoft?

python - 上传到 Azure Blob 存储时设置内容类型

visual-studio - 不使用模拟器安装 Azure SDK

php - Azure使用rest api和php将blob从一个容器复制到同一存储帐户中的另一个容器

azure 通知中心注册生存时间

python - 如何将Azure应用服务Python版本从3.9.7更改为3.9.12?

azure - 快速检测VM是否正在Azure上运行

azure - 使用 Java SDK 生成 Azure Blob 存储的签名 URL

python 异步 upload_blob -- 类型错误 : object AccessToken can't be used in 'await' expression

azure - 发布到 Azure Blob 存储时自动生成缩略图或预览图像