Skip to content

AzureBackup: PolicyCreate overhaul — schedule/retention options, builders, validators, 55 live tests#2504

Open
shrja-ms wants to merge 2 commits intomicrosoft:mainfrom
shrja-ms:user/azurebackup-policy-create-fixes
Open

AzureBackup: PolicyCreate overhaul — schedule/retention options, builders, validators, 55 live tests#2504
shrja-ms wants to merge 2 commits intomicrosoft:mainfrom
shrja-ms:user/azurebackup-policy-create-fixes

Conversation

@shrja-ms
Copy link
Copy Markdown
Contributor

Summary

Complete overhaul of azmcp azurebackup policy create with full schedule, retention, and archive tier support across all RSV and DPP workloads.

What changed

New options (25+): Schedule frequency/days/times, hourly intervals, daily/weekly/monthly/yearly retention with relative and absolute formats, archive tier mode/days, SQL Full/Differential/Log sub-policies, SAPHANA incremental/snapshot, VM Enhanced/smart-tier/instant-RP, DPP vault-tier copy, backup mode (vaulted/continuous), PITR retention, AKS scoping flags, policy tags.

PolicyCreateValidator — Pre-flight validation that converts opaque service 400s into actionable client-side messages:

  • Workload-family exclusivity (RSV-only vs DPP-only flags)
  • SQL: Full/Diff day overlap, Diff single-day-only, Log retention ≥7 days, Log < Diff retention
  • DPP: Archive tier rejected for all DPP datasources (none support ArchiveStore today)
  • AzureDisk: Yearly retention rejected (manifest allows Daily/Weekly/Monthly only)
  • Required-input combinations (weekly needs days-of-week, hourly needs all three inputs, etc.)
  • Continuous DPP workloads reject schedule/retention/archive flags

RsvPolicyBuilder — Builds RSV policies for VM, SQL/SAPHANA/SAPASE, FileShare:

  • Weekly multi-day Full + single-day Differential for SQL
  • Weekly retention days-of-week auto-aligns to schedule days when omitted
  • Monthly/yearly relative format (week-of-month) for Weekly schedules
  • Archive tier (TieringPolicy) on VM Enhanced and SQL Full sub-policies
  • Hourly Enhanced V2 with instant-RP and snapshot consistency
  • Smart-tier (TierRecommended) for VM

DppPolicyBuilder — Builds DPP policies for Disk, Blob, ADLS, AKS, PostgreSQL, CosmosDB, ElasticSAN:

  • Vault-tier copy with OS→VS lifecycle for AzureDisk
  • Vaulted mode for Blob/ADLS (VaultStore-only, no AzureBackupRule)
  • Continuous mode with PITR retention for Blob/ADLS
  • Per-datasource profiles via DppDatasourceRegistry

PolicyCreateRequest — Clean POCO decoupling command options from builder internals.

Test coverage

  • 425 unit tests (validator shape rules, builder behaviors, datasource registry)
  • 55 live tests passing, 3 skipped (private preview features: smart-tier, vaulted Blob, vaulted ADLS)
  • Started at 51 passed / 7 skipped → resolved all 4 originally-deferred tests:
    • DPP Disk vault-tier multi-tier (dropped unsupported archive/yearly per manifest)
    • SQL Full+Diff+Log (Weekly multi-day Full, single Diff, retention constraints via Kusto log analysis)
    • SQL Weekly+Archive (workload type fix, relative monthly format, log retention)
    • VM Weekly+Archive (relative monthly/yearly format, days alignment, Enhanced sub-type)

Files changed

28 files, +4663 / -210 lines across options, validators, builders, tests, docs, and changelog.

Invoking Livetests

Copilot submitted PRs are not trustworthy by default. Users with write access to the repo need to validate the contents of this PR before leaving a comment with the text /azp run mcp - pullrequest - live. This will trigger the necessary livetest workflows to complete required validation.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Overhauls azmcp azurebackup policy create to support richer schedule/retention inputs across RSV and DPP vault types by introducing request DTOs, pure policy builders, and a pre-flight validator; updates unit/live tests and documentation accordingly.

