Skip to content

Commit 5b97e10

Browse files
Invoke-DbaDbLogShipping - Convert backticks to splats and add Azure credential validation
- Convert 10 instances of backtick line continuation to splats with aligned hashtables - Add Azure credential validation in New-DbaLogShippingPrimaryDatabase - Add Azure credential validation in New-DbaLogShippingSecondaryPrimary - Improve error messages explaining SAS token credential naming convention - Add unit tests for Azure parameter set validation (do Invoke-DbaDbLogShipping) Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
1 parent 754748c commit 5b97e10

File tree

4 files changed

+225
-133
lines changed

4 files changed

+225
-133
lines changed

private/functions/New-DbaLogShippingPrimaryDatabase.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,18 @@ function New-DbaLogShippingPrimaryDatabase {
146146
Stop-Function -Message "Azure blob storage backup requires SQL Server 2012 or later. Instance is version $($server.Version.Major)" -Target $SqlInstance
147147
return
148148
}
149+
150+
# Validate Azure credential exists on SQL Server instance
151+
# When using SAS token authentication, credential name must match the Azure URL
152+
$credentialName = $BackupShare
153+
$credential = $server.Credentials | Where-Object Name -eq $credentialName
154+
155+
if (-not $credential) {
156+
Stop-Function -Message "Azure blob storage requires a SQL Server credential named '$credentialName' to exist on instance $SqlInstance. Create the credential using New-DbaCredential with either a Shared Access Signature (SAS) token or storage account key before setting up log shipping." -Target $SqlInstance
157+
return
158+
}
159+
160+
Write-Message -Message "Found Azure credential: $credentialName" -Level Verbose
149161
} else {
150162
# Traditional UNC path - validate format and accessibility
151163
if ([bool]([uri]$BackupShare).IsUnc -and $BackupShare -notmatch '^\\(?:\\[^<>:`"/\\|?*]+)+$') {

private/functions/New-DbaLogShippingSecondaryPrimary.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,32 @@ function New-DbaLogShippingSecondaryPrimary {
158158
Stop-Function -Message "Azure blob storage restore requires SQL Server 2012 or later. Instance is version $($ServerSecondary.Version.Major)" -Target $SqlInstance
159159
return
160160
}
161+
162+
# Validate Azure credentials exist on SQL Server instance
163+
# When using SAS token authentication, credential name must match the Azure URL
164+
if ($IsAzureSource) {
165+
$sourceCredentialName = $BackupSourceDirectory
166+
$sourceCredential = $ServerSecondary.Credentials | Where-Object Name -eq $sourceCredentialName
167+
168+
if (-not $sourceCredential) {
169+
Stop-Function -Message "Azure blob storage requires a SQL Server credential named '$sourceCredentialName' to exist on instance $SqlInstance. Create the credential using New-DbaCredential with either a Shared Access Signature (SAS) token or storage account key before setting up log shipping." -Target $SqlInstance
170+
return
171+
}
172+
173+
Write-Message -Message "Found Azure source credential: $sourceCredentialName" -Level Verbose
174+
}
175+
176+
if ($IsAzureDestination) {
177+
$destCredentialName = $BackupDestinationDirectory
178+
$destCredential = $ServerSecondary.Credentials | Where-Object Name -eq $destCredentialName
179+
180+
if (-not $destCredential) {
181+
Stop-Function -Message "Azure blob storage requires a SQL Server credential named '$destCredentialName' to exist on instance $SqlInstance. Create the credential using New-DbaCredential with either a Shared Access Signature (SAS) token or storage account key before setting up log shipping." -Target $SqlInstance
182+
return
183+
}
184+
185+
Write-Message -Message "Found Azure destination credential: $destCredentialName" -Level Verbose
186+
}
161187
} else {
162188
# Traditional file path scenario - validate UNC path
163189
if ([bool]([uri]$BackupDestinationDirectory).IsUnc -and $BackupDestinationDirectory -notmatch '^\\(?:\\[^<>:`"/\\|?*]+)+$') {

0 commit comments

Comments
 (0)