Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy-DbaDatabase incorrectly reports that source and destination databases are the same when using -Force #9031

Closed
bowerandy opened this issue Jul 11, 2023 · 1 comment · Fixed by #9032

Comments

@bowerandy
Copy link

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

Type Name Status Notes


Database NQTestDaily_0003_TestDailyBower Failed Source and destination database are the same.

Steps to Reproduce

Import-Module dbatools -MinimumVersion 2.0.4
Copy-DbaDatabase  -Source . -Destination . -Database NQTestDaily_0003_TestDailyBower -NewName TestCopyDb1 -Force -BackupRestore -SharedPath "F:\MSSQL\Backup" -EnableException

Please confirm that you are running the most recent version of dbatools

2.0.4

Other details or mentions

It seems to me that the error is around line 1113 in Copy-DbaDatabase.ps1. I think $DestinationdbName should be $dbName when looking up the database on the $sourceServer.

                    } elseif ($null -ne $destServer.Databases[$DestinationdbName] -and $force) {
                        if ($sourceServer.Name -eq $destServer.Name -and $sourceServer.Databases[$DestinationdbName].Name -eq $destServer.Databases[$DestinationdbName].Name) {
                            Write-Message -Level Verbose -Message "Source and destination database are the same. Aborting routine for this database."
                            $copyDatabaseStatus.Status = "Failed"
                            $copyDatabaseStatus.Notes = "Source and destination database are the same."
                            $copyDatabaseStatus | Select-DefaultView -Property DateTime, SourceServer, DestinationServer, Name, Type, Status, Notes -TypeName MigrationObject
                            continue
                        }

What PowerShell host was used when producing this error

Windows PowerShell (powershell.exe)

PowerShell Host Version

Name Value


PSVersion 5.1.14393.5582
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.5582
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

SQL Server Edition and Build number

Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64) Sep 24 2019 13:48:23 Copyright (C) 2019 Microsoft Corporation Developer Edition (64-bit) on Windows Server 2016 Standard 10.0 (Build 14393: ) (Hypervisor)

.NET Framework Version

.NET Framework 4.7.4050.0

@bowerandy bowerandy added bugs life triage required New issue that has not been reviewed by maintainers labels Jul 11, 2023
@andreasjordan
Copy link
Contributor

Thanks for reporting this bug, will be fixed in the next release.

@andreasjordan andreasjordan removed the triage required New issue that has not been reviewed by maintainers label Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants