Fix Get-AzDataProtectionJob returning only first page of backup jobs#29900
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Live test skipped⏭️ Skipping the live test for this revision because no changed test file was found under a The live-test pipeline runs only the scenario/xUnit test files a PR changes, so there is nothing to execute for this commit. This is informational — a regression test is encouraged where it makes sense, but not required. If a test file is added in a later commit, the live test will run automatically. Posted by agent-assist (autonomous bug-fix pipeline). |
Live test skipped⏭️ Skipping the live test for this revision because no changed test file was found under a The live-test pipeline runs only the scenario/xUnit test files a PR changes, so there is nothing to execute for this commit. This is informational — a regression test is encouraged where it makes sense, but not required. If a test file is added in a later commit, the live test will run automatically. Posted by agent-assist (autonomous bug-fix pipeline). |
There was a problem hiding this comment.
Automated Review Summary
Status: ✅ Pass
- CI checks: 1/1 completed and passed, 0 failed, 0 pending.
- Live test (TestFx
Record): Skipped — this PR does not modify any<Service>.Test/**/*.cs|*.ps1files, so there is nothing for the live-test workflow to run against.
No outstanding failures. Flipping this PR out of draft so a human reviewer can take a look.
Posted by agent-assist (autonomous bug-fix pipeline).
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot could not run the full agentic suite for this review because it was automatically requested on a bot-authored pull request. Request a review from Copilot under Reviewers to retry with the full agentic suite. Improved support for bot-authored pull requests is coming soon.
This PR addresses Get-AzDataProtectionJob returning only the first page of jobs by adding explicit pagination handling so all backup jobs are returned for vaults with many jobs.
Changes:
- Added an entry to the DataProtection changelog describing the pagination fix and linking to the tracked issue.
- Updated
Get-AzDataProtectionJobto follownextLinkand aggregate results across pages in the list scenario. - Kept single-item retrieval behavior when
-Idor-InputObjectis provided.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/DataProtection/DataProtection/ChangeLog.md | Documents the pagination fix for Get-AzDataProtectionJob. |
| src/DataProtection/DataProtection.Autorest/custom/Cmdlets/Platform/Job/Get-AzDataProtectionJob.ps1 | Implements paging by calling ARM and iterating nextLink for list results. |
| foreach($job in $content.value){ | ||
| $psObj = [PSCustomObject]$job | ||
| $psObj.PSObject.TypeNames.Insert(0, "Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.AzureBackupJobResource") | ||
| $psObj.PSObject.TypeNames.Insert(0, "Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.AzureBackupJobResource#Multiple") | ||
| Write-Output $psObj | ||
| } |
| # List case: implement pagination by following nextLink | ||
| $subscriptionIds = if($PSBoundParameters.ContainsKey("SubscriptionId")) { $SubscriptionId } else { @((Get-AzContext).Subscription.Id) } | ||
| $apiVersion = "2026-03-01" | ||
|
|
||
| foreach($subId in $subscriptionIds){ | ||
| $url = "https://management.azure.com/subscriptions/$subId/resourceGroups/$ResourceGroupName/providers/Microsoft.DataProtection/backupVaults/$VaultName/backupJobs?api-version=$apiVersion" |
| $response = Invoke-AzRestMethod -Uri $url -Method GET | ||
| if($response.StatusCode -ne 200){ | ||
| $errorContent = $response.Content | ConvertFrom-Json | ||
| $errorMessage = if($errorContent.error) { $errorContent.error.message } else { $response.Content } | ||
| throw "Failed to list backup jobs. Status: $($response.StatusCode). Error: $errorMessage" | ||
| } |
| else{ | ||
| # List case: implement pagination by following nextLink | ||
| $subscriptionIds = if($PSBoundParameters.ContainsKey("SubscriptionId")) { $SubscriptionId } else { @((Get-AzContext).Subscription.Id) } | ||
| $apiVersion = "2026-03-01" |
| * Fixed `Get-AzDataProtectionJob` returning only the first page of backup jobs instead of all jobs when a vault has many jobs | ||
| - The cmdlet now follows pagination links to retrieve all backup jobs from the vault | ||
| - Fixed issue [#29899] |
Get-AzDataProtectionJobreturns a truncated list when a vault has many jobs (e.g. 259 of 650+). The AutoRest-generated internal cmdlet makes a single HTTP GET and discards thenextLinkin the response, so pagination never occurs.Changes
Get-AzDataProtectionJob.ps1— For theListparameter set (no-Id,-InputObject, or-UseSecondaryRegion), replaced the single internal cmdlet call with anInvoke-AzRestMethodpagination loop that followsnextLinkuntil exhausted. Handles multiple subscription IDs. InjectsAzureBackupJobResourcetype names on returned objects to preserve table formatting.-Id,-InputObject,-UseSecondaryRegion) are unchanged.ChangeLog.md— Added entry under## Upcoming Release.