Closed bcullman closed 3 months ago
@ebalders - I think you were the last person to touch this script. Your review would be appreciated.
@bcullman I don't have write access, so my review won't allow this to be merged, but I'll add my 2 cents.
Get-ChildItem $BackupDirectory -Exclude $retained | Remove-Item
Here, a filter should be applied that only removes files starting with the db name. Even then, I think there is a chance this may delete unintended files:
Take the following databases and the resulting backup names: database1 => database1_timestamp.bak database1_final => database1_final_timestamp.bak
I think a safer approach would be to build a regex based on the $dbname and timestamp format used.
I concur with @ebalders , good suggestion.
Thank you for making the update, I think one more refinement on the filter and we should be in good shape. Adding something like
$regexPattern = "$($dbName)_\d+.*\.bak"
$allfiles = (Get-ChildItem $BackupDirectory | Where-Object {$_.Name -Match $regexPattern})
would filter out files that have a similar name. @ebalders , thoughts?
@twerthi, @ebalders
Appreciate the feedback. I am working on refactoring so i can put some unit tests around this change.
Converting this to a draft until i validate this effort.
@twerthi, @ebalders
Thank you for your patience. Completed my validation here.
Please note: The existing unit test in the project for windows-scheduled-task-create did not seem work on my machine on the master branch. 😢 I did nothing here to resolve that issue here.
I did alter the Invoke-PesterTests.ps1 to fall back to a global instance of Pester if the local one is not available.
I did alter the Invoke-PesterTests.ps1 to fall back to a global instance of Pester if the local one is not available.
I had some issues executing the pester tests using Invoke-PesterTests.ps1
as there wasnt a sql-backup-database.ScriptBody.ps1
file in the (root) folder that could be "." sourced. The function file threw exceptions for both
However, after I created one from the step template itself and then ran your tests with 7 passing.
I completely ignored windows scheduled task one too.
I had some issues executing the pester tests using
Invoke-PesterTests.ps1
as there wasnt asql-backup-database.ScriptBody.ps1
file in the (root) folder that could be "." sourced. The function file threw exceptions for bothHowever, after I created one from the step template itself and then ran your tests with 7 passing.
🤔 It wouldn't be too hard to alter the script to check for a > 0 count of .ps1 files and throw a warning if none are found. Or, perhaps even check for each .Tests.ps1 file, check for a matching *.ps1 file...
🤔 It wouldn't be too hard to alter the script to check for a > 0 count of .ps1 files and throw a warning if none are found. Or, perhaps even check for each .Tests.ps1 file, check for a matching *.ps1 file...
We'll have a discussion internally and see if its something we want to update
@harrisonmeister - Running the unit tests as part of a PR status check via a GitHub action or other means would be something to review as well. Although I understand if you were to conclude it's not worth the effort, given there are only 2 unit tests at the moment, and one of them does not seem to work...
Although
...once Github action were place, you could then automate the Converter.ps1 step. Then, you could make it so that folks check in the actual .ps1 files, rather than the .json files for step templates.
That would be a big win, because then PRs would be code reviews not of the .json files, where the script under review script has been compressed into a single json property, but instead of the actual .ps1 files themselves, where commentary can happen line-by-line, and git history becomes more useful.
Background
Allow user of the SQL Backup Database step template to optionally limit the number of backup files on disk
Results
By Default, this script will work exactly the same as before - the retention capability is set to false via the RetentionPolicyEnabled value. It set to true, we clean up Db backup files, leaving only newest N remaining, where N is specified in RetentionPolicyCount
Before
After
Pre-requisites
Id
should be a GUID that is not00000000-0000-0000-0000-000000000000
Id
property (updating theId
will break the Library sync functionality in Octopus).Version
should be incremented, otherwise the integration with Octopus won't update the step template correctly$
LastModifiedBy
field must be present, and (optionally) updated with the correct authorCategory
has been created:{categoryname}.png
must be present under thestep-templates/logos
folderswitch
in thehumanize
function ingulpfile.babel.js
must have acase
statement corresponding to it