Raw New Markdown
Generating updated version of doc...
Rendered New Markdown
Generating updated version of doc...
---
title: Modify VM backup policy using Azure CLI
description: Learn how to modify VM backup policy settings, including retention rules and backup schedules, using Azure CLI commands.
keywords: backup policy, Azure CLI, retention, VM backup, backup schedule, modify policy
ms.topic: how-to
ms.custom: devx-track-azurecli
ms.date: 06/26/2026
author: AbhishekMallick-MS
ms.author: v-mallicka
# Customer intent: As a system administrator, I want to update the VM backup policy using CLI commands, so that I can modify retention settings and ensure my virtual machines are backed up according to the latest requirements.
---
# Modify VM backup policy by using Azure CLI
This article describes how to modify an existing VM backup policy by using Azure CLI to adjust retention rules, backup schedules, and other policy settings. To modify the policy, export the policy to a JSON file, make the required updates in the file, and then use Azure CLI to apply the changes. You can also [modify the policy by using the Azure portal](backup-azure-manage-vms.md#modify-backup-policy).
## Modify an existing policy
To modify an existing VM backup policy, follow these steps:
1. Execute the [az backup policy show](/cli/azure/backup/policy#az-backup-policy-show) command to retrieve the details of policy you want to update.
Example:
```azurecli
az backup policy show --name testing123 --resource-group rg1234 --vault-name testvault
```
The example above shows the details for a VM policy with the name *testing123*.
Output:
```json
{
"eTag": null,
"id": "/Subscriptions/efgsf-123-test-subscription/resourceGroups/rg1234/providers/Microsoft.RecoveryServices/vaults/testvault/backupPolicies/testing123",
"location": null,
"name": "testing123",
"properties": {
"backupManagementType": "AzureIaasVM",
"instantRpDetails": {
"azureBackupRgNamePrefix": null,
"azureBackupRgNameSuffix": null
},
"instantRpRetentionRangeInDays": 2,
"protectedItemsCount": 0,
"retentionPolicy": {
"dailySchedule": {
"retentionDuration": {
"count": 180,
"durationType": "Days"
},
"retentionTimes": [
"2020-08-03T04:30:00+00:00"
]
},
"monthlySchedule": null,
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": [
"Sunday"
],
"retentionDuration": {
"count": 30,
"durationType": "Weeks"
},
"retentionTimes": [
"2020-08-03T04:30:00+00:00"
]
},
"yearlySchedule": null
},
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunDays": null,
"scheduleRunFrequency": "Daily",
"scheduleRunTimes": [
"2020-08-03T04:30:00+00:00"
],
"scheduleWeeklyFrequency": 0
},
"timeZone": "UTC"
},
"resourceGroup": "azurefiles",
"tags": null,
"type": "Microsoft.RecoveryServices/vaults/backupPolicies"
}
```
1. Save the above output in a .json file. For example, let's save it as *Policy.json*.
1. Update the JSON file based on your requirements and save the changes.
Example:
To update the weekly retention to 60 days, update the following section of the JSON file by changing the count to 60.
```json
"retentionDuration": {
"count": 60,
"durationType": "Weeks"
}
```
1. Save the changes.
1. Execute the [az backup policy set](/cli/azure/backup/policy#az-backup-policy-set) command and pass the complete path of the updated JSON file as the value for the **- - policy** parameter.
```azurecli
az backup policy set --resource-group rg1234 --vault-name testvault --policy C:\temp2\Policy.json --name testing123
```
>[!NOTE]
>You can also retrieve the sample JSON policy by executing the [az backup policy get-default-for-vm](/cli/azure/backup/policy#az-backup-policy-get-default-for-vm) command.
## Next steps
- [Manage Azure VM backups with the Azure Backup service](backup-azure-manage-vms.md)