Changes:

  • Introduces PolicyCreateRequest, PolicyCreateValidator, and pure builders (RsvPolicyBuilder, DppPolicyBuilder) to generate correct policy bodies from CLI flags.
  • Refactors RSV/DPP operations + AzureBackupService to accept a single request object for policy creation.
  • Adds/updates extensive unit tests, live tests, and docs/changelog entries for the expanded flag surface.

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
tools/Azure.Mcp.Tools.AzureBackup/src/Services/RsvBackupOperations.cs Switches RSV policy creation to builder-based request DTO; applies RSV policy tags.
tools/Azure.Mcp.Tools.AzureBackup/src/Services/DppBackupOperations.cs Switches DPP policy creation to builder-based request DTO.
tools/Azure.Mcp.Tools.AzureBackup/src/Services/AzureBackupService.cs Routes policy create through new request-based operations APIs.
tools/Azure.Mcp.Tools.AzureBackup/src/Services/IAzureBackupService.cs Updates service interface signature to take PolicyCreateRequest.
tools/Azure.Mcp.Tools.AzureBackup/src/Services/IRsvBackupOperations.cs Updates operations interface signature to take PolicyCreateRequest.
tools/Azure.Mcp.Tools.AzureBackup/src/Services/IDppBackupOperations.cs Updates operations interface signature to take PolicyCreateRequest.
tools/Azure.Mcp.Tools.AzureBackup/src/Services/Policy/PolicyCreateRequest.cs Adds DTO to decouple CLI binding from builder internals.
tools/Azure.Mcp.Tools.AzureBackup/src/Services/Policy/PolicyCreateValidator.cs Adds pre-flight validation with workload-family rules and flag-shape constraints.
tools/Azure.Mcp.Tools.AzureBackup/src/Services/Policy/PolicyValidationIssue.cs Adds validation issue model.
tools/Azure.Mcp.Tools.AzureBackup/src/Services/Policy/PolicyValidationResult.cs Adds aggregate validation result model.
tools/Azure.Mcp.Tools.AzureBackup/src/Services/Policy/RsvPolicyBuilder.cs New RSV policy builder supporting schedule/retention/tiering variants.
tools/Azure.Mcp.Tools.AzureBackup/src/Services/Policy/DppPolicyBuilder.cs New DPP policy builder supporting tier rules, vault-tier copy, vaulted storage modes, etc.
tools/Azure.Mcp.Tools.AzureBackup/src/Services/DppDatasourceRegistry.cs Adjusts CosmosDB DPP profile shape (weekly full, vault-store) and related metadata.
tools/Azure.Mcp.Tools.AzureBackup/src/Options/AzureBackupOptionDefinitions.cs Expands CLI option definitions for schedule/retention/tiering and Stage 2 flags.
tools/Azure.Mcp.Tools.AzureBackup/src/Options/Policy/PolicyCreateOptions.cs Expands bound options object for new flags.
tools/Azure.Mcp.Tools.AzureBackup/src/Commands/Policy/PolicyCreateCommand.cs Registers/binds new options, validates, maps options → request DTO, calls new service API.
tools/Azure.Mcp.Tools.AzureBackup/tests/Azure.Mcp.Tools.AzureBackup.UnitTests/Services/AzureBackupServiceTests.cs Updates service tests for request-based CreatePolicyAsync signature.
tools/Azure.Mcp.Tools.AzureBackup/tests/Azure.Mcp.Tools.AzureBackup.UnitTests/Policy/PolicyCreateCommandTests.cs Updates command tests for new required flags and request DTO call shape.
tools/Azure.Mcp.Tools.AzureBackup/tests/Azure.Mcp.Tools.AzureBackup.UnitTests/Services/Policy/RsvPolicyBuilderTests.cs Adds unit tests for RSV builder behavior across workloads and shapes.
tools/Azure.Mcp.Tools.AzureBackup/tests/Azure.Mcp.Tools.AzureBackup.UnitTests/Services/Policy/DppPolicyBuilderTests.cs Adds unit tests for DPP builder behavior across workloads and shapes.
tools/Azure.Mcp.Tools.AzureBackup/tests/Azure.Mcp.Tools.AzureBackup.UnitTests/Services/Policy/PolicyCreateValidatorTests.cs Adds unit tests for validator shape/required-input rules.
tools/Azure.Mcp.Tools.AzureBackup/tests/Azure.Mcp.Tools.AzureBackup.UnitTests/Services/DppDatasourceRegistryTests.cs Adds CosmosDB-specific profile shape tests.
tools/Azure.Mcp.Tools.AzureBackup/tests/Azure.Mcp.Tools.AzureBackup.LiveTests/assets.json Updates live-test assets tag.
tools/Azure.Mcp.Tools.AzureBackup/tests/Azure.Mcp.Tools.AzureBackup.LiveTests/AzureBackupCommandTests.cs Updates/adds live tests for new policy-create shapes and validation behavior.
tools/Azure.Mcp.Tools.AzureBackup/docs/architecture.md Adds policy-create feature support matrix documentation.
servers/Azure.Mcp.Server/docs/e2eTestPrompts.md Adds new E2E prompts for expanded policy-create scenarios.
servers/Azure.Mcp.Server/docs/azmcp-commands.md Updates CLI docs for new policy-create flags and behaviors.
servers/Azure.Mcp.Server/CHANGELOG.md Adds release notes for the policy-create overhaul.
Comment thread tools/Azure.Mcp.Tools.AzureBackup/src/Options/AzureBackupOptionDefinitions.cs Outdated
Comment thread tools/Azure.Mcp.Tools.AzureBackup/src/Services/Policy/DppPolicyBuilder.cs Outdated
Comment thread servers/Azure.Mcp.Server/docs/azmcp-commands.md Outdated
Comment thread servers/Azure.Mcp.Server/docs/e2eTestPrompts.md Outdated
Comment thread tools/Azure.Mcp.Tools.AzureBackup/src/Options/AzureBackupOptionDefinitions.cs Outdated
Comment thread tools/Azure.Mcp.Tools.AzureBackup/src/Services/Policy/PolicyCreateValidator.cs Outdated
Comment thread tools/Azure.Mcp.Tools.AzureBackup/src/Services/Policy/PolicyCreateValidator.cs Outdated
Comment thread tools/Azure.Mcp.Tools.AzureBackup/docs/architecture.md Outdated
Comment thread servers/Azure.Mcp.Server/CHANGELOG.md Outdated
shrja-ms added a commit to shrja-ms/mcp that referenced this pull request Apr 27, 2026


