Skip to content

feat(ENG-758673): add DbRestoreOverwritePolicy to Restore-CohesityMSSQLObject - #262

Merged
deepak-patel-cohesity merged 1 commit into
masterfrom
ENG-758673
Sep 2, 2026
Merged

feat(ENG-758673): add DbRestoreOverwritePolicy to Restore-CohesityMSSQLObject#262
deepak-patel-cohesity merged 1 commit into
masterfrom
ENG-758673

Conversation

@deepayan-bose-cohesity

@deepayan-bose-cohesity deepayan-bose-cohesity commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a -DbRestoreOverwritePolicy switch parameter to Restore-CohesityMSSQLObject, bringing it to parity with Restore-CohesityRemoteMSSQLObject.

The cmdlet now always sets sqlRestoreParameters.overwritePolicy on the POST /public/restore/applicationsRecover request:

Switch state overwritePolicy sent
-DbRestoreOverwritePolicy specified kOverwrite
Switch omitted (default) kFailIfExists

Background

Restore-CohesityRemoteMSSQLObject already exposes -DbRestoreOverwritePolicy for inactive-job restores via the legacy Iris API. The local Restore-CohesityMSSQLObject cmdlet (C# implementation using the public restore API) had no equivalent option, so users could not request overwrite behavior when restoring SQL objects through the standard cmdlet.

The SqlRestoreParameters model already includes an overwritePolicy field with kOverwrite and kFailIfExists enum values — no model or API contract changes were required.

Changes

  • RestoreCohesityMSSQLObject.cs
    • Added optional -DbRestoreOverwritePolicy switch parameter with cmdlet help text
    • Always sets SqlRestoreParameters.OverwritePolicy before submitting the restore task:
      • KOverwrite when the switch is present
      • KFailIfExists when the switch is omitted (explicit default, documented in help text)

Backward compatibility

Restore semantics are unchanged: without the switch, restore continues to fail if the database already exists at the target. The amendment makes this explicit in the request payload by always sending overwritePolicy (kFailIfExists by default) rather than omitting the field.

Test plan

  • Restore a SQL database to a target where the database already exists without -DbRestoreOverwritePolicy — verify fail-if-exists behavior; confirm request payload contains "overwritePolicy": "kFailIfExists"
  • Restore the same scenario with -DbRestoreOverwritePolicy — verify restore succeeds and overwrites the existing database; confirm payload contains "overwritePolicy": "kOverwrite"
  • Compare request payload with Restore-CohesityRemoteMSSQLObject -DbRestoreOverwritePolicy to confirm both set overwritePolicy: kOverwrite when overwrite is requested
  • Run Get-Help Restore-CohesityMSSQLObject -Parameter DbRestoreOverwritePolicy to verify help text documents the kFailIfExists default

Related

@deepayan-bose-cohesity deepayan-bose-cohesity added enhancement New feature or request good first issue Good for newcomers labels Aug 27, 2026
@deepayan-bose-cohesity deepayan-bose-cohesity changed the title feat: add DbRestoreOverwritePolicy to Restore-CohesityMSSQLObject feat(ENG-758673): add DbRestoreOverwritePolicy to Restore-CohesityMSSQLObject Aug 27, 2026
…QLObject

Expose overwrite-existing-database support on the local MSSQL restore cmdlet
for parity with Restore-CohesityRemoteMSSQLObject (RFPE-2273 / Rijkswaterstaat).

When -DbRestoreOverwritePolicy is specified, the cmdlet sets
sqlRestoreParameters.overwritePolicy to kOverwrite on the existing
ApplicationsRestoreTaskRequest payload sent to POST
/public/restore/applicationsRecover. No model or API changes required;
SqlRestoreParameters.OverwritePolicy was already defined but unused.

Backward compatible: default behavior unchanged (fail if DB exists).

Co-authored-by: Cursor <cursoragent@cursor.com>
@deepayan-bose-cohesity

Copy link
Copy Markdown
Contributor Author

Amendment (post-review update)

The implementation was refined after initial review:

Before: overwritePolicy was only set when -DbRestoreOverwritePolicy was specified; the field was omitted from the request otherwise.

After: overwritePolicy is always set on every restore request:

applicationRestoreObject.SqlRestoreParameters.OverwritePolicy = DbRestoreOverwritePolicy.IsPresent
    ? Model.SqlRestoreParameters.OverwritePolicyEnum.KOverwrite
    : Model.SqlRestoreParameters.OverwritePolicyEnum.KFailIfExists;
  • Switch present"overwritePolicy": "kOverwrite"
  • Switch omitted"overwritePolicy": "kFailIfExists" (explicit default)

Cmdlet help text was also updated to document that the default is kFailIfExists when the switch is not specified.

Behavior impact: Restore semantics are unchanged — fail-if-exists without the switch, overwrite with it. The difference is that the default policy is now explicitly sent in the JSON payload rather than relying on Iris server-side defaults.

@deepak-patel-cohesity
deepak-patel-cohesity merged commit 9dc2d13 into master Sep 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants