src/Administration/Backup-XrmInstance.ps1
|
<# .SYNOPSIS Backup instance .DESCRIPTION Add a backup for given instance .PARAMETER InstanceDomainName Instance domain name (myinstance => myinstance.crm.dynamics1.com) .PARAMETER BackupLabel Name of the backup .PARAMETER BackupDescription Backup description .OUTPUTS PSCustomObject. Response of Backup-PowerAppEnvironment: the new backup, or the error details when the request fails (no error is raised). .EXAMPLE Connect-XrmAdmin -TenantId $tenantId -ApplicationId $applicationId -ClientSecret $clientSecret; $backup = Backup-XrmInstance -InstanceDomainName "contoso-prod" -BackupLabel "Before release 2.4" -BackupDescription "Taken by the release pipeline"; .LINK https://github.com/AymericM78/PowerDataOps/blob/main/documentation/commands/Backup-XrmInstance.md #> function Backup-XrmInstance { [CmdletBinding(SupportsShouldProcess, ConfirmImpact = "Low")] [OutputType([PSCustomObject])] param ( [Parameter(Mandatory, ValueFromPipeline)] [String] $InstanceDomainName, [Parameter(Mandatory = $true)] [String] $BackupLabel, [Parameter(Mandatory = $false)] [String] $BackupDescription ) begin { $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters); Assert-XrmAdminConnected; } process { $instance = Get-XrmInstance -Name $InstanceDomainName; $backupRequest = [pscustomobject]@{ Label = $BackupLabel Notes = $BackupDescription } if (-not $PSCmdlet.ShouldProcess($instance.Id, "Back up environment")) { return; } Backup-PowerAppEnvironment -EnvironmentName $instance.Id -BackupRequestDefinition $backupRequest; } end { $StopWatch.Stop(); Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch; } } Export-ModuleMember -Function Backup-XrmInstance -Alias *; |