Skip to content

Commit e45fa78

Browse files
Copy-DbaDatabase - Fix SetSourceOffline to only run on successful copy
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 <potatoqualitee@users.noreply.github.com>
1 parent a6b1bf6 commit e45fa78

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

public/Copy-DbaDatabase.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ function Copy-DbaDatabase {
14491449
$copyDatabaseStatus | Select-DefaultView -Property DateTime, SourceServer, DestinationServer, Name, Type, Status, Notes -TypeName MigrationObject
14501450
}
14511451

1452-
if ($SetSourceOffline -and $sourceServer.databases[$dbName].status -notlike '*offline*') {
1452+
if ($SetSourceOffline -and $copyDatabaseStatus.Status -eq "Successful" -and $sourceServer.databases[$dbName].status -notlike '*offline*') {
14531453
if ($Pscmdlet.ShouldProcess($source, "Setting $dbName offline")) {
14541454
Set-DbaDbState -SqlInstance $sourceServer -Database $dbName -Offline -Force
14551455
}

0 commit comments

Comments
 (0)