make the cloud backup update script require powershell 4 and make that the repo default for new scripts
This commit is contained in:
@@ -2,6 +2,12 @@
|
||||
|
||||
## RMM script execution model
|
||||
|
||||
Target **Windows PowerShell 4.0** by default for new Windows RMM scripts. Put
|
||||
`#Requires -Version 4.0` in both the RMM caller and its downloaded core. Use
|
||||
4.0-compatible syntax, cmdlets and .NET APIs throughout their execution path,
|
||||
including shared helpers. If a workload genuinely needs a newer version,
|
||||
document the dependency alongside its version requirement.
|
||||
|
||||
This is the required convention for new RMM scripts. Read both
|
||||
[`Install-MicrosoftOffice365.ps1`](Install-MicrosoftOffice365.ps1) and its
|
||||
[`rmm/Install-MicrosoftOffice365.ps1`](rmm/Install-MicrosoftOffice365.ps1) caller
|
||||
@@ -75,7 +81,7 @@ $QuickBooksGraceSeconds = '60'
|
||||
- Download `Tools.ps1` live when needed. **Do not cache `Tools.ps1` or its helper
|
||||
definitions**, or introduce an offline Tools fallback. This is an explicit
|
||||
repository preference; the cloud-backup workflow requires network access.
|
||||
- Set TLS 1.2 before the first HTTPS download on Windows PowerShell 5.
|
||||
- Set TLS 1.2 before the first HTTPS download on Windows PowerShell 4.0 and 5.x.
|
||||
- Normally dot-source live `Tools.ps1` as shown above, then call `Run-Script`.
|
||||
The QuickBooks permanent backup shim has a documented specialized loader: it
|
||||
downloads Tools live and dot-sources only its two conversion definitions to
|
||||
@@ -85,6 +91,8 @@ $QuickBooksGraceSeconds = '60'
|
||||
from `resources/quickbooks/QuickBooksBackup.ps1`. All code is fetched live;
|
||||
only recovery state/logs persist. Start must not call a local Stop shim or use
|
||||
a cached Stop script in a hidden restore mode.
|
||||
- Use focused Windows PowerShell 5 tests to verify actual shim-to-core input
|
||||
visibility, string-to-boolean/list conversion, and exit-code propagation when
|
||||
changing these boundaries. Mock downloads and disruptive actions during tests.
|
||||
- Test shim-to-core input visibility, string conversions, and exit-code
|
||||
propagation when changing these boundaries. Mock downloads and disruptive
|
||||
actions. For the 4.0 baseline, run on Windows PowerShell 4.0 when available.
|
||||
Otherwise check compatibility against the Server 2012 R2 / PowerShell 4.0
|
||||
profile and run the focused tests on Windows PowerShell 5.1.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#Requires -Version 5.1
|
||||
#Requires -Version 4.0
|
||||
# Update an existing Emberkom MSP360 Managed Backup agent during an idle RMM window.
|
||||
|
||||
function Get-CloudBackupInstallation {
|
||||
@@ -121,7 +121,7 @@ function Invoke-CloudBackupUpdate {
|
||||
}
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$updateLock = [Threading.Mutex]::new($false, 'Global\EmberkomCloudBackupUpdate')
|
||||
$updateLock = New-Object -TypeName System.Threading.Mutex -ArgumentList $false,'Global\EmberkomCloudBackupUpdate'
|
||||
$ownsLock = $false
|
||||
try {
|
||||
try { $ownsLock = $updateLock.WaitOne(0) }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Updating Emberkom Cloud Backup between plans
|
||||
|
||||
Publish the repository changes to the live `master` branch, then upload [the RMM caller](../rmm/Update-EmberkomCloudBackup.ps1) to Syncro as a Windows PowerShell 5.1 script. Run it as SYSTEM on endpoints with Emberkom Cloud Backup. Schedule it in a gap long enough for the download, installation, and backup service restart. Include restore plans and consistency checks when choosing that gap.
|
||||
Publish the repository changes to the live `master` branch, then upload [the RMM caller](../rmm/Update-EmberkomCloudBackup.ps1) to Syncro. The caller and updater require Windows PowerShell 4.0 or later. Replace any previously uploaded caller that still declares 5.1. PowerShell checks that declaration before the caller can fetch the live scripts. Run it as SYSTEM on endpoints with Emberkom Cloud Backup. Schedule it in a gap long enough for the download, installation, and backup service restart. Include restore plans and consistency checks when choosing that gap.
|
||||
|
||||
For endpoints that might receive a delayed RMM job, configure the optional **string** variable `MSP360UpdateWindow`. For example, `12:00-13:00` admits installation starts from noon until just before 1 p.m. in the endpoint's local time. Overnight windows such as `23:30-00:30` also work. With an omitted or blank value, Syncro controls the timing. Allow enough time after the last permitted start for setup to finish.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#Requires -Version 5.1
|
||||
#Requires -Version 4.0
|
||||
# Syncro: run as SYSTEM at a time reserved between backup, restore and consistency plans.
|
||||
# Optional string $MSP360UpdateWindow, e.g. '12:00-13:00' in endpoint local time.
|
||||
# Leave blank to use the Syncro schedule alone. See docs/EmberkomCloudBackup-Updates.md.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#Requires -Version 5.1
|
||||
#Requires -Version 4.0
|
||||
# Run with Windows PowerShell. All downloads, plan checks and installs are fixtures.
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$repo = Split-Path -Parent $PSScriptRoot
|
||||
@@ -19,6 +19,10 @@ function Find-TestFunction($Tree, $Name) {
|
||||
|
||||
try {
|
||||
$core = Read-TestAst (Join-Path $repo 'Update-EmberkomCloudBackup.ps1')
|
||||
$shim = Read-TestAst (Join-Path $repo 'rmm/Update-EmberkomCloudBackup.ps1')
|
||||
foreach ($entry in @($shim,$core)) {
|
||||
if ($entry.ScriptRequirements.RequiredPSVersion -ne [version]'4.0') { throw "Expected #Requires -Version 4.0 in $($entry.Extent.File)" }
|
||||
}
|
||||
$windowFn = Find-TestFunction $core 'Test-CloudBackupUpdateWindow'
|
||||
. ([scriptblock]::Create($windowFn.Extent.Text))
|
||||
foreach ($case in @(
|
||||
@@ -54,7 +58,10 @@ try {
|
||||
return $path
|
||||
}
|
||||
function New-Object {
|
||||
param($TypeName)
|
||||
param($TypeName,[object[]]$ArgumentList)
|
||||
if ($TypeName -eq 'System.Threading.Mutex') {
|
||||
return (Microsoft.PowerShell.Utility\New-Object -TypeName $TypeName -ArgumentList $ArgumentList)
|
||||
}
|
||||
if ($TypeName -ne 'Net.WebClient') { throw "Unexpected construction of $TypeName" }
|
||||
$client = [pscustomobject]@{}
|
||||
$client | Add-Member ScriptMethod DownloadString { param($url)
|
||||
@@ -77,9 +84,11 @@ try {
|
||||
$record.Staged = $OutFile
|
||||
[IO.File]::WriteAllBytes($OutFile, $fixtureBytes)
|
||||
if ($scenario -eq 'corrupt') { [IO.File]::AppendAllText($OutFile,'x') }
|
||||
if ($scenario -eq 'download failure') { throw [Net.WebException]::new('Certificate validation failed',[Net.WebExceptionStatus]::TrustFailure) }
|
||||
if ($scenario -eq 'download failure') {
|
||||
throw (Microsoft.PowerShell.Utility\New-Object Net.WebException -ArgumentList 'Certificate validation failed',([Net.WebExceptionStatus]::TrustFailure))
|
||||
}
|
||||
if ($scenario -eq 'persistent timeout' -or ($scenario -in @('timeout then success','plan during retry') -and $record.Downloads -eq 1)) {
|
||||
throw [Net.WebException]::new('The operation has timed out',[Net.WebExceptionStatus]::Timeout)
|
||||
throw (Microsoft.PowerShell.Utility\New-Object Net.WebException -ArgumentList 'The operation has timed out',([Net.WebExceptionStatus]::Timeout))
|
||||
}
|
||||
}
|
||||
function Start-Sleep { param($Seconds) if ($Seconds -ne 3) { throw 'Unexpected retry delay' } }
|
||||
@@ -146,7 +155,14 @@ try {
|
||||
default { '' }
|
||||
}
|
||||
$record = @{ Downloads=0; Installs=0; Staged=$null; ManifestReads=0; CliCalls=0; PlanChecks=0 }
|
||||
$messages = & (Join-Path $repo 'rmm/Update-EmberkomCloudBackup.ps1') *>&1
|
||||
# PowerShell 4 writes Write-Host directly to the host. Capture it separately
|
||||
# so log assertions work on 4.0 without mixing text into the core's return value.
|
||||
$record.HostMessages = @()
|
||||
$messages = & {
|
||||
function Write-Host { param([string]$Object) $record.HostMessages += $Object }
|
||||
& (Join-Path $repo 'rmm/Update-EmberkomCloudBackup.ps1') *>&1
|
||||
}
|
||||
$messages = @($messages) + $record.HostMessages
|
||||
if ($LASTEXITCODE -ne $expected -or $record.Downloads -ne $expectedDownloads -or $record.Installs -ne $expectedInstalls) {
|
||||
throw "$scenario failed. Exit=$LASTEXITCODE Downloads=$($record.Downloads) Installs=$($record.Installs). $messages"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user