dataplat / dbatools

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

Backup-DbaDatabase : add a new switch parameter "NoAppendDbNameInPath" to prevent dbname systematically appended at the end of backup path #9348

Closed rferraton closed 1 month ago

rferraton commented 1 month ago

Type of Change

Purpose

  1. Avoid to force the directory path to finish with the dbname whereas the path can be variabilized with -ReplaceInName and dbname token
  2. When the dbname is long the directory path length limit (259 characters) imposed by MSSQL Engine can be reach very easily when dbname is used twice in the path
  3. To allow to stick with Ola Hallengren default backup path
  4. Solve feature request #9346

Approach

Add a new switch variable that will avoid breaking changes to existing backup scripts using Backup-DbaDatabase but will allow to prevent the dbname to be systematicaly added at the end of the path

Commands to test

Backup-DbaDatabase -SqlInstance localhost -Database TESTDATABASE_ABC_1eed02d4-f58b-4110-9cee-78c2fa65123a_123456789012345678901234567890 -Type Full -CompressBackup -Checksum -Verify -FileCount 1 -Path "D:\MSSQL\BACKUPS\servername\instancename\dbname\backuptype" -FilePath "servername_dbname_backuptype_timestamp.bak" -TimeStampFormat "yyyyMMdd_HHmm" -ReplaceInName -CreateFolder -WarningVariable WarningVariable -OutVariable BackupResults -EnableException -NoAppendDbNameInPath

Screenshots

2024-05-13_15h04_34

wsmelton commented 1 month ago

Why is this needed? I don't see any issue linking the feature being requested. If we are not going to do an issue please expand on the scenarios (multiple are needed) this is meeting to address (these must be what we built tests on for the command).

wsmelton commented 1 month ago

breaking changes to existing backup scripts

Who's backup scripts?

rferraton commented 1 month ago

breaking changes to existing backup scripts

Who's backup scripts?

I mean that the new parameter NoAppendDbNameInPath , is not activate by default. If it was, it would lead to a behavior change and would impact backup directories output (in all currently used backup scripts using Backup-DbaDatabase over the world).

Using such a switch parameter allow to avoid breaking change because it will prevent the dbname to be added at the end of the backup path only when used ==> no breaking change.

I closed the issue https://github.com/dataplat/dbatools/issues/9341 that i opened a couple of days ago to signal a problem when dbname is long because niphlod say that is was more an enhancement request.

So i did the enhancement request #9346, made the enhancement, and push it.

potatoqualitee commented 1 month ago

Thank you, @rferraton. This is a nice solution. @niphlod can you give approval? I will merge upon approval from core team.

niphlod commented 1 month ago

looks good, may be a niche case, and would probably benefit from a specific test to make sure no regressions are introduced.

potatoqualitee commented 1 month ago

merci 🇮🇹 😊

rferraton commented 1 month ago

Thanks/Merci !