使用 Azure portal、Azure PowerShell 或 Azure CLI 配置 Azure 备份 中的细分计费

Azure 备份中的精细计费使你可以以自定义粒度级别查看备份成本,以便跨团队、应用程序和成本中心改进退款和报告。

Important

  • 细粒度计费支持恢复服务保管库和备份保管库。
  • 此功能只是管理平面报告更改,不会修改定价计量或总备份成本。
  • 现有的历史账单行保持早期格式,只有新费用使用选定的粒度。
  • Vault 级别是现有和新 Vault 的默认设置,保持向后兼容性。

可用的计费粒度级别

Azure 备份提供了多个粒度级别,可帮助你根据报告和退款要求查看和分析备份成本。

可以根据要求选择以下粒度级别之一:

  • 保管库级别(默认):显示在关联的恢复服务保管库或备份保管库下呈现的备份成本。 映射到指定计量的资源的成本显示为每个保管库的一个行项。

  • 受保护的项级别:显示每个受保护项的备份成本。

  • 标签级别:按标签汇总备份成本,以查看和分析资源层面的支出。

    • 默认标签(推荐):当你选择标签级别时,Azure 备份 会自动将内置ms-resource-parent标签传递给 Azure 成本管理。 每个受保护项目的备份费用都显示在 Azure 成本管理 的相关资源下,这样你可以在无需额外配置的情况下,获得资源和备份成本的整合视图。

    • 自定义标签:要将备份成本归属于其他资源,添加cm-resource-parent该标签并将其值设置为你希望备份成本显示的目标资源的 Azure 资源管理器(ARM)资源 ID。 Azure 备份 随后会在 Azure 成本管理 中汇总该资源下的备份费用,这样你就可以支持自定义的退款和成本报告场景。

通过使用 Azure 门户设置细分计费

两种保险库的步骤都相同,只是导航到 属性 窗格的方式不同。 选择你想要配置的保管库类型:

  1. 在 Azure 门户中,进入恢复服务保管库,然后选择设置>属性。

    显示如何在恢复服务保管库中配置精细计费属性的屏幕截图。

  2. 在 “属性 ”窗格中,对于 成本管理粒度,请选择“ 更新 ”。

  3. 在 成本管理粒度 面板中,选择一个 粒度选项。

  4. 选择 “更新 ”以保存设置。

下表列出了颗粒级别以及你传递给 -CostManagementGranularity 参数的值。

粒度级别(门户) Value Behavior
金库等级(默认) VaultLevel 保管库中的所有备份会汇总为每个保管库的一条行项目。
受保护项级别 ProtectedItemLevel 显示每个受保护物品的备份费用。
标签级别 ProtectedItemWithParentTag 它通过父标签汇总备份成本,因此你可以在资源层面查看支出。

Prerequisites

在使用Azure PowerShell配置细分计费之前,请确保满足以下先决条件:

为精细计费配置设置 Azure PowerShell

使用 Azure Az PowerShell 模块与 Azure 交互。 在设置 Azure PowerShell 进行细分计费配置之前,先安装 Azure PowerShell。 要遷移到 Az PowerShell 模組,請參考 将 Azure PowerShell 从 AzureRM 迁移到 Az.

