From 84f35ed26d9ebfeda6d0c3b7fc556a3cb1d68e2b Mon Sep 17 00:00:00 2001 From: KellyMichels Date: Thu, 23 Jul 2026 13:27:09 -0500 Subject: [PATCH] fix: zbackup_ec2/zec2/zec2online require an explicit target (all), matching zbackup These three defaulted to "every project" when run with no arguments - inconsistent with zbackup/zdeploy/zstart/etc. (which show usage), and a surprising amount of work to kick off by accident: zbackup_ec2 pulls a server backup of every project, and zec2online deep-checks everything AND auto-starts any downed stacks. Now a bare invocation prints usage and lists the projects; 'all' does what bare used to. Applied to both the bash and PowerShell versions. --- bash/zbackup_ec2 | 9 ++++++++- bash/zec2 | 8 +++++++- bash/zec2online | 8 +++++++- zbackup_ec2.ps1 | 9 ++++++++- zec2.ps1 | 9 ++++++++- zec2online.ps1 | 9 ++++++++- 6 files changed, 46 insertions(+), 6 deletions(-) diff --git a/bash/zbackup_ec2 b/bash/zbackup_ec2 index be3df82..56bc23d 100644 --- a/bash/zbackup_ec2 +++ b/bash/zbackup_ec2 @@ -7,8 +7,8 @@ # with a "db" config block, plus a zip of server-side data dirs (uploads/archive/dist). # # Usage: -# zbackup_ec2 # every project with a remote.path # zbackup_ec2 [ ...] +# zbackup_ec2 all # every project with a remote.path # # Output: # //__db.sql (projects with a db block) @@ -21,7 +21,14 @@ z_need_config z_require ssh scp projects=("$@") +# Require an explicit target; 'all' pulls every project with a remote.path. if [ "${#projects[@]}" -eq 0 ]; then + printf '\n'; warn "Usage: zbackup_ec2 [ ...] | all" + dim " Projects in zconfig.json: $(zproj_csv)" + dim " 'all' pulls a server backup of every project with a remote.path." + exit 1 +fi +if printf '%s\n' "${projects[@]}" | grep -qx 'all'; then projects=(); while IFS= read -r _zl || [ -n "$_zl" ]; do projects+=("$_zl"); done \ < <(jq -r '.projects | to_entries[] | select((.key | startswith("_") | not) and .value.remote.path != null) | .key' "$ZCONFIG") fi diff --git a/bash/zec2 b/bash/zec2 index a991bee..94d8664 100644 --- a/bash/zec2 +++ b/bash/zec2 @@ -6,8 +6,8 @@ # zec2 — quick reachability check (TCP + HTTP + live build version) for deployed projects. # # Usage: -# zec2 # every project with a "domain" in zconfig.json # zec2 [ ...] +# zec2 all # every project with a "domain" in zconfig.json # zec2 viteapp --host 203.0.113.10 set -uo pipefail @@ -28,6 +28,12 @@ done HOST="${host_override:-$(zec2_ip)}" if [ "${#projects[@]}" -eq 0 ]; then + printf '\n'; warn "Usage: zec2 [ ...] | all [--host ]" + dim " Projects in zconfig.json: $(zproj_csv)" + dim " 'all' checks every project with a 'domain' configured." + exit 1 +fi +if printf '%s\n' "${projects[@]}" | grep -qx 'all'; then projects=(); while IFS= read -r _zl || [ -n "$_zl" ]; do projects+=("$_zl"); done < <(zproj_keys_with_domain) if [ "${#projects[@]}" -eq 0 ]; then warn "No projects with a 'domain' configured in zconfig.json." diff --git a/bash/zec2online b/bash/zec2online index e85c246..31b92e4 100644 --- a/bash/zec2online +++ b/bash/zec2online @@ -7,8 +7,8 @@ # build; auto-start downed stacks via docker compose and stream diagnostics. # # Usage: -# zec2online # every project with a "domain" in zconfig.json # zec2online [ ...] +# zec2online all # every project with a "domain" in zconfig.json # # A plain HTTP-200 check passes even when a stale cached build is live — the # local-vs-server version match is what proves the deployed build is the one running. @@ -32,6 +32,12 @@ HOST="${host_override:-$(zec2_ip)}" EDGE_KEY="$(zedge_key)" if [ "${#projects[@]}" -eq 0 ]; then + printf '\n'; warn "Usage: zec2online [ ...] | all [--host ]" + dim " Projects in zconfig.json: $(zproj_csv)" + dim " 'all' deep-checks every project with a 'domain' (and auto-starts any that are down)." + exit 1 +fi +if printf '%s\n' "${projects[@]}" | grep -qx 'all'; then projects=(); while IFS= read -r _zl || [ -n "$_zl" ]; do projects+=("$_zl"); done < <(zproj_keys_with_domain) if [ "${#projects[@]}" -eq 0 ]; then warn "No projects with a 'domain' configured in zconfig.json." diff --git a/zbackup_ec2.ps1 b/zbackup_ec2.ps1 index ef94029..7d017bd 100644 --- a/zbackup_ec2.ps1 +++ b/zbackup_ec2.ps1 @@ -6,8 +6,8 @@ # with a "db" config block, plus a zip of server-side data dirs (uploads/archive/dist). # # Usage: -# zbackup_ec2 # every project with a remote.path # zbackup_ec2 [ ...] +# zbackup_ec2 all # every project with a remote.path # # Output: # \\__db.sql (projects with a db block) @@ -29,6 +29,13 @@ $RemoteHome = Get-Ec2Home $Ec2BackupRoot = $cfg.paths.backupsEc2 if ($Projects.Count -eq 0) { + Write-Host "" + Write-Host "Usage: zbackup_ec2 [ ...] | all" -ForegroundColor Yellow + Write-Host " Projects in zconfig.json: $((Get-ZProjectKeys) -join ', ')" -ForegroundColor Gray + Write-Host " 'all' pulls a server backup of every project with a remote.path." -ForegroundColor Gray + Stop-ZTracking; exit 1 +} +if ($Projects -contains 'all') { $Projects = @(Get-ZProjectKeys | Where-Object { $cfg.projects.$_.remote -and $cfg.projects.$_.remote.path }) } diff --git a/zec2.ps1 b/zec2.ps1 index 2db49f7..d5ecbe0 100644 --- a/zec2.ps1 +++ b/zec2.ps1 @@ -5,8 +5,8 @@ # zec2.ps1 — quick reachability check (TCP + HTTP + live build version) for deployed projects. # # Usage: -# zec2 # every project with a "domain" in zconfig.json # zec2 [ ...] +# zec2 all # every project with a "domain" in zconfig.json # zec2 viteapp -HostName 203.0.113.10 # param( @@ -23,6 +23,13 @@ $cfg = Get-ZConfig if (-not $HostName) { $HostName = $cfg.ec2.ip } if ($Projects.Count -eq 0) { + Write-Host "" + Write-Host "Usage: zec2 [ ...] | all [-HostName ]" -ForegroundColor Yellow + Write-Host " Projects in zconfig.json: $((Get-ZProjectKeys) -join ', ')" -ForegroundColor Gray + Write-Host " 'all' checks every project with a 'domain' configured." -ForegroundColor Gray + Stop-ZTracking; exit 1 +} +if ($Projects -contains 'all') { $Projects = @(Get-ZProjectKeys | Where-Object { $cfg.projects.$_.domain }) if ($Projects.Count -eq 0) { Write-Host "No projects with a 'domain' configured in zconfig.json." -ForegroundColor Yellow diff --git a/zec2online.ps1 b/zec2online.ps1 index 71e2d4f..4143eea 100644 --- a/zec2online.ps1 +++ b/zec2online.ps1 @@ -6,8 +6,8 @@ # build; auto-start downed stacks via docker compose and stream diagnostics. # # Usage: -# zec2online # every project with a "domain" in zconfig.json # zec2online [ ...] +# zec2online all # every project with a "domain" in zconfig.json # # Verification compares the LOCAL build version against what the server is actually # serving. A plain HTTP-200 check passes even when a stale cached build is live — @@ -30,6 +30,13 @@ $SshTarget = Get-Ec2Target $edgeProj = Get-ZEdgeProject if ($Projects.Count -eq 0) { + Write-Host "" + Write-Host "Usage: zec2online [ ...] | all [-HostName ]" -ForegroundColor Yellow + Write-Host " Projects in zconfig.json: $((Get-ZProjectKeys) -join ', ')" -ForegroundColor Gray + Write-Host " 'all' deep-checks every project with a 'domain' (and auto-starts any that are down)." -ForegroundColor Gray + Stop-ZTracking; exit 1 +} +if ($Projects -contains 'all') { $Projects = @(Get-ZProjectKeys | Where-Object { $cfg.projects.$_.domain }) if ($Projects.Count -eq 0) { Write-Host "No projects with a 'domain' configured in zconfig.json." -ForegroundColor Yellow