[backup] AFS soft delete: implement undelete for Azure File Share + --is-deleted filter on backup item list#33392
Conversation
* 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>
|
Validation for Azure CLI Full Test Starting...
Thanks for your contribution! |
|
Hi @bharatpurwar, |
|
Validation for Breaking Change Starting...
Thanks for your contribution! |
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
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). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
There was a problem hiding this comment.
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
AzureStoragedispatch forbackup protection undelete, implemented via newcustom_afs.undelete_protectionusingis_rehydrate=True. - Add
--is-deletedtobackup item list, threading the flag throughcustom_baseintocustom_common.list_itemsfor 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.
|
@bharatpurwar please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
Related command
az backup protection undelete,az backup item listDescription
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.az backup protection undelete --backup-management-type AzureStorage --workload-type AzureFileShare ...Nonesilently — only theAzureIaasVMandAzureWorkloadbranches were wired incustom_base.undelete_protectioncustom_afs.undelete_protectionwhich issues PUT withis_rehydrate=True,protection_state=ProtectionStopped,policy_id="",source_resource_idfrom the itemaz backup item list--is-deletedswitch (client-side filter onproperties.is_scheduled_for_deferred_delete) — works for every backup-management-type that supports soft deleteThe protected-items LIST endpoint does not expose
isDeletedas an OData predicate, so the filter is applied client-side after pagination. This matches the equivalent PowerShell-DeleteState SoftDeletedbehavior shipping in parallel at Azure/azure-powershell#29622.Files
azure/cli/command_modules/backup/custom_afs.py— newundelete_protectionazure/cli/command_modules/backup/custom_base.py—AzureStoragebranch inundelete_protection; threadis_deletedthroughlist_itemsazure/cli/command_modules/backup/custom_common.py—is_deletedclient-side filter inlist_itemsazure/cli/command_modules/backup/_params.py— register--is-deletedonbackup item listazure/cli/command_modules/backup/_help.py— examples forbackup protection undelete(AFS) andbackup item list --is-deletedazure/cli/command_modules/backup/tests/latest/test_afs_commands.py—test_afs_backup_softdeletesrc/azure-cli/HISTORY.rstTesting
python -c "import ast; ast.parse(open(p).read())"clean for every modified.py.test_afs_backup_softdeletemirrorstest_backup_softdelete(intest_backup_commands.py) for IaaS VM. Covers the full lifecycle: disable with--delete-backup-data→ assertisScheduledForDeferredDelete=Truevia bothbackup item showand the new--is-deletedfilter → undelete → assertisScheduledForDeferredDelete=None. Marked@live_onlybecause the service state transitions can't be recorded.HISTORY.rst entry
Backward compatibility
--is-deletedis a new optional flag; default behavior ofaz backup item listis unchanged.az backup protection undeletefor--backup-management-type AzureStoragepreviously silently returnedNone; it now succeeds. No existing caller was relying on the no-op.