要設定 Azure PowerShell,請執行以下 cmdlets:

  1. 安装或更新所需的模块。

    注释

    -CostManagementGranularity该参数要求恢复服务保险库使用Az.RecoveryServices 7.14.1及更高版本,备份保险库则需Az.DataProtection 3.1.0及更新版本。

    Install-Module -Name Az.RecoveryServices -MinimumVersion 7.14.1 -Force
    Install-Module -Name Az.DataProtection -MinimumVersion 3.1.0 -Force
    
  2. 确认已安装的模块版本:

    Get-Module -Name Az.RecoveryServices, Az.DataProtection -ListAvailable |
        Select-Object Name, Version
    

    示例输出:

    Name                Version
    ----                -------
    Az.DataProtection   3.1.0
    Az.RecoveryServices 7.14.1
    
  3. 确认新参数是否存在于你安装的模块中:

    'New-AzRecoveryServicesVault',
    'Update-AzRecoveryServicesVault',
    'New-AzDataProtectionBackupVault',
    'Update-AzDataProtectionBackupVault' | ForEach-Object {
        $cmd = Get-Command $_ -ErrorAction SilentlyContinue
        [pscustomobject]@{
            Cmdlet       = $_
            Installed    = $null -ne $cmd
            HasParameter = ($null -ne $cmd) -and $cmd.Parameters.ContainsKey('CostManagementGranularity')
        }
    } | Format-Table -AutoSize
    

    示例输出:

    Cmdlet                             Installed HasParameter
    ------                             --------- ------------
    New-AzRecoveryServicesVault             True         True
    Update-AzRecoveryServicesVault          True         True
    New-AzDataProtectionBackupVault         True         True
    Update-AzDataProtectionBackupVault      True         True
    
  4. 通过使用Connect-AzAccount.登录您的Azure账户。 在出现的网页上,系统会提示输入帐户凭据。

  5. 由于一个帐户可以有多个订阅,因此请将要使用的订阅与帐户关联在一起:

    Select-AzSubscription -SubscriptionName $SubscriptionName
    

下表列出了本文为每种保管库类型所使用的 cmdlet。

Task 恢复服务保管库 备份保管库
创建时设置粒度 New-AzRecoveryServicesVault 使用 -CostManagementGranularity New-AzDataProtectionBackupVault 使用 -CostManagementGranularity
更改粒度 Update-AzRecoveryServicesVault 使用 -CostManagementGranularity Update-AzDataProtectionBackupVault 使用 -CostManagementGranularity
读取粒度 Get-AzRecoveryServicesVault - 读取 Properties.CostManagementSettings.GranularityLevel Get-AzDataProtectionBackupVault -
成本管理设置细分层级
应用自定义父标签 Update-AzTag Update-AzTag

使用 Azure PowerShell 配置精细的计费

选择你想要配置的保管库类型:

创建保管库时设置粒度

在 New-AzRecoveryServicesVault 上,-CostManagementGranularity 参数是可选的。 如果你在创建保险库时没有指定这个选项,默认值就是 VaultLevel。

要创建带有粒度级别的保险库,运行以下指令。 用ProtectedItemLevel中的任意值替换。

$vault = New-AzRecoveryServicesVault `
    -Name "afs-vault" `
    -ResourceGroupName "backup-rg" `
    -Location "chinanorth2" `
    -CostManagementGranularity ProtectedItemLevel

$vault.Properties.CostManagementSettings.GranularityLevel

示例输出:

ProtectedItemLevel

更改现有保管库的粒度

用于 Update-AzRecoveryServicesVault 后续更改。 该 cmdlet 与门户流程 恢复服务保管库>属性>成本管理粒度>更新 一致。

将一个保管库切换到受保护项级别

要将保险库切换到受保护项级别,请运行以下 cmdlet 命令:

