Backup EnginebackupEngine
Docs/CLI Reference/Scripting & Automation

Scripting & Automation

Run BackupEngine from RMM tools, CI/CD pipelines, and custom scripts with PowerShell and bash, using the exit codes and --json output the CLI really has.

What a Script Can Rely On

The backupengine command is the desktop agent itself, so a script drives the same sets, settings and signed-in session as the app. Everything below uses only commands that exist; the Command Reference lists all of them.

  • •Exit codes: 0 means success and 1 means the command failed, was given bad arguments or could not tell. Exceptions: gui-status answers 0 / 10 / 11 / 12, usage-report send exits 2 when some recipients failed, and selftest exits 2 when a suite was skipped or blocked.
  • •backup start has no --wait flag because it already waits: it runs the backup in your console and returns when every destination has finished. It runs file backup sets; Hyper-V, SQL Server, System State and bare-metal sets run from the app.
  • •--json prints one JSON document for the commands that support it (see the JSON Output page). backup start and restore run print text progress whatever flags you pass.
  • •The command line cannot create or change schedules. Schedules are set in the app or the customer portal, and schedule list reads them.
  • •A backup started with backup start is not added to backup list or status, which show runs made by the app and the background service. Read its result from the exit code, or from last_run and last_run_status in sets list --json.

RMM Integration

Any RMM tool that can run a PowerShell script as SYSTEM or an administrator can install the agent silently, enroll the computer and then check on it. Enrollment uses an activation code, not a password, so nobody has to sign in or type an MFA code on the machine. Create the code under Device enrollment codes in the customer portal (see Device Enrollment Codes), and make it a multi-use code when you are pushing the script to many computers.

Silent install, enroll and verify (PowerShell, run as administrator)
# 1. Stage the activation code where the agent looks for it on first start
$dir = Join-Path $env:ProgramData 'BackupEngine'
New-Item -ItemType Directory -Force -Path $dir | Out-Null
@{ code = $env:BE_ACTIVATION_CODE } | ConvertTo-Json -Compress | Set-Content -Path (Join-Path $dir 'pending_enrollment.json')
icacls $dir /grant '*S-1-5-32-545:(OI)(CI)M' | Out-Null

# 2. Download the installer and run it silently
$exe = Join-Path $env:TEMP 'BackupEngineSetup.exe'
Invoke-WebRequest -Uri 'https://downloads.backupengine.com/latest/windows/backup-engine-windows.exe' -OutFile $exe
Start-Process -FilePath $exe -ArgumentList '/VERYSILENT','/SUPPRESSMSGBOXES','/NORESTART' -Wait

# 3. Check that the computer enrolled. A shell opened before the install does not have the
#    new PATH entry yet, so call the shim by its full path.
$be = Join-Path $env:ProgramFiles 'Backup Engine\backupengine.cmd'
$status = & $be status --json | ConvertFrom-Json
if ($status.device_id) {
    Write-Host "Enrolled as $($status.email), device $($status.device_id)"
} else {
    Write-Host 'Not enrolled yet: check the activation code and run again.'
    exit 1
}
  • •To enroll an agent that is already installed, run backupengine enroll --code XXXX-XXXX-XXXX. It prints status, message, email and device_id (as JSON with --json) and exits 1 when the code is refused.
  • •The agent keeps its configuration in one database that the app, the background service and the command line share, so a script running as SYSTEM sees the same sets and settings as the signed-in user.
  • •While the app asks for sign-in (Stay signed in off, or required by your organization), commands that restore data or change settings need an elevated prompt. RMM scripts run elevated, so they are not affected.

ℹ Note

The installer puts the install folder on the machine PATH, so backupengine works in any new console. Today the pre-built agent is for Windows; see Installation for the status of the macOS and Linux builds.

CI/CD Pipeline Integration

Use BackupEngine in a pipeline stage that runs on a Windows computer where the agent is installed and signed in, for example a self-hosted runner, to back up build artifacts or configuration files before a deployment. The stage fails when the backup fails because backup start returns exit code 1. A database dump can go in the same stage: write it into a folder that a file backup set covers, then back that set up.

