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

Save-DbaKbUpdate - Using Architecture and some other fixes #7531

Merged
merged 3 commits into from
Jul 13, 2021

Conversation

andreasjordan
Copy link
Contributor

Type of Change

  • Bug fix (non-breaking change, fixes # )

When downloading cumulative updates for SQL Server 2014 I noticed, that also the x86 files where downloaded.
Reason is that the filtering for Architecture was not working, as $item in $InputObject.Link was not a list of all files for the KB, but only a single file - with no chance to see the other files for that KB. So the "Could not find architecture match, downloading all" never worked here. Maybe worked before pipeline input from Get-DbaKbUpdate was enabled.
So I reduced the two loops into one - sorry, this makes the diff not very readable again.

I also found other issues with the tests and the way the filename was build.

@andreasjordan
Copy link
Contributor Author

andreasjordan commented Jul 13, 2021

This is my use case code to download the cumulative updates in a lab environment, that I will put in "Discussions / Show and tell" after this is released:

Import-Module -Name dbatools

function Get-CU {
    param(
        [Parameter(Mandatory)]
        [ValidateSet('2019', '2017', '2016', '2014')]
        [string]$Version,
        [regex]$BuildBaseRegex,
        [int]$Last = 999,
        [string[]]$Exclude,
        [string]$Path = '.'
    )
    if ($null -eq $BuildBaseRegex) {
        $BuildBaseRegex = switch ($Version) {
            '2019' { '^15' }
            '2017' { '^14' }
            '2016' { '^13.0.5' }  # Based on SP2
            '2014' { '^12.0.6' }  # Based on SP3
        }
    }
    if ($Version -eq '2019') { 
        $Exclude += 'CU7'  # CU7 is not available any more
    }
    $buildrefFile = Join-Path -Path (Get-DbatoolsConfigValue -Name 'Path.DbatoolsData') -ChildPath "dbatools-buildref-index.json"
    $buildrefData = (Get-Content -Path $buildrefFile -Raw | ConvertFrom-Json).Data
    $cuData = $buildrefData | 
        Where-Object -FilterScript { $_.Version -match $BuildBaseRegex -and $_.CU -ne $null -and $_.CU -notin $Exclude } |
        Sort-Object -Property KBList |
        Select-Object -Last $Last
    foreach ($cu in $cuData) {
        $kbNr = $cu.KBList
        $cuName = $cu.CU
        $filePath = Join-Path -Path $Path -ChildPath "SQLServer$Version-KB$kbNr-$cuName-x64.exe"
        if (-not (Test-Path -Path $filePath)) {
            Save-DbaKbUpdate -Name $kbNr -FilePath $filePath
        }
    }
}

Update-DbaBuildReference
$patchPath = 'D:\Software\SQLServerPatches'
Get-CU -Version 2019 -Path $patchPath
Get-CU -Version 2017 -Path $patchPath -Last 5
Get-CU -Version 2016 -Path $patchPath -Last 5
Get-CU -Version 2014 -Path $patchPath
# KB4583462 - Security update for SQL Server 2014 SP3 CU4: January 12, 2021
Save-DbaKbUpdate -Name 4583462 -FilePath "$patchPath\SQLServer2014-KB4583462-CU4-Security-x64.exe"
# KB4583465 - Security update for SQL Server 2012 SP4 GDR: January 12, 2021
Save-DbaKbUpdate -Name 4583465 -FilePath "$patchPath\SQLServer2012-KB4583465-GDR-Security-x64.exe"
# Check for new versions at: https://sqlserverbuilds.blogspot.com/
# KB5003830 - New CU that is not yet known by dbatools
Save-DbaKbUpdate -Name 5003830 -FilePath "$patchPath\SQLServer2017-KB5003830-CU25-x64.exe"

@potatoqualitee
Copy link
Member

haha awesome code!

@potatoqualitee potatoqualitee merged commit 65854f3 into development Jul 13, 2021
@potatoqualitee potatoqualitee deleted the SaveDbaKbUpdate_fixes branch July 13, 2021 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants