Edit

Share via


Migrate from diagnostic settings storage retention to Azure Storage lifecycle management

The Diagnostic Settings Storage Retention feature has being deprecated. All retention functionality for the Diagnostic Settings Storage Retention feature were disabled across all environments on September 30, 2025.

This article walks through migrating from using Azure diagnostic settings storage retention to using Azure Storage lifecycle management for retention. For logs sent to a Log Analytics workspace, retention is set for each table on the Tables page of your workspace. For more information on Log Analytics workspace retention, see Manage data retention in a Log Analytics workspace.

Prerequisites

An existing diagnostic setting logging to a storage account.

Migration procedures

Note

  • When you change your retention settings, the new settings only apply to new logs ingested after the change. Existing logs are subject to the previous retention settings.

  • Deleting a diagnostic setting doesn't delete the logs in the storage account. The retention settings will continue to apply to the logs created before the diagnostic settings were deleted.

Use the following CLI command to check if a resource has a diagnostic setting:

 az monitor diagnostic-settings list --resource <resource Id>

The output shows whether the diagnostic setting sends the data to a storage account, for example:

[
  {
    "id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/rg-001/providers/microsoft.insights/datacollectionrules/dcr-east2/providers/microsoft.insights/diagnosticSettings/dsetting-1",
    "logs": [
      {
        "categoryGroup": "allLogs",
        "enabled": true,
        "retentionPolicy": {
          "days": 0,
          "enabled": false
        }
      }
    ],
    "metrics": [
      {
        "category": "AllMetrics",
        "enabled": false,
        "retentionPolicy": {
          "days": 0,
          "enabled": false
        }
      }
    ],
    "name": "dsetting-1",
    "resourceGroup": "rg-001",
    "storageAccountId": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/rg-DCR/providers/Microsoft.Storage/storageAccounts/logs001",
    "type": "Microsoft.Insights/diagnosticSettings"
  }
]

Use the az storage account management-policy create command to create a lifecycle management policy. You must still set the retention in your diagnostic settings to 0. For more information, see the migration procedures for the Azure portal.


az storage account management-policy create --account-name <storage account name> --resource-group <resource group name> --policy @<policy definition file>

The sample policy definition file below sets the retention for all blobs in the container insights-activity-logs for the given subscription ID. For more information, see Lifecycle management policy definition.

{
  "rules": [
    {
      "enabled": true,
      "name": "Susbcription level lifecycle rule",
      "type": "Lifecycle",
      "definition": {
        "actions": {
          "baseBlob": {
              "delete": {
              "daysAfterModificationGreaterThan": 120
            }
          }
        },
        "filters": {
          "blobTypes": [
            "appendBlob"
          ],
          "prefixMatch": [
            "insights-activity-logs/ResourceId=/SUBSCRIPTIONS/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e"
          ]
        }
      }
    }
  ]
}

Next steps

Configure a lifecycle management policy.