Skip to content

Conversation

@potatoqualitee
Copy link
Member

Fixes #9546

Only set source database offline when the copy operation succeeds. Previously, the source database would be set offline even if the restore failed due to insufficient disk space or other errors.

Changes

  • Modified the SetSourceOffline logic to check $copyDatabaseStatus.Status -eq "Successful" before setting the source database offline
  • This ensures the source database remains online if the copy/restore operation fails

🤖 Generated with Claude Code

Only set source database offline when the copy operation succeeds.
Previously, the source database would be set offline even if the
restore failed due to insufficient disk space or other errors.

Fixes #9546

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Chrissy LeMaire <[email protected]>
@potatoqualitee
Copy link
Member Author

@claude pls add an integration test

@claude
Copy link

claude bot commented Oct 28, 2025

Claude finished @potatoqualitee's task —— View job


Integration Test Added ✓

Successfully added regression tests for the SetSourceOffline fix.

Tasks Completed

  • Read the PR changes to understand the fix
  • Locate and read the integration test file
  • Design regression test for failed copy scenario
  • Implement the test following dbatools style guide
  • Commit and push changes

Implementation Details

Added a new regression test context with two test cases in tests/Copy-DbaDatabase.Tests.ps1:

  1. Test when copy fails: Creates a database that already exists on the destination, attempts to copy with -SetSourceOffline, and verifies the source database remains online when the operation fails (Status: "Skipped").

  2. Test when copy succeeds: Removes the destination database, performs a successful copy with -SetSourceOffline, and verifies the source database is set offline after a successful copy.

The test follows dbatools conventions:

  • Uses properly aligned hashtable splats
  • Uses double quotes for strings
  • Includes EnableException handling in BeforeAll/AfterAll blocks
  • Creates unique database names with Get-Random
  • Properly cleans up test resources

Changes Pushed

Commit: 74df8be

--- |

Add regression tests for issue #9546 to verify that the source database
only goes offline when the copy operation succeeds, not when it fails.

Test coverage:
- Verify source remains online when copy fails (database already exists)
- Verify source goes offline when copy succeeds

Co-authored-by: Chrissy LeMaire <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copy-DbaDatabase -SetSourceOffline sets source offline even if the copy wasn't successfull.

1 participant