1. ArchiveTierMode: fix description TierRecommended->CopyOnExpiry, point to --smart-tier

2. DppPolicyBuilder: normalize RSV-style schedule frequency (Daily/Weekly) to ISO-8601 (P1D/P1W)

3. DppPolicyBuilder: update no-op stub comment to reflect intentional retention

4. azmcp-commands.md: archive tiering RSV-only, not both vault types

5. e2eTestPrompts.md: Disk prompt uses supported flags only (no yearly/archive)

6. PolicyTags description: RSV only (was incorrectly DPP)

7. PolicyCreateValidator: update class doc to reflect client-side constraint enforcement

8. PolicyCreateValidator: remove contradictory DPP-only comment on --policy-tags

9. architecture.md: CosmosDB operational tier -> not supported (UsesOperationalStore=false)

10. CHANGELOG.md: archive tiering RSV-only
Copy link
Copy Markdown
Contributor

@jongio jongio left a comment

Choose a reason for hiding this comment

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

Thorough overhaul - the validator/builder/request layering is well-designed and the test suite is solid for the scope. A few items worth addressing before merge:

Silent defaults for invalid input - NormalizeDayOfWeek, NormalizeMonthOfYear, and ParseWeeksOfMonth in RsvPolicyBuilder silently default to Sunday/January/First when given unrecognized strings. If a user types --schedule-days-of-week "Foobar", they'll get a Sunday schedule with no warning. Consider validating known values in the validator (or at least logging a warning).

DPP schedule-frequency passthrough - NormalizeDppScheduleInterval normalizes "Daily" and "Weekly" but passes anything else verbatim into the repeating interval string. A typo like --schedule-frequency "BADVALUE" becomes R/.../BADVALUE and only fails at the Azure API with an opaque error. A validator rule for known DPP frequencies would give a much better error message.

Test coverage gaps - The validator has solid coverage overall, but a few rules lack dedicated unit tests: SQL Full/Diff day-overlap detection (HasDayOverlap), SQL Log retention constraints (min 7 days, must be < diff retention), archive-tier-on-DPP rejection (Rule A.8), and yearly-on-Disk rejection (Rule A.9). These are the most complex validation paths and would benefit from targeted tests.

No SAPASE builder tests - SAPASE has unique behavior (incremental allowed, SQL compression forbidden) but zero dedicated builder unit tests. The live tests don't cover SAPASE either.

Parse helpers untested - ParseScheduleTimes, ParseDaysOfWeek, ParseMonthsOfYear, ParseWeeksOfMonth, ParseDaysOfMonth have non-trivial normalization (abbreviations, comma splitting, case handling) with no dedicated tests. If the normalization logic changes, regressions won't be caught.

Comment thread tools/Azure.Mcp.Tools.AzureBackup/src/Services/Policy/DppPolicyBuilder.cs Outdated
Comment thread tools/Azure.Mcp.Tools.AzureBackup/src/Services/Policy/RsvPolicyBuilder.cs Outdated
Comment thread tools/Azure.Mcp.Tools.AzureBackup/src/Services/Policy/RsvPolicyBuilder.cs Outdated
Comment thread tools/Azure.Mcp.Tools.AzureBackup/src/Services/Policy/RsvPolicyBuilder.cs Outdated
Comment thread tools/Azure.Mcp.Tools.AzureBackup/src/Options/AzureBackupOptionDefinitions.cs Outdated
shrja-ms added a commit to shrja-ms/mcp that referenced this pull request Apr 28, 2026
- Fix DPP policy-level tags comment → RSV policy-level tags (RSV-only)
- Remove DppPolicyBuilder AppendVaultTierCopyIfRequested no-op stub and call site
- Simplify ParseDaysOfWeek switch (both arms identical → single expression)
- Fix ParseScheduleRunType: defaultDaily=false now returns Weekly (was Daily)
- Throw ArgumentException on unrecognized day/month/week values instead of
  silently defaulting to Sunday/January/First
