简体   繁体   中英

Set Retention Period in BLOB Storage in Azure

I want to SET RETENTION Period manually so that I can delete my archived data once retention period is over. Please suggest me any link or way which could help me. Please suggest how I will be able to code in my portal to set it.

Note the approach I mention is not the direct approach of setting the retention duration per blob but a higher level policy which can affect the whole storage account or specific containers or specific blobs which match some filtration criteria. As of March 2021, I haven't yet found a way to set the retention period oa per blob basis via the Azure API.

Link to Lifecycle Management for Azure Blobs for Azure Storage V2

I have successfully configured a lifecycle management policy , which does exactly what you want to do, with ARM templates. Here's the minimal working example:

 }
  "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 }
              }
            }
          }
        }
      ]
    }
  }
}

In this example, I have setup the search to happen once a day with the trackingGranularityInDays field, and the BLOBs to be deleted after 90 days.

You can create using Azure Automation account.

You can try the following PowerShell script to remove Old Azure Storage Blobs. The below script works for the Classic Storage accounts, you can modify the script for the ARM Storage account.

https://www.wikitechy.com/tutorials/azure/delete-blobs-in-blob-storage-older-than-a-number-of-days

https://gist.github.com/philskents/4e61ebe418a7861ed294044814d193d7#file-remove-oldazurestorageblob-ps1

https://strangeadventures.in/deletingoldfilesfromazureblobstorage/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM