dataplat / dbatools

🚀 SQL Server automation and instance migrations have never been safer, faster or freer
https://dbatools.io
MIT License
2.44k stars 794 forks source link

[Bug] Start-DbaMigration with -BackupRestore -SetSourceReadOnly tries to update database owner while restored DB is still READ_ONLY #5370

Closed VladDBA closed 5 years ago

VladDBA commented 5 years ago

NOTE: Copy-DbaDatabase will not work in every environment and every situation. Instead, we try to ensure Backup & Restore work in your environment.

Environmental data

<# 
Name                           Value
----                           -----
PSVersion                      5.1.14393.2608
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.2608
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

### dbatools Module version:

Name    : dbatools
Path    : C:\Program Files\WindowsPowerShell\Modules\dbatools\0.9.803\dbatools.psd1
Version : 0.9.803

Name    : dbatools
Path    : C:\Program Files\WindowsPowerShell\Modules\dbatools\0.9.800\dbatools.psd1
Version : 0.9.800

Name    : dbatools
Path    : C:\Program Files\WindowsPowerShell\Modules\dbatools\0.9.797\dbatools.psd1
Version : 0.9.797
#>

SQL Server:

/* Microsoft SQL Server 2016 (SP2-CU2) (KB4340355) - 13.0.5153.0 (X64)   Jun 28 2018 17:24:28   Copyright (c) Microsoft Corporation  Standard Edition (64-bit) on Windows Server 2016 Standard 10.0 <X64> (Build 14393: ) (Hypervisor) */

Steps to Reproduce

<#
Start-DbaMigration -Verbose -Source SourceHost\SourceInstance -Destination DestHost\DestInstance -BackupRestore -SharedPath \\DestHost\BackupShare -Exclude DatabaseMail, LinkedServers, CentralManagementServer, SystemTriggers, BackupDevices, Audits, CustomErrors, ServerAuditSpecifications, ResourceGovernor -SetSourceReadOnly
#>

Expected Behavior

once the restore is done the database should be set to READ_WRITE and then the ownership should be updated

Actual Behavior

VERBOSE: [04:20:44][Set-DbaDbOwner] Setting database owner for MyDB to OwnerName on DestHost\DestInstance. WARNING: [04:20:44][Set-DbaDbOwner] MyDB on DestHost\DestInstance is not in an updateable state and can not be altered. It will be skipped. VERBOSE: [04:20:44][Copy-DbaDatabase] Failed to update database owner. VERBOSE: [04:20:44][Set-DbaDbState] Setting database [MyDB ] to READ_WRITE

potatoqualitee commented 5 years ago

Thank you for your report. We'll take a look when we get a moment.

potatoqualitee commented 5 years ago

this has been fixed in the prerelease branch and will be available when we go 1.0 on June 20 👍