$updatedVault = Update-AzRecoveryServicesVault `
    -ResourceGroupName "backup-rg" `
    -Name "afs-vault" `
    -CostManagementGranularity ProtectedItemLevel

$updatedVault.Properties.CostManagementSettings.GranularityLevel

示例输出:

ProtectedItemLevel

查看当前的粒度设置

Get-AzRecoveryServicesVault 不需要新的参数。 该设置出现在返回的vault对象中 Properties.CostManagementSettings.GranularityLevel,遵循与 CrossSubscriptionRestoreState相同的模式。

要查看当前的粒度设置,请运行以下 cmdlet:

$vault = Get-AzRecoveryServicesVault `
    -ResourceGroupName "backup-rg" `
    -Name "afs-vault"

$vault.Properties.CostManagementSettings.GranularityLevel

示例输出:

ProtectedItemLevel

要审计订阅中每个恢复服务保管库的细度设置,请运行以下 cmdlet:

Get-AzRecoveryServicesVault | ForEach-Object {
    [pscustomobject]@{
        Name              = $_.Name
        ResourceGroupName = $_.ResourceGroupName
        Location          = $_.Location
        Granularity       = $_.Properties.CostManagementSettings.GranularityLevel
    }
} | Format-Table -AutoSize

示例输出:

Name       ResourceGroupName Location Granularity
----       ----------------- -------- -----------
afs-vault  backup-rg         chinanorth2   ProtectedItemLevel
fin-vault  finance-rg        chinanorth2   VaultLevel
hr-vault   hr-rg             chinanorth2  ProtectedItemWithParentTag

配置标签级粒度

标签级细度包括以下独立职责:

  • 在保管库上应用标签:复用标准的 Az.Resources cmdlet。 该过程不需要新的备份 cmdlet 来标记。
  • 启用标签级成本分组:在保险库中将 -CostManagementGranularity 参数设置为 ProtectedItemWithParentTag。

场景一:使用默认的父标签

备份服务会自动应用 ms-resource-parent 标签,所以你只需要在保险库上启用标签级粒度。 无需手动标记。

要使用默认父标签,请遵循以下步骤:

  1. 在保管库上启用标签级别成本分组。

    Update-AzRecoveryServicesVault `
        -ResourceGroupName "backup-rg" `
        -Name "afs-vault" `
        -CostManagementGranularity ProtectedItemWithParentTag
    
  2. 确认已配置的设置。

    $vault = Get-AzRecoveryServicesVault -ResourceGroupName "backup-rg" -Name "afs-vault"
    $vault.Properties.CostManagementSettings.GranularityLevel
    

    示例输出:

    ProtectedItemWithParentTag
    

注释

默认 ms-resource-parent 标签不会作为可见标签应用于保险库或受保护资源。 Azure 备份 会把标签作为计费详情的一部分传递给 Azure 成本管理,所以你不会在保险库的标签面板里看到它。

场景二:使用自定义父标签

要按自定义父资源分组成本,首先将标签应用 cm-resource-parent 到保险库,并将其值设置为父资源的 ARM 资源 ID。 然后在保险库上启用标签级别的细粒度。

Important

使用 Update-AzTag -Operation Merge 保留保险库上的现有标签。 New-AzTag 替换资源上的所有标签,所以这里不要使用它。

