Skip to content

[backup] AFS soft delete: implement undelete for Azure File Share + --is-deleted filter on backup item list - #33392

Draft
bharatpurwar wants to merge 3 commits into
Azure:devfrom
bharatpurwar:users/bharatpurwar/afs-soft-delete
Draft

[backup] AFS soft delete: implement undelete for Azure File Share + --is-deleted filter on backup item list#33392
bharatpurwar wants to merge 3 commits into
Azure:devfrom
bharatpurwar:users/bharatpurwar/afs-soft-delete

Conversation

@bharatpurwar

Copy link
Copy Markdown
Member

Related command

az backup protection undelete, az backup item list

Description

Adds end-user soft-delete support for Azure File Share (AFS) backup items in az backup, bringing the CLI surface for AFS in line with what IaaS VM already exposes.

Command Before After
az backup protection undelete --backup-management-type AzureStorage --workload-type AzureFileShare ... Returned None silently — only the AzureIaasVM and AzureWorkload branches were wired in custom_base.undelete_protection Dispatches to a new custom_afs.undelete_protection which issues PUT with is_rehydrate=True, protection_state=ProtectionStopped, policy_id="", source_resource_id from the item
az backup item list No filter for soft-deleted items Adds --is-deleted switch (client-side filter on properties.is_scheduled_for_deferred_delete) — works for every backup-management-type that supports soft delete

The protected-items LIST endpoint does not expose isDeleted as an OData predicate, so the filter is applied client-side after pagination. This matches the equivalent PowerShell -DeleteState SoftDeleted behavior shipping in parallel at Azure/azure-powershell#29622.

Files

  • azure/cli/command_modules/backup/custom_afs.py — new undelete_protection
  • azure/cli/command_modules/backup/custom_base.pyAzureStorage branch in undelete_protection; thread is_deleted through list_items
  • azure/cli/command_modules/backup/custom_common.pyis_deleted client-side filter in list_items
  • azure/cli/command_modules/backup/_params.py — register --is-deleted on backup item list
  • azure/cli/command_modules/backup/_help.py — examples for backup protection undelete (AFS) and backup item list --is-deleted
  • azure/cli/command_modules/backup/tests/latest/test_afs_commands.pytest_afs_backup_softdelete
  • src/azure-cli/HISTORY.rst

Testing

  • python -c "import ast; ast.parse(open(p).read())" clean for every modified .py.
  • New scenario test test_afs_backup_softdelete mirrors test_backup_softdelete (in test_backup_commands.py) for IaaS VM. Covers the full lifecycle: disable with --delete-backup-data → assert isScheduledForDeferredDelete=True via both backup item show and the new --is-deleted filter → undelete → assert isScheduledForDeferredDelete=None. Marked @live_only because the service state transitions can't be recorded.

HISTORY.rst entry

**Backup**

* `az backup protection undelete`: Add support for rehydrating soft-deleted Azure File Share backup items
* `az backup item list`: Add `--is-deleted` flag to return only soft-deleted backup items in the vault

Backward compatibility

  • --is-deleted is a new optional flag; default behavior of az backup item list is unchanged.
  • az backup protection undelete for --backup-management-type AzureStorage previously silently returned None; it now succeeds. No existing caller was relying on the no-op.

Bharat Purwar and others added 3 commits May 18, 2026 13:27
* custom_afs.py: add `undelete_protection` mirroring the IaaS VM
  flow but built from `AzureFileshareProtectedItem` (policy_id="",
  protection_state=ProtectionStopped, source_resource_id from item,
  is_rehydrate=True). Issues PUT to the protected-item endpoint via
  `client.create_or_update` and tracks the resulting backup job.

* custom_base.py (undelete_protection dispatcher): add `azurestorage`
  branch that calls `custom_afs.undelete_protection`. Sits between the
  existing `azureiaasvm` (VM) and `azureworkload` (SAP HANA/SQL)
  branches so `az backup protection undelete --backup-management-type
  AzureStorage --workload-type AzureFileShare ...` now succeeds for
  soft-deleted Azure File Shares.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Customers can now scope `az backup item list` to soft-deleted
backup items only, mirroring the PowerShell -DeleteState
SoftDeleted parameter on Get-AzRecoveryServicesBackupItem.

