Skip to content

{Backup} az backup: Add Cross Subscription Backup (CSB) support for AzureIaaSVM#33703

Open
Prabhkiratnitp wants to merge 5 commits into
Azure:devfrom
Prabhkiratnitp:users/singhprab/csb-cli
Open

{Backup} az backup: Add Cross Subscription Backup (CSB) support for AzureIaaSVM#33703
Prabhkiratnitp wants to merge 5 commits into
Azure:devfrom
Prabhkiratnitp:users/singhprab/csb-cli

Conversation

@Prabhkiratnitp

@Prabhkiratnitp Prabhkiratnitp commented Jul 6, 2026

Copy link
Copy Markdown

Related command

 az backup protection enable-for-vm ,  az backup restore restore-disks ,  az backup item list ,  az backup item show ,  az backup job show 

Description

This PR adds Cross Subscription Backup (CSB) support for Azure VMs, allowing a VM to be protected by a Recovery Services vault in a different subscription.

•  enable-for-vm : accepts a full VM ARM ID whose subscription differs from the vault's. Since discovery ( RefreshContainers / ListProtectableItems ) only runs in the vault's subscription and cannot see a cross-subscription VM, we skip discovery and construct the container URI, protected-item URI, and  sourceResourceId  directly from the ARM ID. Before calling the backend we validate the VM exists and is in the vault's region (fail-fast on a wrong ID or region mismatch). The backend derives the VM's subscription from  sourceResourceId .
•  restore-disks : supports Original Location Recovery (OLR) for CSB items — the container subscription is derived from the recovery point / item  sourceResourceId , so no  --target-subscription  is needed, and the staging storage account is resolved in the VM's subscription. Native container/item names are used because friendly-name resolution is unreliable for cross-subscription containers. Also, a friendly container name that matches multiple containers now fails with a clear error instead of crashing.
•  item list / item show  and  job show : surface a new  containerSubscriptionId  field on the Azure VM backup item and job responses, so users can see the VM's subscription for CSB items/jobs.

Includes help examples, history notes, and self-contained  @live_only  integration tests covering enable → on-demand backup → OLR restore →  containerSubscriptionId  assertions → disable.

Testing Guide

Enable backup for a VM in a different subscription than the vault (CSB):

az backup protection enable-for-vm
--resource-group myVaultRg --vault-name myVault
--policy-name DefaultPolicy
--vm "/subscriptions//resourceGroups//providers/Microsoft.Compute/virtualMachines/"

Confirm the item/job carry the VM's subscription:

az backup item show -g myVaultRg -v myVault -c -n
--backup-management-type AzureIaasVM --workload-type VM
--query properties.containerSubscriptionId

OLR restore of a CSB item (native names; subscription derived from the recovery point):

az backup restore restore-disks
--resource-group myVaultRg --vault-name myVault
--container-name "IaasVMContainer;iaasvmcontainerv2;;"
--item-name "VM;iaasvmcontainerv2;;"
--rp-name --restore-mode OriginalLocation
--storage-account --storage-account-resource-group

Automated tests ( @live_only , run live because playback sanitizes subscription IDs and collapses the "VM sub ≠ vault sub" distinction):

azdev test test_backup_csb_enable_for_vm test_backup_csb_restore_olr --live

Both pass live; both correctly skip in playback/CI.

History Notes

[Backup] az backup protection enable-for-vm: Support Cross Subscription Backup by accepting the complete ARM ID of a VM residing in a different subscription than the vault via --vm
[Backup] az backup restore restore-disks: Support Original Location Recovery (OLR) for Cross Subscription Backup protected items; the container subscription is derived from the recovery point, no additional input required
[Backup] az backup restore restore-disks: Fail with a clear error instead of crashing when a friendly container name matches multiple containers in the vault; pass the native container name instead
[Backup] az backup item list/show: Add containerSubscriptionId to the Azure VM backup item response
[Backup] az backup job show: Add containerSubscriptionId to the Azure VM backup job response


This checklist is used to make sure that common guidelines for a pull request are followed.

…zure VM

- az backup protection enable-for-vm: accept a full VM ARM id in a different subscription than the
  vault (CSB); skip discovery and construct the container/protected-item URIs and sourceResourceId
  directly, after validating the VM exists and is in the vault's region
- az backup restore restore-disks: support OLR for CSB protected items by deriving the container
  subscription from the item sourceResourceId; fail with a clear error when a friendly container name
  matches multiple containers
- az backup item list/show: add containerSubscriptionId to the Azure VM backup item response
- az backup job show: add containerSubscriptionId to the Azure VM backup job response
- Add tests, recording, help examples and history notes

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Prabhkiratnitp Prabhkiratnitp requested a review from a team as a code owner July 6, 2026 13:00
Copilot AI review requested due to automatic review settings July 6, 2026 13:00
@Prabhkiratnitp Prabhkiratnitp requested review from a team as code owners July 6, 2026 13:00
@azure-client-tools-bot-prd

azure-client-tools-bot-prd Bot commented Jul 6, 2026