- Add DPP schedule-frequency validation in PolicyCreateValidator (rejects
  unrecognized values like 'Monthly' or typos with actionable message)
- Add unit tests: SQL Full/Diff overlap, SQL Log retention constraints,
  archive-tier-on-DPP rejection, yearly-on-Disk rejection, DPP schedule
  frequency validation, parse helpers (ParseDaysOfWeek, ParseMonthsOfYear,
  ParseWeeksOfMonth, ParseDaysOfMonth, ParseScheduleTimes)
@shrja-ms shrja-ms requested a review from jongio April 28, 2026 11:40
Copy link
Copy Markdown
Contributor

@jongio jongio left a comment

Choose a reason for hiding this comment

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

Addresses all my previous feedback - the redundant ternary, silent day/month/week defaults, dead no-op stub, redundant switch, option comment, and DPP schedule-frequency passthrough are all fixed. The new ArgumentException throws for bad input and the IsKnownDppScheduleFrequency validator are the right approach. Test additions (+230 validator, +155 builder) fill the gaps I called out.

The BuildRsvProtectResultAsync consolidation and DPP WaitUntil.Completed change both look solid. Removing the 180s container polling loop for VM protection (in favor of the direct PUT approach that az backup uses) is a good call.

One pervasive issue: mojibake characters (—, ✅, ⚠, 🔬) appear ~45 times across 9 files. These are garbled Unicode (em dashes, checkmarks, warning signs, wrench emoji) likely from an editor encoding mismatch. They render incorrectly in IDE tooltips, --help output, and generated docs. A find/replace across the AzureBackup directory should fix all of them. Files affected: PolicyCreateValidator.cs (14), AzureBackupCommandTests.cs (12), AzureBackupOptionDefinitions.cs (6), ProtectedItemProtectCommandTests.cs (5), DppPolicyBuilder.cs (3), ProtectResult.cs (2), DppBackupOperations.cs (1), RsvPolicyBuilder.cs (1), PolicyCreateValidatorTests.cs (1).

Comment thread tools/Azure.Mcp.Tools.AzureBackup/src/Services/Policy/PolicyCreateValidator.cs Outdated
Comment thread servers/Azure.Mcp.Server/docs/azmcp-commands.md
@shrja-ms shrja-ms requested review from alzimmermsft and jongio April 28, 2026 15:46
Copy link
Copy Markdown
Contributor

@jongio jongio left a comment

Choose a reason for hiding this comment

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

Mojibake fix looks good - all ~45 garbled characters across 18 files replaced with clean ASCII. This addresses my last remaining comment.

All findings from both my previous reviews have been addressed. No new issues in the incremental diff.

Comment thread servers/Azure.Mcp.Server/CHANGELOG.md Outdated
@shrja-ms shrja-ms force-pushed the user/azurebackup-policy-create-fixes branch from 4e5b1d1 to 93d3949 Compare April 29, 2026 02:54
@shrja-ms shrja-ms requested review from anannya03 and jongio April 29, 2026 03:30
Copy link
Copy Markdown
Contributor

@jongio jongio left a comment

Choose a reason for hiding this comment

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

PR was rebased and squashed on main. Source code is clean - all prior findings remain addressed in the squashed commit. Changelog entries and e2e test prompts look good.

One remaining issue: �rchitecture.md still has 32 mojibake characters (same encoding problem as the source files that were fixed in the previous commit). The feature support matrix section has garbled UTF-8 throughout.

Comment thread tools/Azure.Mcp.Tools.AzureBackup/docs/architecture.md Outdated
@shrja-ms shrja-ms force-pushed the user/azurebackup-policy-create-fixes branch from 93d3949 to efa06da Compare April 29, 2026 03:44
Copy link
Copy Markdown
Contributor

@jongio jongio left a comment

Choose a reason for hiding this comment

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

Fifth pass (incremental). The architecture.md mojibake I flagged last round is fully cleaned up - zero garbled characters remain. All prior findings from my earlier reviews have been addressed. Nothing new to flag.

@anannya03
Copy link
Copy Markdown
Contributor

/azp run mcp - pullrequest - live

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

5 participants