Skip to content

Commit 832d4de

Browse files
Invoke-DbaDbLogShipping - Improve Azure URL validation and error messages
- Update CLAUDE.md with notes about avoiding ParameterSets and parameter spacing - Improve Azure URL regex to properly validate storage account naming constraints (3-24 chars) - Add concrete examples to all Azure URL error messages - Add Azure support attribution to .NOTES sections in private functions (do Invoke-DbaDbLogShipping) Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
1 parent 7a26eb1 commit 832d4de

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

CLAUDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ param(
3838
- Use `[Parameter(Mandatory)]` not `[Parameter(Mandatory = $true)]`
3939
- Use `[switch]` for boolean flags, not `[bool]` parameters
4040
- Keep non-boolean attributes with values: `[Parameter(ValueFromPipelineByPropertyName = "Name")]`
41+
- Avoid ParameterSets - their error messages are terrible and hard to use. Use Test-Bound instead and provide users with useful, concrete error messages.
42+
- No extra line breaks between parameter declarations - keep parameter blocks compact without blank lines separating individual parameters.
4143

4244
### POWERSHELL v3 COMPATIBILITY
4345

private/functions/New-DbaLogShippingPrimaryDatabase.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function New-DbaLogShippingPrimaryDatabase {
7979
It will also remove the any present schedules with the same name for the specific job.
8080
8181
.NOTES
82-
Author: Sander Stad (@sqlstad, sqlstad.nl)
82+
Author: Sander Stad (@sqlstad, sqlstad.nl), Azure blob storage support added by Claude
8383
Website: https://dbatools.io
8484
Copyright: (c) 2018 by dbatools, licensed under MIT
8585
License: MIT https://opensource.org/licenses/MIT
@@ -137,8 +137,8 @@ function New-DbaLogShippingPrimaryDatabase {
137137
# Azure blob storage URL - validate format
138138
Write-Message -Message "Using Azure blob storage for log shipping backups: $BackupShare" -Level Verbose
139139

140-
if ($BackupShare -notmatch '^https?://[a-z0-9]+\.blob\.core\.windows\.net/[a-z0-9\-]+') {
141-
Stop-Function -Message "The Azure backup URL $BackupShare should be in the format https://storageaccount.blob.core.windows.net/container" -Target $SqlInstance
140+
if ($BackupShare -notmatch '^https?://[a-z0-9]{3,24}\.blob\.core\.windows\.net/[a-z0-9]([a-z0-9\-]*[a-z0-9])?') {
141+
Stop-Function -Message "The Azure backup URL $BackupShare should be in the format https://storageaccount.blob.core.windows.net/container (example: https://mystorageaccount.blob.core.windows.net/logshipping)" -Target $SqlInstance
142142
return
143143
}
144144

private/functions/New-DbaLogShippingSecondaryPrimary.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function New-DbaLogShippingSecondaryPrimary {
7272
It will also remove the any present schedules with the same name for the specific job.
7373
7474
.NOTES
75-
Author: Sander Stad (@sqlstad, sqlstad.nl)
75+
Author: Sander Stad (@sqlstad, sqlstad.nl), Azure blob storage support added by Claude
7676
Website: https://dbatools.io
7777
Copyright: (c) 2018 by dbatools, licensed under MIT
7878
License: MIT https://opensource.org/licenses/MIT
@@ -144,13 +144,13 @@ function New-DbaLogShippingSecondaryPrimary {
144144
}
145145

146146
# Validate Azure URL format if provided
147-
if ($IsAzureSource -and $BackupSourceDirectory -notmatch '^https?://[a-z0-9]+\.blob\.core\.windows\.net/') {
148-
Stop-Function -Message "The Azure backup source URL should be in the format https://storageaccount.blob.core.windows.net/container" -Target $SqlInstance
147+
if ($IsAzureSource -and $BackupSourceDirectory -notmatch '^https?://[a-z0-9]{3,24}\.blob\.core\.windows\.net/') {
148+
Stop-Function -Message "The Azure backup source URL should be in the format https://storageaccount.blob.core.windows.net/container (example: https://mystorageaccount.blob.core.windows.net/logshipping)" -Target $SqlInstance
149149
return
150150
}
151151

152-
if ($IsAzureDestination -and $BackupDestinationDirectory -notmatch '^https?://[a-z0-9]+\.blob\.core\.windows\.net/') {
153-
Stop-Function -Message "The Azure backup destination URL should be in the format https://storageaccount.blob.core.windows.net/container" -Target $SqlInstance
152+
if ($IsAzureDestination -and $BackupDestinationDirectory -notmatch '^https?://[a-z0-9]{3,24}\.blob\.core\.windows\.net/') {
153+
Stop-Function -Message "The Azure backup destination URL should be in the format https://storageaccount.blob.core.windows.net/container (example: https://mystorageaccount.blob.core.windows.net/logshipping)" -Target $SqlInstance
154154
return
155155
}
156156

public/Invoke-DbaDbLogShipping.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ function Invoke-DbaDbLogShipping {
591591
$RegexDate = '(?<!\d)(?:(?:(?:1[6-9]|[2-9]\d)?\d{2})(?:(?:(?:0[13578]|1[02])31)|(?:(?:0[1,3-9]|1[0-2])(?:29|30)))|(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))0229)|(?:(?:1[6-9]|[2-9]\d)?\d{2})(?:(?:0?[1-9])|(?:1[0-2]))(?:0?[1-9]|1\d|2[0-8]))(?!\d)'
592592
$RegexTime = '^(?:(?:([01]?\d|2[0-3]))?([0-5]?\d))?([0-5]?\d)$'
593593
$RegexUnc = '^\\(?:\\[^<>:`"/\\|?*]+)+$'
594-
$RegexAzureUrl = '^https?://[a-z0-9]+\.blob\.core\.windows\.net/[a-z0-9\-]+/?'
594+
$RegexAzureUrl = '^https?://[a-z0-9]{3,24}\.blob\.core\.windows\.net/[a-z0-9]([a-z0-9\-]*[a-z0-9])?/?'
595595

596596
# Validate mutually exclusive parameters for backup destination
597597
if (-not (Test-Bound -ParameterName "SharedPath", "AzureBaseUrl" -Min 1 -Max 1)) {
@@ -616,7 +616,7 @@ function Invoke-DbaDbLogShipping {
616616
$AzureBaseUrl = $AzureBaseUrl.TrimEnd("/")
617617

618618
if ($AzureBaseUrl -notmatch $RegexAzureUrl) {
619-
Stop-Function -Message "Azure blob storage URL $AzureBaseUrl must be in the format https://storageaccount.blob.core.windows.net/container" -Target $SourceSqlInstance
619+
Stop-Function -Message "Azure blob storage URL $AzureBaseUrl must be in the format https://storageaccount.blob.core.windows.net/container (example: https://mystorageaccount.blob.core.windows.net/logshipping)" -Target $SourceSqlInstance
620620
return
621621
}
622622

0 commit comments

Comments
 (0)