GitHub Actions example (self-hosted Windows runner)
# .github/workflows/backup.yml
name: Back up before deploy
on:
  workflow_dispatch:
  push:
    branches: [main]

jobs:
  backup:
    # A Windows computer that has Backup Engine installed and signed in
    runs-on: [self-hosted, windows]
    steps:
      - name: Back up the release folder
        shell: powershell
        run: |
          backupengine backup start "Release Artifacts"
          if ($LASTEXITCODE -ne 0) { throw "Backup failed (exit code $LASTEXITCODE)" }

      - name: Show the result
        shell: powershell
        run: |
          $sets = (backupengine sets list --json | ConvertFrom-Json).sets
          $set = $sets | Where-Object { $_.name -eq "Release Artifacts" }
          Write-Host "Last run: $($set.last_run) ($($set.last_run_status))"

      - name: Deploy application
        run: |
          echo "Deploying after a successful backup..."

PowerShell Scripts

PowerShell is the recommended scripting language on Windows. The --json flag works with ConvertFrom-Json for structured data processing. sets list --json gives every set with its enabled flag (1 or 0), last_run (local time) and last_run_status (completed, failed or cancelled), which is what a health check needs.

Monitor backup health (PowerShell)
# Mail an alert for every enabled set whose last run failed or that has not run for 26 hours
$sets = (backupengine sets list --json | ConvertFrom-Json).sets

foreach ($set in $sets | Where-Object { $_.enabled -eq 1 }) {
    $stale = (-not $set.last_run) -or (([datetime]$set.last_run) -lt (Get-Date).AddHours(-26))

    if ($set.last_run_status -eq "failed" -or $stale) {
        $subject = "BackupEngine alert: $($set.name) on $env:COMPUTERNAME"
        $body = "Backup set '$($set.name)': last run $($set.last_run), status $($set.last_run_status)."
        Send-MailMessage -To "admin@company.com" -From "backup@company.com" `
            -Subject $subject -Body $body -SmtpServer "smtp.company.com"
    }
}
Check the schedules and the connection (PowerShell)
# What is each set scheduled to do? (read-only)
(backupengine schedule list --json | ConvertFrom-Json).schedules |
    Select-Object name, enabled, summary, last_run

# Can this computer reach BackupEngine Cloud? Exit code 0 = yes
backupengine connectivity test
if ($LASTEXITCODE -ne 0) { Write-Host "Connectivity test failed" }

Bash Scripts

Bash scripts can use jq for JSON parsing and run wherever the backupengine command is on the PATH, for example Git Bash on a Windows server. A pre-built Mac or Linux agent is not in the current distribution yet (see Installation), so the Windows agent is what these scripts drive today.

Pre-backup database dump (bash)
#!/bin/bash
set -euo pipefail

SET_NAME="Server Data"

# Dump the database into a folder that the backup set covers
echo "Dumping PostgreSQL database..."
pg_dump -h localhost -U app_user -d production > /backup/staging/db_dump.sql

# Run the backup set. This blocks until the backup is finished; the exit code is the result.
echo "Starting backup..."
if backupengine backup start "$SET_NAME"; then
    echo "Backup completed successfully"
    backupengine sets list --json | jq -r --arg n "$SET_NAME" \
        '.sets[] | select(.name == $n) | "Last run: \(.last_run) (\(.last_run_status))"'
else
    echo "Backup failed!" >&2
    # Show the end of the newest diagnostic log of this set
    SET_ID=$(backupengine sets list --json | jq -r --arg n "$SET_NAME" '.sets[] | select(.name == $n) | .id')
    LOG=$(backupengine logs list "$SET_ID" --json | jq -r '.logs[0].path')
    backupengine logs show "$LOG" | tail -n 20
    exit 1
fi

💡 Tip

To cap how fast a scripted backup uploads, set a per-set limit first with backupengine sets bandwidth "Server Data" 5000 (kilobits per second). See Bandwidth Throttling.