Copy link
Copy Markdown
️✔️AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.14
️✔️acs
️✔️latest
️✔️3.12
️✔️3.14
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.14
️✔️ams
️✔️latest
️✔️3.12
️✔️3.14
️✔️apim
️✔️latest
️✔️3.12
️✔️3.14
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.14
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.14
️✔️aro
️✔️latest
️✔️3.12
️✔️3.14
️✔️backup
️✔️latest
️✔️3.12
️✔️3.14
️✔️batch
️✔️latest
️✔️3.12
️✔️3.14
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.14
️✔️billing
️✔️latest
️✔️3.12
️✔️3.14
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.14
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.14
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.14
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.14
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.14
️✔️config
️✔️latest
️✔️3.12
️✔️3.14
️✔️configure
️✔️latest
️✔️3.12
️✔️3.14
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.14
️✔️container
️✔️latest
️✔️3.12
️✔️3.14
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.14
️✔️core
️✔️latest
️✔️3.12
️✔️3.14
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.14
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.14
️✔️dls
️✔️latest
️✔️3.12
️✔️3.14
️✔️dms
️✔️latest
️✔️3.12
️✔️3.14
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.14
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.14
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.14
️✔️find
️✔️latest
️✔️3.12
️✔️3.14
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.14
️✔️identity
️✔️latest
️✔️3.12
️✔️3.14
️✔️iot
️✔️latest
️✔️3.12
️✔️3.14
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.14
️✔️lab
️✔️latest
️✔️3.12
️✔️3.14
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.14
️✔️maps
️✔️latest
️✔️3.12
️✔️3.14
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.14
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.14
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.14
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.14
️✔️network
️✔️latest
️✔️3.12
️✔️3.14
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.14
️✔️postgresql
️✔️latest
️✔️3.12
️✔️3.14
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.14
️✔️profile
️✔️latest
️✔️3.12
️✔️3.14
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.14
️✔️redis
️✔️latest
️✔️3.12
️✔️3.14
️✔️relay
️✔️latest
️✔️3.12
️✔️3.14
️✔️resource
️✔️latest
️✔️3.12
️✔️3.14
️✔️role
️✔️latest
️✔️3.12
️✔️3.14
️✔️search
️✔️latest
️✔️3.12
️✔️3.14
️✔️security
️✔️latest
️✔️3.12
️✔️3.14
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.14
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.14
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.14
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.14
️✔️sql
️✔️latest
️✔️3.12
️✔️3.14
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.14
️✔️storage
️✔️latest
️✔️3.12
️✔️3.14
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.14
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.14
️✔️util
️✔️latest
️✔️3.12
️✔️3.14
️✔️vm
️✔️latest
️✔️3.12
️✔️3.14

@azure-client-tools-bot-prd

azure-client-tools-bot-prd Bot commented Jul 6, 2026

Copy link
Copy Markdown
️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the az backup command module to support Cross Subscription Backup (CSB) scenarios for Azure VM protection and restore, and surfaces the protected VM’s subscription on item/job responses to help customers operate across vault/VM subscription boundaries.

Changes:

  • Enable az backup protection enable-for-vm to accept a full cross-subscription VM ARM ID and bypass protectable-item discovery by constructing container/item URIs directly.
  • Improve restore flows for CSB, including Original Location Recovery behavior and clearer failures when friendly names are ambiguous.
  • Add containerSubscriptionId to Azure VM backup item and job outputs, plus tests/recordings/help/history notes.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/azure-cli/HISTORY.rst Adds history notes documenting new CSB behavior and response fields.
src/azure-cli/azure/cli/command_modules/backup/tests/latest/test_backup_commands.py Adds validation for containerSubscriptionId on Azure VM backup items and introduces a playback-only ambiguity regression test.
src/azure-cli/azure/cli/command_modules/backup/tests/latest/recordings/test_backup_restore_multiple_containers_same_friendly_name.yaml Recording supporting the new ambiguity regression scenario.
src/azure-cli/azure/cli/command_modules/backup/custom.py Implements CSB enable-for-vm path, ambiguity validation, OLR subscription derivation, and job response augmentation.
src/azure-cli/azure/cli/command_modules/backup/custom_help.py Adds helpers to surface containerSubscriptionId for items/jobs.
src/azure-cli/azure/cli/command_modules/backup/custom_common.py Ensures item list/show consistently set containerSubscriptionId.
src/azure-cli/azure/cli/command_modules/backup/_help.py Adds help examples/long-summary guidance for CSB/native names.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/azure-cli/azure/cli/command_modules/backup/custom.py
Comment thread src/azure-cli/azure/cli/command_modules/backup/custom.py
@yonzhan

yonzhan commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Backup

@yonzhan yonzhan requested a review from yanzhudd July 6, 2026 23:13
Prabhkirat Singh and others added 3 commits July 13, 2026 23:59
…e job-subscription check

Rework the Cross Subscription Backup (CSB) live-only tests so they are fully self-contained via VaultPreparer, and fold the job containerSubscriptionId validation into the restore test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…Id parsing

Add unit tests for set_job_container_subscription_id covering the 'VM Subscription ID' property-bag key name and parsing, so the containerSubscriptionId field on 'az backup job show' is guarded in CI without a live cross-subscription setup.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@zubairabid zubairabid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor change to be made, looks good otherwise.

Comment thread src/azure-cli/HISTORY.rst Outdated
…release process)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: fe45641d-3d74-4e8e-882f-6d2cebb8839a
@Prabhkiratnitp Prabhkiratnitp force-pushed the users/singhprab/csb-cli branch from 8b555ad to 07c4aef Compare July 14, 2026 07:20
@Prabhkiratnitp Prabhkiratnitp marked this pull request as ready for review July 14, 2026 07:21
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@yanzhudd yanzhudd changed the title [Backup] az backup: Add Cross Subscription Backup (CSB) support for A… {Backup} az backup: Add Cross Subscription Backup (CSB) support for A… Jul 15, 2026
@yanzhudd

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@Prabhkiratnitp Prabhkiratnitp changed the title {Backup} az backup: Add Cross Subscription Backup (CSB) support for A… {Backup} az backup: Add Cross Subscription Backup (CSB) support for AzureIaaSVM Jul 15, 2026
@Prabhkiratnitp

Copy link
Copy Markdown
Author

@Prabhkiratnitp please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree company="Microsoft"

@yanzhudd

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants