CopyDestinationFolder issue with Invoke-DbaDbLogShipping
Verified issue does not already exist?
I have searched and found no existing issue
What error did you receive?
In a scenario where I am trying to execute Invoke-DbaDbLogShipping from a VM/laptop against 2 remote SQL Server servers, I get the following error:
[Invoke-DbaDbLogShipping] Something went wrong creating the database copy destination folder.
This only happens when I set CopyDestinationFolder path that's local to secondary, f.ex. D:\BackupsHere If I use UNC path, then the command runs correctly without the error.
I've done the following testing on it:
- Tried with a couple of different versions of DBAtools, the last before 2.0 and then the latest
- I've also tested setting up the log shipping manually, and it works using the local drive as a target for copying backup files
- I've checked that Powershell Remoting works
- I've checked that the user permissions are set correctly
- I've checked that Invoke-Command to remote servers (Get-Item D:\BackupsHere).PSProvider.Name returns FileSystem
Steps to Reproduce
$logShippingParams = @{
SourceSqlInstance = server1
DestinationSqlInstance = server2
Database = AdventureWorks
BackupLocalPath = \\fileshare\backups
CopyDestinationFolder = D:\BackupsHere
SharedPath = \\fileshare\backups
BackupJob = BackupJobName
RestoreJob = RestoreJobName
CopyJob = CopyJobName
BackupScheduleFrequencyType = Daily
BackupScheduleFrequencySubdayType = minutes
BackupScheduleFrequencySubdayInterval = 10
CopyScheduleFrequencyType = Daily
CopyScheduleFrequencySubdayType = minutes
CopyScheduleFrequencySubdayInterval = 10
RestoreScheduleFrequencyType = Daily
RestoreScheduleFrequencySubdayType = minutes
RestoreScheduleFrequencySubdayInterval = 10
PrimaryMonitorServer = server1
SecondaryMonitorServer = server2
NoInitialization = $true
NoRecovery = $true
Force = $true
}
Invoke-DbaDbLogShipping @logShippingParams
Please confirm that you are running the most recent version of dbatools
2.1.5
Other details or mentions
No response
What PowerShell host was used when producing this error
PowerShell Core (pwsh.exe), Windows PowerShell (powershell.exe)
PowerShell Host Version
Name Value
PSVersion 7.4.0 PSEdition Core GitCommitId 7.4.0 OS Microsoft Windows 10.0.17763 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0
SQL Server Edition and Build number
Microsoft SQL Server 2019 (RTM-CU23-OD) (KB5032975) - 15.0.4338.1 (X64) Oct 24 2023 19:03:45 Copyright (C) 2019 Microsoft Corporation Standard Edition (64-bit) on Windows Server 2019 Datacenter 10.0 <X64> (Build 17763: ) (Hypervisor)
.NET Framework Version
.NET 8.0.0
This is the code that failes:
Invoke-Command2 -Credential $DestinationCredential -ScriptBlock {
Write-Message -Message "Copy destination folder $DatabaseCopyDestinationFolder not found. Trying to create it.. ." -Level Verbose
$null = New-Item -Path $DatabaseCopyDestinationFolder -ItemType Directory -Credential $DestinationCredential -Force:$Force
}
It looks like this code is executes on the local maschine you are running dbatools from, resulting in a local folder. You probably don't have the drive letter so it failes. You could test this by using a folder name that can be created locally. To support a "local to the remote" folder name, this needs to be executed on the target server.
Other parts of the code take this into account - this is missing here.
As I don't have a lab for log shipping nor do I need log shipping in my job, I don't want to invest much time in fixing these commands. Maybe you can create the needed folders ahead of time or just use UNC paths.
I figured out as much, too, that the check was happening locally. The UNC path is a decent workaround, so I'll probably go with that.
Did you have an example of where this is done successfully? If I find some time, I might look into creating the fix for it.