made the backup update script fail faster
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#Requires -Version 5.1
|
||||
# Update an existing Emberkom MSP360 Managed Backup agent during an idle RMM window.
|
||||
|
||||
function Get-CloudBackupAgent {
|
||||
function Get-CloudBackupInstallation {
|
||||
# MSP360's managed-agent registration points to the branded uninstall key.
|
||||
# Open the registry view explicitly so a 32-bit RMM host can see a 64-bit agent.
|
||||
$views = if ([Environment]::Is64BitOperatingSystem) { 'Registry64', 'Registry32' } else { 'Registry32' }
|
||||
@@ -15,7 +15,10 @@ function Get-CloudBackupAgent {
|
||||
if (!$product -or !$product.GetValue('')) { throw 'The MSP360 agent registration has no executable path.' }
|
||||
if ($product.GetValue('Publisher') -ne 'Emberkom') { throw 'The registered backup agent belongs to a different publisher.' }
|
||||
$cli = Join-Path (Split-Path -LiteralPath $product.GetValue('')) 'cbb.exe'
|
||||
return (Read-CloudBackupAgent -Cli $cli)
|
||||
return [pscustomobject]@{
|
||||
Cli = $cli
|
||||
Version = [version][Diagnostics.FileVersionInfo]::GetVersionInfo($cli).FileVersion
|
||||
}
|
||||
} finally {
|
||||
if ($product) { $product.Dispose() }
|
||||
if ($marker) { $marker.Dispose() }
|
||||
@@ -25,8 +28,9 @@ function Get-CloudBackupAgent {
|
||||
}
|
||||
|
||||
function Read-CloudBackupAgent {
|
||||
param([string]$Cli)
|
||||
$details = & $Cli ver
|
||||
param($Installation)
|
||||
if (!$Installation) { return }
|
||||
$details = & $Installation.Cli ver
|
||||
if ($LASTEXITCODE -ne 0) { throw "MSP360 could not report the installed agent details (exit $LASTEXITCODE)." }
|
||||
$edition = $service = $null
|
||||
foreach ($line in $details) {
|
||||
@@ -43,7 +47,7 @@ function Read-CloudBackupAgent {
|
||||
}
|
||||
if (!$service) { throw 'MSP360 did not report its backup service name.' }
|
||||
[pscustomobject]@{
|
||||
Version = [version][Diagnostics.FileVersionInfo]::GetVersionInfo($Cli).FileVersion
|
||||
Version = $Installation.Version
|
||||
Build = $build
|
||||
Service = $service
|
||||
}
|
||||
@@ -72,9 +76,17 @@ function Test-CloudBackupPlanRunning {
|
||||
function Invoke-CloudBackupUpdate {
|
||||
param([string]$Window)
|
||||
if (!(Test-CloudBackupUpdateWindow $Window)) { Write-Host "Deferred. Outside the local update window $Window."; return 0 }
|
||||
$agent = Get-CloudBackupAgent
|
||||
if (!$agent) { Write-Host 'Skipped. MSP360 Managed Backup is not installed.'; return 0 }
|
||||
$release = Get-EmberkomCloudBackupRelease -Build $agent.Build
|
||||
$installation = Get-CloudBackupInstallation
|
||||
if (!$installation) { Write-Host 'Skipped. MSP360 Managed Backup is not installed.'; return 0 }
|
||||
$releases = Get-EmberkomCloudBackupReleases
|
||||
# If neither package is newer, the daily check can finish without launching cbb.exe.
|
||||
if ($releases.Count -eq 2 -and $installation.Version -ge [version]$releases.Windows.Version -and
|
||||
$installation.Version -ge [version]$releases.VM.Version) {
|
||||
Write-Host "No update needed. Installed $($installation.Version), published Windows $($releases.Windows.Version), VM $($releases.VM.Version)."
|
||||
return 0
|
||||
}
|
||||
$agent = Read-CloudBackupAgent $installation
|
||||
$release = Get-EmberkomCloudBackupRelease -Build $agent.Build -Releases $releases
|
||||
$target = [version]$release.Version
|
||||
if ($agent.Version -ge $target) {
|
||||
Write-Host "No update needed. Installed $($agent.Version), published $($agent.Build) build $target."
|
||||
@@ -87,7 +99,7 @@ function Invoke-CloudBackupUpdate {
|
||||
Write-Host "Downloading the published $($agent.Build) update from $($agent.Version) to $target."
|
||||
Save-EmberkomCloudBackupInstaller -Release $release -Path $installer
|
||||
# A scheduled plan or the agent's own updater could have started during download.
|
||||
$current = Get-CloudBackupAgent
|
||||
$current = Read-CloudBackupAgent (Get-CloudBackupInstallation)
|
||||
if (!$current -or $current.Build -ne $agent.Build) { throw 'The installed agent changed during download.' }
|
||||
if ($current.Version -ge $target) { Write-Host "Already updated to $($current.Version)."; return 0 }
|
||||
if (!(Test-CloudBackupUpdateWindow $Window)) { Write-Host 'Deferred. The update window ended during download.'; return 0 }
|
||||
@@ -95,7 +107,7 @@ function Invoke-CloudBackupUpdate {
|
||||
$setup = Start-Process -FilePath $installer -ArgumentList '/S' -WindowStyle Hidden -Wait -PassThru -ErrorAction Stop
|
||||
if ($setup.ExitCode -eq 3010) { Write-Host 'MSP360 setup requires a restart to finish. Run the check again after restart.'; return 3010 }
|
||||
if ($setup.ExitCode -ne 0) { throw "MSP360 setup returned exit code $($setup.ExitCode)." }
|
||||
$updated = Get-CloudBackupAgent
|
||||
$updated = Read-CloudBackupAgent (Get-CloudBackupInstallation)
|
||||
if (!$updated -or $updated.Build -ne $agent.Build -or $updated.Version -lt $target) {
|
||||
throw "Setup exited successfully but the installed $($agent.Build) agent could not be verified at $target or newer."
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user