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

Add-DbaAgDatabase - Add parameter AdvancedBackupParams #8135

Merged
merged 2 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions functions/Add-DbaAgDatabase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ function Add-DbaAgDatabase {
.PARAMETER UseLastBackup
Use the last full and log backup of the database. A log backup must be the last backup.

.PARAMETER AdvancedBackupParams
Provide additional parameters to the backup command as a hashtable.

.PARAMETER WhatIf
Shows what would happen if the command were to run. No actions are actually performed.

Expand Down Expand Up @@ -117,6 +120,11 @@ function Add-DbaAgDatabase {
PS C:\> Get-DbaDbSharePoint -SqlInstance sqlcluster -ConfigDatabase SharePoint_Config_2019 | Add-DbaAgDatabase -AvailabilityGroup SharePoint

Adds SharePoint databases as found in SharePoint_Config_2019 on sqlcluster to ag1 on sqlcluster

.EXAMPLE
PS C:\> Add-DbaAgDatabase -SqlInstance sql2017a -AvailabilityGroup ag1 -Database db1 -Secondary sql2017b -SeedingMode Manual -SharedPath \\FS\Backup -AdvancedBackupParams @{ CompressBackup = $true ; FileCount = 3 }

Adds db1 to ag1 on sql2017a and sql2017b. Uses compression and three files while taking the backups.
#>
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Low')]
param (
Expand Down Expand Up @@ -149,6 +157,9 @@ function Add-DbaAgDatabase {
[switch]$UseLastBackup,
[Parameter(ParameterSetName = 'NonPipeline')]
[Parameter(ParameterSetName = 'Pipeline')]
[hashtable]$AdvancedBackupParams,
[Parameter(ParameterSetName = 'NonPipeline')]
[Parameter(ParameterSetName = 'Pipeline')]
[switch]$EnableException
)

Expand Down Expand Up @@ -282,8 +293,13 @@ function Add-DbaAgDatabase {
if ($Pscmdlet.ShouldProcess($server, "Taking full and log backup of database $($db.Name)")) {
try {
Write-Message -Level Verbose -Message "Taking full and log backup of database $($db.Name)."
$fullbackup = $db | Backup-DbaDatabase -BackupDirectory $SharedPath -Type Full -EnableException
$logbackup = $db | Backup-DbaDatabase -BackupDirectory $SharedPath -Type Log -EnableException
if ($AdvancedBackupParams) {
$fullbackup = $db | Backup-DbaDatabase -BackupDirectory $SharedPath -Type Full -EnableException @AdvancedBackupParams
$logbackup = $db | Backup-DbaDatabase -BackupDirectory $SharedPath -Type Log -EnableException @AdvancedBackupParams
} else {
$fullbackup = $db | Backup-DbaDatabase -BackupDirectory $SharedPath -Type Full -EnableException
$logbackup = $db | Backup-DbaDatabase -BackupDirectory $SharedPath -Type Log -EnableException
}
$backups = $fullbackup, $logbackup
} catch {
Stop-Function -Message "Failed to take full and log backup of database $($db.Name)." -ErrorRecord $_ -Continue
Expand Down
2 changes: 1 addition & 1 deletion tests/Add-DbaAgDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'AvailabilityGroup', 'Database', 'Secondary', 'SecondarySqlCredential', 'InputObject', 'SeedingMode', 'SharedPath', 'UseLastBackup', 'EnableException'
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'AvailabilityGroup', 'Database', 'Secondary', 'SecondarySqlCredential', 'InputObject', 'SeedingMode', 'SharedPath', 'UseLastBackup', 'AdvancedBackupParams', 'EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
Expand Down