dataplat / dbatools

🚀 SQL Server automation and instance migrations have never been safer, faster or freer
https://dbatools.io
MIT License
2.48k stars 805 forks source link

Backup-DbaServiceMasterKey - Support Custom Backup File Name #9483

Open serenefiresiren opened 1 month ago

serenefiresiren commented 1 month ago

Summarize Functionality

TSQL Command allows specifying the file name when backing up the service master key. Backup-DbaServiceMasterKey currently automatically sets the filename. It would be nice to have the option here as well. Relates to #9484 , #9485

Is there a command that is similiar or close to what you are looking for?

Yes

Technical Details

SQL Command

BACKUP SERVICE MASTER KEY
 TO FILE = 'c:\sqlbackup\MainServiceMaster.key'
 ENCRYPTION BY PASSWORD = 'S3cureP@ssword!sneeded'

Existing file name command, line 119 $filename = Join-DbaPath -SqlInstance $server -Path $Path -ChildPath "$fileinstance-servicemasterkey.key"

Suggested change adding an option Filename parameter

param (
        [parameter(Mandatory, ValueFromPipeline)]
        [DbaInstanceParameter[]]$SqlInstance,
        [PSCredential]$SqlCredential,
        [PSCredential]$KeyCredential,
        [Alias("Password")]
        [Security.SecureString]$SecurePassword,
        [string]$Path,
        **[string]$ChildPath,
        [Alias("FileName")]**
        [switch]$EnableException
    )
 #
 #
 #
 # pseudo
$ChildPath = $ChildPath or if null then $fileinstance-servicemasterkey.key" 
$filename = Join-DbaPath -SqlInstance $server -Path $Path -ChildPath $ChildPath 
wsmelton commented 1 month ago

Is there any difference to you just running Rename-Item after the command?

serenefiresiren commented 1 month ago

See #9485 for discussion