Skip to content

Commit

Permalink
Backup-DbaDatabase : add a new switch parameter "NoAppendDbNameInPath…
Browse files Browse the repository at this point in the history
…" to prevent dbname systematically appended at the end of backup path (#9348)
  • Loading branch information
rferraton committed May 16, 2024
1 parent b51ae6d commit 0fd8aa0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion public/Backup-DbaDatabase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ function Backup-DbaDatabase {
timestamp - will be replaced with the timestamp (either the default, or the format provided)
backuptype - will be replaced with Full, Log or Differential as appropriate
.PARAMETER NoAppendDbNameInPath
A switch that will prevent to systematically appended dbname to the path when creating the backup file path
.PARAMETER CopyOnly
If this switch is enabled, CopyOnly backups will be taken. By default function performs a normal backup, these backups interfere with the restore chain of the database. CopyOnly backups will not interfere with the restore chain of the database.
Expand Down Expand Up @@ -217,6 +220,7 @@ function Backup-DbaDatabase {
[string]$FilePath,
[switch]$IncrementPrefix,
[switch]$ReplaceInName,
[switch]$NoAppendDbNameInPath,
[switch]$CopyOnly,
[ValidateSet('Full', 'Log', 'Differential', 'Diff', 'Database')]
[string]$Type = 'Database',
Expand Down Expand Up @@ -661,7 +665,11 @@ function Backup-DbaDatabase {
for ($i = 0; $i -lt $FinalBackupPath.Count; $i++) {
$parent = [IO.Path]::GetDirectoryName($FinalBackupPath[$i])
$leaf = [IO.Path]::GetFileName($FinalBackupPath[$i])
$FinalBackupPath[$i] = [IO.Path]::Combine($parent, $dbName, $leaf)
if ($NoAppendDbNameInPath) {
$FinalBackupPath[$i] = [IO.Path]::Combine($parent, $leaf)
} else {
$FinalBackupPath[$i] = [IO.Path]::Combine($parent, $dbName, $leaf)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Backup-DbaDatabase.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', 'Database', 'ExcludeDatabase', 'Path', 'FilePath', 'ReplaceInName', 'CopyOnly', 'Type', 'InputObject', 'CreateFolder', 'FileCount', 'CompressBackup', 'Checksum', 'Verify', 'MaxTransferSize', 'BlockSize', 'BufferCount', 'AzureBaseUrl', 'AzureCredential', 'NoRecovery', 'BuildPath', 'WithFormat', 'Initialize', 'SkipTapeHeader', 'TimeStampFormat', 'IgnoreFileChecks', 'OutputScriptOnly', 'EnableException', 'EncryptionAlgorithm', 'EncryptionCertificate', 'IncrementPrefix', 'Description'
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'ExcludeDatabase', 'Path', 'FilePath', 'ReplaceInName', 'NoAppendDbNameInPath', 'CopyOnly', 'Type', 'InputObject', 'CreateFolder', 'FileCount', 'CompressBackup', 'Checksum', 'Verify', 'MaxTransferSize', 'BlockSize', 'BufferCount', 'AzureBaseUrl', 'AzureCredential', 'NoRecovery', 'BuildPath', 'WithFormat', 'Initialize', 'SkipTapeHeader', 'TimeStampFormat', 'IgnoreFileChecks', 'OutputScriptOnly', 'EnableException', 'EncryptionAlgorithm', 'EncryptionCertificate', 'IncrementPrefix', 'Description'
$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

0 comments on commit 0fd8aa0

Please sign in to comment.