dbatools icon indicating copy to clipboard operation
dbatools copied to clipboard

Copy-DbaDatabase fails when destination is a mountpoint

Open AGregersen opened this issue 6 years ago • 1 comments

On version 1.0.123

The destination server have the same folder structure as the source, but one of the destination folders is a drive mapped to a path (which we use on all our SQL Servers instead of drive letters)

Copy-DbaDatabase -Source sqlmigratesql2.agr.bah -Destination sqlmigratesql4.agr.bah -DestinationSqlCredential $sacred -AllDatabases -DetachAttach -ReuseSourceFolderStructure -Reattach

First a warning is displayed: WARNING: [08:58:26][Mount-SqlDatabase] Issue mounting database. | Unable to open the physical file "c:\mssql\crmdata\agrtmp_Primary.mdf". Operating system error 2: "2(The system cannot find the file specified.)". CREATE DATABASE failed. Some file names listed could not be created. Check related errors. Type Name Status Notes


Database xxxxxxxbooking Skipped Already exists on destination Database (DetachAttach) agrtmp Failed Failed to attach database to destination And when trying to do that database the following error occurs: Start-BitsTransfer : The destination volume has changed. If the disk is removable, it might have been replaced with a d ifferent disk. Reinsert the original disk and resume the job. At C:\Program Files\WindowsPowerShell\Modules\dbatools\1.0.123\allcommands.ps1:5327 char:29

  • ... Start-BitsTransfer -Source $from -Destination $remotefile ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [Start-BitsTransfer], Exception
    • FullyQualifiedErrorId : StartBitsTransferCOMException,Microsoft.BackgroundIntelligentTransfer.Management.NewBits TransferCommand

It seems that the Start-BitsTransfer is the culprit and the code for the transfer (Start-SqlFileTransfer) never falls back to the copy-item command in the third try-catch block (which it seems the code intended to)

Trying the command below result in the same error Start-BitsTransfer -Source .\myfile.txt -Destination \sqlmigratesql4.agr.bah\c$\mssql\crmdata\myfile.txt

System, Administrators and MSSQLSERVER have full permissions on the folder (and mapped drive) - relaxing the permissions doesn't solve the BITS problem, so the bug is that the Copy-Item never gets executed

AGregersen avatar Oct 10 '20 07:10 AGregersen

The intended behavior would be achieved by adding -ErrorAction Stop to the Start-BitsTransfer commands in this senario, but that might not cover all needs

AGregersen avatar Oct 11 '20 11:10 AGregersen