Add backend api #1

Manually merged
kyle merged 5 commits from add-backend-api into main 2026-10-07 15:00:07 -06:00
2 changed files with 39 additions and 9 deletions
Showing only changes of commit ba798284df - Show all commits
+30 -6
View File
@@ -7,7 +7,9 @@
matters because it runs as SYSTEM). matters because it runs as SYSTEM).
- Writes the config to ProgramData\BackupDashboard and restricts that folder to SYSTEM and - Writes the config to ProgramData\BackupDashboard and restricts that folder to SYSTEM and
Administrators, since it contains the API key. Administrators, since it contains the API key.
- Registers a scheduled task that runs every IntervalMinutes. - Registers a scheduled task that runs every IntervalMinutes under PowerShell 7 (pwsh.exe),
which the Veeam module on VBR 13 expects. Install PowerShell 7 machine-wide (MSI or winget)
first: Microsoft Store installs can't be run by SYSTEM.
Safe to re-run to change settings or update the script. Safe to re-run to change settings or update the script.
.EXAMPLE .EXAMPLE
@@ -22,7 +24,9 @@ param(
[string]$SourceSystem = 'Veeam B&R', [string]$SourceSystem = 'Veeam B&R',
[ValidateRange(5, 1440)][int]$IntervalMinutes = 15, [ValidateRange(5, 1440)][int]$IntervalMinutes = 15,
[ValidateRange(1, 720)][int]$LookbackHours = 48, [ValidateRange(1, 720)][int]$LookbackHours = 48,
[string]$InstallDir = (Join-Path $env:ProgramFiles 'BackupDashboard') [string]$InstallDir = (Join-Path $env:ProgramFiles 'BackupDashboard'),
# Defaults to the machine-wide PowerShell 7 install
[string]$PwshPath
) )
$ErrorActionPreference = 'Stop' $ErrorActionPreference = 'Stop'
@@ -30,6 +34,26 @@ $TaskName = 'Backup Dashboard - Veeam collector'
$DataDir = Join-Path $env:ProgramData 'BackupDashboard' $DataDir = Join-Path $env:ProgramData 'BackupDashboard'
$ConfigPath = Join-Path $DataDir 'veeam-collector.json' $ConfigPath = Join-Path $DataDir 'veeam-collector.json'
# Find PowerShell 7 before changing anything, so a missing install fails cleanly
if (-not $PwshPath) {
$PwshPath = Join-Path $env:ProgramFiles 'PowerShell\7\pwsh.exe'
if (-not (Test-Path $PwshPath)) {
$onPath = Get-Command pwsh.exe -ErrorAction SilentlyContinue
if ($onPath) { $PwshPath = $onPath.Source }
}
}
if (-not (Test-Path $PwshPath)) {
throw "PowerShell 7 not found at '$PwshPath'. Install it machine-wide (e.g. winget install Microsoft.PowerShell) or pass -PwshPath."
}
if ($PwshPath -match '\\WindowsApps\\') {
throw "'$PwshPath' is a Microsoft Store install, which the SYSTEM account can't run. Install the MSI or winget version instead."
}
$pwshVersion = & $PwshPath -NoProfile -NonInteractive -Command '$PSVersionTable.PSVersion.ToString()'
$pwshMajor = & $PwshPath -NoProfile -NonInteractive -Command '$PSVersionTable.PSVersion.Major'
if ($LASTEXITCODE -or ($pwshMajor -as [int]) -lt 7) {
throw "'$PwshPath' isn't a working PowerShell 7 (reported '$pwshVersion')."
}
if ($ApiUrl -notmatch '^https://') { if ($ApiUrl -notmatch '^https://') {
Write-Warning 'ApiUrl is not HTTPS: the API key would be sent in clear text.' Write-Warning 'ApiUrl is not HTTPS: the API key would be sent in clear text.'
} }
@@ -59,7 +83,7 @@ $scriptPath = Join-Path $InstallDir 'Send-VeeamBackupStatus.ps1'
Copy-Item -Path (Join-Path $PSScriptRoot 'Send-VeeamBackupStatus.ps1') -Destination $scriptPath -Force Copy-Item -Path (Join-Path $PSScriptRoot 'Send-VeeamBackupStatus.ps1') -Destination $scriptPath -Force
Unblock-File -Path $scriptPath Unblock-File -Path $scriptPath
$action = New-ScheduledTaskAction -Execute 'powershell.exe' ` $action = New-ScheduledTaskAction -Execute $PwshPath `
-Argument "-NoProfile -NonInteractive -ExecutionPolicy Bypass -File `"$scriptPath`"" -Argument "-NoProfile -NonInteractive -ExecutionPolicy Bypass -File `"$scriptPath`""
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(1) ` $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(1) `
-RepetitionInterval (New-TimeSpan -Minutes $IntervalMinutes) -RepetitionInterval (New-TimeSpan -Minutes $IntervalMinutes)
@@ -70,9 +94,9 @@ Register-ScheduledTask -TaskName $TaskName -Action $action -Trigger $trigger -Pr
-Settings $settings -Description 'Sends Veeam job results to the Backup Dashboard' -Force | Out-Null -Settings $settings -Description 'Sends Veeam job results to the Backup Dashboard' -Force | Out-Null
Write-Host "Installed. Config: $ConfigPath" Write-Host "Installed. Config: $ConfigPath"
Write-Host "Task '$TaskName' runs every $IntervalMinutes minutes as SYSTEM." Write-Host "Task '$TaskName' runs every $IntervalMinutes minutes as SYSTEM, using PowerShell $pwshVersion ($PwshPath)."
Write-Host '' Write-Host ''
Write-Host 'Next steps:' Write-Host 'Next steps:'
Write-Host " 1. Preview what will be sent: & '$scriptPath' -DryRun" Write-Host " 1. Preview what will be sent: & '$PwshPath' -File '$scriptPath' -DryRun"
Write-Host " 2. Backfill 30 days of history: & '$scriptPath' -LookbackHours 720" Write-Host " 2. Backfill 30 days of history: & '$PwshPath' -File '$scriptPath' -LookbackHours 720"
Write-Host " 3. Check the log: Get-Content '$DataDir\veeam-collector.log' -Tail 20" Write-Host " 3. Check the log: Get-Content '$DataDir\veeam-collector.log' -Tail 20"
+9 -3
View File
@@ -5,19 +5,25 @@ It covers jobs returned by `Get-VBRJob`: VM backup, replication and backup copy
## Install (on the VBR server, as an administrator) ## Install (on the VBR server, as an administrator)
Requires PowerShell 7 installed machine-wide (`winget install Microsoft.PowerShell` or the MSI),
which VBR 13's Veeam module expects. The Microsoft Store version won't work, because the SYSTEM
account can't run it. The installer checks for this before changing anything.
1. On the dashboard host, create a key for this server: 1. On the dashboard host, create a key for this server:
```bash ```bash
python manage.py create-key veeam-acme python manage.py create-key veeam-acme
``` ```
2. Copy this folder to the VBR server and run: 2. Copy this folder to the VBR server and run, from PowerShell 7 (`pwsh`):
```powershell ```powershell
.\Install-VeeamCollector.ps1 -ApiUrl https://backups.example.com -Tenant "Acme Corp" .\Install-VeeamCollector.ps1 -ApiUrl https://backups.example.com -Tenant "Acme Corp"
``` ```
It prompts for the key, then: It prompts for the key, then:
- writes `C:\ProgramData\BackupDashboard\veeam-collector.json` (readable only by SYSTEM and Administrators) - writes `C:\ProgramData\BackupDashboard\veeam-collector.json` (readable only by SYSTEM and Administrators)
- copies the script to `C:\Program Files\BackupDashboard\` - copies the script to `C:\Program Files\BackupDashboard\`
- registers the scheduled task **Backup Dashboard - Veeam collector** (SYSTEM, every 15 minutes) - registers the scheduled task **Backup Dashboard - Veeam collector** (SYSTEM, every 15 minutes,
3. Preview the payloads, then backfill 30 days so the history view is populated straight away: run by `C:\Program Files\PowerShell\7\pwsh.exe`; use `-PwshPath` if it's installed elsewhere)
3. Preview the payloads, then backfill 30 days so the history view is populated straight away
(from `pwsh`):
```powershell ```powershell
& 'C:\Program Files\BackupDashboard\Send-VeeamBackupStatus.ps1' -DryRun & 'C:\Program Files\BackupDashboard\Send-VeeamBackupStatus.ps1' -DryRun
& 'C:\Program Files\BackupDashboard\Send-VeeamBackupStatus.ps1' -LookbackHours 720 & 'C:\Program Files\BackupDashboard\Send-VeeamBackupStatus.ps1' -LookbackHours 720