* _params.py (backup item list): register `--is-deleted` switch.

* custom_base.list_items / custom_common.list_items: thread the
  `is_deleted` boolean through and apply a client-side filter on
  `properties.is_scheduled_for_deferred_delete` after the LIST call.
  Client-side is required because the protectedItems LIST endpoint
  does not expose `isDeleted` as an OData predicate; the service
  already returns soft-deleted items in the default response.

Works for every backup-management-type that supports soft delete
(AzureIaasVM, AzureStorage / AzureFileShare, AzureWorkload).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* tests/latest/test_afs_commands.py: add `test_afs_backup_softdelete`
  modelled on the IaaS VM equivalent (test_backup_softdelete in
  test_backup_commands.py). Covers the full soft-delete lifecycle:
  disable with delete-backup-data -> verify ProtectionStopped +
  isScheduledForDeferredDelete=True via `backup item show` and the
  new `backup item list --is-deleted` filter -> undelete -> verify
  rehydrated (isScheduledForDeferredDelete=None). Marked @live_only
  because soft-delete state transitions require a live AFS vault.

* _help.py: add AFS example to `backup protection undelete` and an
  --is-deleted example to `backup item list`.

* HISTORY.rst: under 2.86.0 add a Backup subsection (between Cloud
  and Compute) noting the AFS undelete support and `--is-deleted`
  flag.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 18, 2026 11:16
@azure-client-tools-bot-prd

azure-client-tools-bot-prd Bot commented May 18, 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

Copy link
Copy Markdown

Hi @bharatpurwar,
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

@azure-client-tools-bot-prd

azure-client-tools-bot-prd Bot commented May 18, 2026

Copy link
Copy Markdown
⚠️AzureCLI-BreakingChangeTest
⚠️backup
rule cmd_name rule_message suggest_message
⚠️ 1006 - ParaAdd backup item list cmd backup item list added parameter is_deleted

@yonzhan

yonzhan commented May 18, 2026

Copy link
Copy Markdown
Collaborator

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions

Copy link
Copy Markdown

The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR.

Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

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

Adds Azure File Share (AFS) soft-delete rehydration support to az backup protection undelete and introduces an --is-deleted switch on az backup item list to surface only soft-deleted items (client-side filtered via properties.isScheduledForDeferredDelete).

Changes:

  • Add AzureStorage dispatch for backup protection undelete, implemented via new custom_afs.undelete_protection using is_rehydrate=True.
  • Add --is-deleted to backup item list, threading the flag through custom_base into custom_common.list_items for client-side filtering.
  • Add a new live-only scenario test covering the AFS soft-delete lifecycle and update help/HISTORY entries.

Reviewed changes

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

Show a summary per file
File Description
src/azure-cli/HISTORY.rst Documents the new undelete support for AFS and the new --is-deleted flag.
src/azure-cli/azure/cli/command_modules/backup/tests/latest/test_afs_commands.py Adds a live-only scenario test validating AFS soft-delete → list filter → undelete behavior.
src/azure-cli/azure/cli/command_modules/backup/custom_common.py Implements the --is-deleted client-side filter in list_items.
src/azure-cli/azure/cli/command_modules/backup/custom_base.py Threads is_deleted through list_items and dispatches undelete for AzureStorage to custom_afs.
src/azure-cli/azure/cli/command_modules/backup/custom_afs.py Adds undelete_protection implementation for AFS rehydration (is_rehydrate=True).
src/azure-cli/azure/cli/command_modules/backup/_params.py Registers the --is-deleted argument for backup item list.
src/azure-cli/azure/cli/command_modules/backup/_help.py Adds examples for backup item list --is-deleted and AFS backup protection undelete.

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

@yanzhudd

Copy link
Copy Markdown
Contributor

/azp run

@yanzhudd

Copy link
Copy Markdown
Contributor

Please note that the code completion time for the upcoming release train is on 06/30/2026 at 02:00 UTC. If you want it to be released in this sprint, please get it ready asap and ping me in Teams directly.

@azure-pipelines

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

@bharatpurwar
bharatpurwar marked this pull request as draft July 27, 2026 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants