Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start-TssConfigurationBackup - new command
- Loading branch information
Showing
4 changed files
with
252 additions
and
83 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
docs/commands/configurations/Start-TssConfigurationBackup.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Start-TssConfigurationBackup | ||
|
||
## SYNOPSIS | ||
Start the database backup as configured | ||
|
||
## SYNTAX | ||
|
||
``` | ||
Start-TssConfigurationBackup [-TssSession] <Session> [-WhatIf] [-Confirm] [<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
Start the database backup as configured | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
``` | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Start-TssConfigurationBackup -TssSession $session | ||
``` | ||
|
||
Run the backup for the Secret Server as configured | ||
|
||
## PARAMETERS | ||
|
||
### -TssSession | ||
TssSession object created by New-TssSession for authentication | ||
|
||
```yaml | ||
Type: Session | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: True | ||
Position: 1 | ||
Default value: None | ||
Accept pipeline input: True (ByValue) | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -WhatIf | ||
Shows what would happen if the cmdlet runs. | ||
The cmdlet is not run. | ||
|
||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: (All) | ||
Aliases: wi | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -Confirm | ||
Prompts you for confirmation before running the cmdlet. | ||
|
||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: (All) | ||
Aliases: cf | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### CommonParameters | ||
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). | ||
|
||
## INPUTS | ||
|
||
## OUTPUTS | ||
|
||
## NOTES | ||
Requires TssSession object returned by New-TssSession | ||
|
||
## RELATED LINKS | ||
|
||
[https://thycotic-ps.github.io/thycotic.secretserver/commands/configurations/Start-TssConfigurationBackup](https://thycotic-ps.github.io/thycotic.secretserver/commands/configurations/Start-TssConfigurationBackup) | ||
|
||
[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/configurations/Start-TssConfigurationBackup.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/configurations/Start-TssConfigurationBackup.ps1) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/functions/configurations/Start-TssConfigurationBackup.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
function Start-TssConfigurationBackup { | ||
<# | ||
.SYNOPSIS | ||
Start the database backup as configured | ||
.DESCRIPTION | ||
Start the database backup as configured | ||
.EXAMPLE | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Start-TssConfigurationBackup -TssSession $session | ||
Run the backup for the Secret Server as configured | ||
.LINK | ||
https://thycotic-ps.github.io/thycotic.secretserver/commands/configurations/Start-TssConfigurationBackup | ||
.LINK | ||
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/configurations/Start-TssConfigurationBackup.ps1 | ||
.NOTES | ||
Requires TssSession object returned by New-TssSession | ||
#> | ||
[CmdletBinding(SupportsShouldProcess)] | ||
param ( | ||
# TssSession object created by New-TssSession for authentication | ||
[Parameter(Mandatory, ValueFromPipeline, Position = 0)] | ||
[Thycotic.PowerShell.Authentication.Session] | ||
$TssSession | ||
) | ||
begin { | ||
$tssParams = $PSBoundParameters | ||
$invokeParams = . $GetInvokeApiParams $TssSession | ||
} | ||
process { | ||
Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)" | ||
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) { | ||
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation | ||
$uri = $TssSession.ApiUrl, 'configuration', 'backup', 'run-now' -join '/' | ||
$invokeParams.Uri = $uri | ||
$invokeParams.Method = 'POST' | ||
|
||
if (-not $PSCmdlet.ShouldProcess("SecretId: $user", "$($invokeParams.Method) $($invokeParams.Uri)")) { return } | ||
Write-Verbose "Performing the operation: $($invokeParams.Method) $($invokeParams.Uri)" | ||
try { | ||
$apiResponse = Invoke-TssApi @invokeParams | ||
$restResponse = . $ProcessResponse $apiResponse | ||
} catch { | ||
$err = $_ | ||
. $ErrorHandling $err | ||
} | ||
|
||
if ($restResponse) { | ||
Write-Verbose "Database Backup started successfully" | ||
} | ||
} else { | ||
Write-Warning 'No valid session found' | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/configurations/Start-TssConfigurationBackup.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
BeforeDiscovery { | ||
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf | ||
} | ||
Describe "$commandName verify parameters" { | ||
BeforeDiscovery { | ||
[object[]]$knownParameters = 'TssSession' | ||
[object[]]$currentParams = ([Management.Automation.CommandMetaData]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function')).Parameters.Keys | ||
[object[]]$commandDetails = [System.Management.Automation.CommandInfo]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function') | ||
$unknownParameters = Compare-Object -ReferenceObject $knownParameters -DifferenceObject $currentParams -PassThru | ||
} | ||
Context "Verify parameters" -Foreach @{currentParams = $currentParams } { | ||
It "$commandName should contain <_> parameter" -TestCases $knownParameters { | ||
$_ -in $currentParams | Should -Be $true | ||
} | ||
It "$commandName should not contain parameter: <_>" -TestCases $unknownParameters { | ||
$_ | Should -BeNullOrEmpty | ||
} | ||
} | ||
} |