使用自定义标签,请遵循以下步骤:

  1. 在 Recovery Services 保管库上应用自定义父标记。 标签键为 cm-resource-parent,标签值是父资源的 ARM 资源 ID。

    $vault  = Get-AzRecoveryServicesVault -ResourceGroupName "backup-rg" -Name "afs-vault"
    $parent = Get-AzResource -Name "financeparent" -ResourceGroupName "storage-rg"
    
    Update-AzTag -ResourceId $vault.ID `
        -Tag @{ "cm-resource-parent" = $parent.Id } `
        -Operation Merge
    

    示例输出:

    Id         : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/backup-rg/providers/Microsoft.RecoveryServices/vaults/afs-vault/providers/Microsoft.Resources/tags/default
    Name       : default
    Type       : Microsoft.Resources/tags
    Properties :
                 Name                Value
                 ==================  ==========================================================
                 cm-resource-parent  /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resour
                                     ceGroups/storage-rg/providers/Microsoft.Storage/storageAcc
                                     ounts/financeparent
    
  2. 在保管库上启用标签级别成本分组。

    Update-AzRecoveryServicesVault `
        -ResourceGroupName "backup-rg" `
        -Name "afs-vault" `
        -CostManagementGranularity ProtectedItemWithParentTag
    
  3. 确认已配置的设置。

    $vault = Get-AzRecoveryServicesVault -ResourceGroupName "backup-rg" -Name "afs-vault"
    $vault.Properties.CostManagementSettings.GranularityLevel
    

    示例输出:

    ProtectedItemWithParentTag
    

下表列出了细度级别以及你传递给 --cost-management-granularity 选项的值。

粒度级别(门户) Value Behavior
金库等级(默认) VaultLevel 保管库中的所有备份会汇总为每个保管库的一条行项目。
受保护项级别 ProtectedItemLevel 显示每个受保护物品的备份费用。
标签级别 ProtectedItemWithParentTag 它通过父标签汇总备份成本,因此你可以在资源层面查看支出。

Prerequisites

在使用Azure CLI配置细粒计费之前,请确保满足以下先决条件:

设置 Azure CLI 以进行精细的计费配置

在设置 Azure CLI 进行细分计费配置之前,先安装 Azure CLI。

要设置 Azure CLI,请执行以下命令:

  1. 请检查已安装的Azure CLI版本:

    az version
    

    示例输出:

    {
      "azure-cli": "2.65.0",
      "azure-cli-core": "2.65.0",
      "azure-cli-telemetry": "1.1.0",
      "extensions": {}
    }
    
  2. 添加 Dataprotection 扩展。 az dataprotection命令组是一个扩展,不是CLI核心的一部分,所以你必须先安装它,才能管理备份保险库。 如果你只使用恢复服务保管库,可以跳过这一步。

    az extension add --name dataprotection --upgrade
    
  3. 确认扩展程序已安装:

    az extension list --query "[].{Name:name, Version:version}" -o table
    

    示例输出:

    Name             Version
    ---------------  ---------
    dataprotection   1.5.1
    
  4. 确认你安装的 Azure CLI 版本中是否支持粒度选项。 该选项出现在命令的帮助输出中:

    az backup vault update --help
    

    示例输出:

    --cost-management-granularity
        Use this parameter to configure cost management settings for the vault.
        By default, the property is "VaultLevel" for the vault.
        Allowed values: ProtectedItemLevel, ProtectedItemWithParentTag, VaultLevel.
    
  5. 请登录到 Azure 帐户:

    az cloud set -n AzureChinaCloud
    az login
    
  6. 设置你想使用的订阅,因为一个账户可以有多个订阅:

    az account set --subscription "<subscription-name-or-id>"
    

下表列出了本文针对每种保管库类型使用的命令。

Task 恢复服务保管库 备份保管库
创建时设置粒度 az backup vault create 与 --cost-management-granularity az dataprotection backup-vault create 与 --cost-management-granularity
更改粒度 az backup vault update 与 --cost-management-granularity az dataprotection backup-vault update 与 --cost-management-granularity
读取粒度 az backup vault show az dataprotection backup-vault show
列出保管库和粒度 az backup vault list az dataprotection backup-vault list
应用自定义父标签 az tag update az tag update

使用 Azure CLI 配置精细计费

选择你想要配置的保管库类型:

创建一个带有粒度级别的保管库

要创建带有粒度级别的保险库,请执行以下命令:

az backup vault create \
    --name "afs-vault" \
    --resource-group "backup-rg" \
    --location "chinanorth2" \
    --cost-management-granularity ProtectedItemLevel \
    --query "{name:name, granularity:properties.costManagementSettings.granularityLevel}"

示例输出:

{
  "granularity": "ProtectedItemLevel",
  "name": "afs-vault"
}

更改现有保险库的粒度

要更改现有保管库的粒度,请执行以下命令:

az backup vault update \
    --name "afs-vault" \
    --resource-group "backup-rg" \
    --cost-management-granularity ProtectedItemWithParentTag \
    --query "properties.costManagementSettings.granularityLevel" -o tsv

示例输出:

ProtectedItemWithParentTag

查看当前的粒度设置

az backup vault show命令不接受新的选项。 要查看粒度级别,可以从 JSON 输出中读取 properties.costManagementSettings.granularityLevel。

要获取为保险库配置的成本管理细度级别,请执行以下命令:

az backup vault show \
    --name "afs-vault" \
    --resource-group "backup-rg" \
    --query "properties.costManagementSettings.granularityLevel" -o tsv

示例输出:

VaultLevel

要审计订阅中所有恢复服务保管库,请执行以下命令:

az backup vault list \
    --query "[].{Name:name, ResourceGroup:resourceGroup, Granularity:properties.costManagementSettings.granularityLevel}" \
    -o table

示例输出:

Name       ResourceGroup    Granularity
---------  ---------------  --------------------------
afs-vault  backup-rg        VaultLevel
fin-vault  finance-rg       ProtectedItemLevel
hr-vault   hr-rg            ProtectedItemWithParentTag

配置标签级粒度

标签级细度包括以下独立职责:

  • 在保管库上应用标签:使用标准 az tag 命令组。 标记不需要专门的备份命令。
  • 启用标签级别成本分组:在保险库中将 --cost-management-granularity 参数设置为 ProtectedItemWithParentTag。

场景一:使用默认的父标签

备份服务会自动应用标签 ms-resource-parent 。 你只需要在保管库上启用标签级别粒度,无需手动标记。

要使用默认父标签,请遵循以下步骤:

  1. 在保管库上启用标签级别成本分组。

    az backup vault update \
        --name "afs-vault" \
        --resource-group "backup-rg" \
        --cost-management-granularity ProtectedItemWithParentTag
    
  2. 确认已配置的设置。

    az backup vault show \
        --name "afs-vault" \
        --resource-group "backup-rg" \
        --query "properties.costManagementSettings.granularityLevel" -o tsv
    

    示例输出:

    ProtectedItemWithParentTag
    

注释

默认 ms-resource-parent 标签不会作为可见标签应用于保险库或受保护的资源。 Azure 备份 会将标签作为计费详情的一部分传递给 Azure 成本管理,因此该标签不会显示在 az backup vault show --query tags 中。

场景二:使用自定义父标签

要按自定义父资源分组成本,首先将标签应用 cm-resource-parent 到保险库,并将其值设置为父资源的 ARM 资源 ID。 然后在保管库上启用标签级粒度。

Important

使用 az tag update --operation Merge 保留保险库上的现有标签。 该 Replace 操作覆盖了资源上的所有标签。

使用自定义标签,请遵循以下步骤:

  1. 在保管库上应用自定义父标签。 标签键为 cm-resource-parent,标签值是父资源的 ARM 资源 ID。

    vaultId=$(az backup vault show \
        --name "afs-vault" \
        --resource-group "backup-rg" \
        --query id -o tsv)
    
    parentId=$(az storage account show \
        --name "financeparent" \
        --resource-group "storage-rg" \
        --query id -o tsv)
    
    az tag update \
        --resource-id "$vaultId" \
        --operation Merge \
        --tags "cm-resource-parent=$parentId" \
        --query "properties.tags" -o json
    

    示例输出:

    {
      "cm-resource-parent": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/storage-rg/providers/Microsoft.Storage/storageAccounts/financeparent"
    }
    
  2. 在保管库上启用标签级别成本分组。

    az backup vault update \
        --name "afs-vault" \
        --resource-group "backup-rg" \
        --cost-management-granularity ProtectedItemWithParentTag
    
  3. 确认已配置的设置。

    az backup vault show \
        --name "afs-vault" \
        --resource-group "backup-rg" \
        --query "properties.costManagementSettings.granularityLevel" -o tsv
    

    示例输出:

    ProtectedItemWithParentTag
    

在成本分析中验证备份费用

为Azure 备份配置精细计费后,请使用所选粒度验证更新的备份费用是否在成本管理中正确反映。

注释

  • 更新成本管理粒度后,新费用以所选格式显示。
  • 较旧的费用保留以前的格式。
  • 活动日志记录了成本设置的更改。
  • 更新后的更改可能需要长达 2 小时才能显示在成本分析中。

若要在成本分析中验证备份费用,请执行以下步骤:

  1. 搜索并选择 “成本分析”。

  2. 在 “成本分析 ”窗格中,选择“ 所有视图>资源 ”,并验证新的备份费用是否以所选粒度格式显示。

    以下屏幕截图中显示的价格仅供参考。

    显示成本分析中所选粒度格式的备份费用的屏幕截图。

排查精细计费问题

本部分提供故障排除步骤,以解决与Azure 备份中的精细计费相关的问题。

预期费用不会显示在 成本分析中。

若要解决该问题:

  1. 确认保险库类型是恢复服务保险库还是备份保险库。

  2. 验证是否保存了粒度设置。

  3. 检查活动日志以确认更新操作已成功完成。

  4. 等待最多 2 小时并刷新 成本分析 以查看更改。

  5. 确保在 成本分析中选择正确的订阅和时间范围范围。

估算和了解Azure 备份定价。