Deploy scripts: compose version check, ovpmon_backup.db in native backups

Docker: variant B needs Docker Compose 2.17+ (additional_contexts); install.sh
and update.sh check it in the preflight. Native: backup.sh, update.sh,
restore.sh and --rollback now copy and restore ovpmon_backup.db (Backup and
Restore settings) as an optional file. Verified install, update, backup,
restore and rollback on Debian 12 (systemd), Alpine 3.23 (OpenRC) and both
container variants.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ayurishchevandClaude Sonnet 5.5 committed 2026-10-07 12:58:42 +03:00
1 parent f8cdcd0fc6
commit 3fac8d70d8
11 files changed
+178 -7

No files matched your search

+1
View File
@@ -59,6 +59,7 @@ trap 'exit 143' TERM
# ---------------------------------------------------------------------------------------------
phase 0 "preflight"
need_docker
need_compose_version
log "docker compose command: $DC_BIN; variant $VARIANT; project $PROJECT"
check_other_variant_stopped
check_name_clash
+39
View File
@@ -63,6 +63,45 @@ need_docker() {
fi
}
# Variant B (docker-compose.yml) uses additional_contexts: Docker Compose v2.17.0 or newer
MIN_COMPOSE_VERSION="2.17.0"
# version_ge FOUND REQUIRED: pure comparison of MAJOR.MINOR[.PATCH] versions, no docker involved.
# A leading 'v' and any suffix after the numbers (-desktop.1, +build, -rc1) are ignored.
# Returns 0 if FOUND >= REQUIRED, 1 if FOUND < REQUIRED, 2 if either value cannot be parsed.
version_ge() {
local f r fa fb fc ra rb rc
f=$(printf '%s' "$1" | sed -n 's/^[vV]\{0,1\}\([0-9][0-9]*\)\.\([0-9][0-9]*\)\(\.\([0-9][0-9]*\)\)\{0,1\}.*$/\1 \2 \4/p')
r=$(printf '%s' "$2" | sed -n 's/^[vV]\{0,1\}\([0-9][0-9]*\)\.\([0-9][0-9]*\)\(\.\([0-9][0-9]*\)\)\{0,1\}.*$/\1 \2 \4/p')
[ -n "$f" ] && [ -n "$r" ] || return 2
set -- $f; fa=$1; fb=$2; fc=${3:-0}
set -- $r; ra=$1; rb=$2; rc=${3:-0}
[ "$fa" -gt "$ra" ] && return 0
[ "$fa" -lt "$ra" ] && return 1
[ "$fb" -gt "$rb" ] && return 0
[ "$fb" -lt "$rb" ] && return 1
[ "$fc" -ge "$rc" ] && return 0
return 1
}
# need_compose_version: variant B needs Docker Compose v2.17+ (additional_contexts). Variant A works
# with any compose. Call after need_docker (DC_BIN) and set_variant (VARIANT).
need_compose_version() {
local v rc
[ "$VARIANT" = b ] || return 0
if [ "$DC_BIN" != "docker compose" ]; then
die "variant B needs the Docker Compose plugin v$MIN_COMPOSE_VERSION or newer ('docker compose', the build uses additional_contexts), but only the legacy 'docker-compose' (v1) was found. Install the plugin (docker-compose-plugin package, see https://docs.docker.com/compose/install/) or use variant A (--variant a), which works with any compose"
fi
v=$(docker compose version --short 2>/dev/null | head -n 1 || true)
rc=0
version_ge "$v" "$MIN_COMPOSE_VERSION" || rc=$?
case "$rc" in
0) log "docker compose version $v (required for variant B: $MIN_COMPOSE_VERSION or newer)" ;;
1) die "variant B needs Docker Compose v$MIN_COMPOSE_VERSION or newer (the build uses additional_contexts), found v${v#v}. Update the Docker Compose plugin (docker-compose-plugin package, see https://docs.docker.com/compose/install/) or use variant A (--variant a), which works with any compose" ;;
*) warn "cannot parse the docker compose version ('$v'); variant B needs v$MIN_COMPOSE_VERSION or newer, continuing without the check" ;;
esac
}
# set_variant a|b: compose file, service and container names of the variant
set_variant() {
case "$1" in
+1
View File
@@ -157,6 +157,7 @@ main() {
CURRENT_PHASE="0 preflight"
phase 0 "preflight"
log "variant $VARIANT, project $PROJECT, compose file $(basename "$COMPOSE_FILE"), docker compose command: $DC_BIN"
need_compose_version
check_env_file
dc config -q || die "the compose configuration is invalid (see the message above)"
check_other_variant_stopped
+23 -3
View File
@@ -434,7 +434,10 @@ run_as_service_user() {
# ---------------------------------------------------------------------------------------------
# Database paths (as the services see them: env file, else the defaults of config.ini)
# ---------------------------------------------------------------------------------------------
# resolve_db_paths PREFIX: DB_MONITOR, DB_PROFILER (absolute)
# resolve_db_paths PREFIX: DB_MONITOR, DB_PROFILER, DB_BACKUPCFG (absolute).
# DB_BACKUPCFG is ovpmon_backup.db of the in-app Backup and Restore feature (destinations, settings,
# encrypted secrets): the app keeps it next to the profiler database (APP_PROFILER/services/backup/store.py,
# no separate override); it may not exist (feature never opened, or an older version).
resolve_db_paths() {
DB_MONITOR=$(env_get OVPMON_OPENVPN_MONITOR_DB_PATH)
DB_PROFILER=$(env_get OVPMON_PROFILER_DB_PATH)
@@ -442,6 +445,7 @@ resolve_db_paths() {
[ -n "$DB_PROFILER" ] || DB_PROFILER="ovpn_profiler.db"
case "$DB_MONITOR" in /*) ;; *) DB_MONITOR="$1/APP_CORE/$DB_MONITOR" ;; esac
case "$DB_PROFILER" in /*) ;; *) DB_PROFILER="$1/APP_PROFILER/$DB_PROFILER" ;; esac
DB_BACKUPCFG="$(dirname "$DB_PROFILER")/ovpmon_backup.db"
}
# users_count DB: rows in the users table (read-only; empty if it cannot be read)
@@ -976,6 +980,7 @@ health_check() {
#
# <BACKUP_ROOT>/<UTC timestamp>/ (mode 700)
# db/monitor.db, db/profiler.db consistent copies (SQLite backup API)
# db/backupcfg.db ovpmon_backup.db (Backup and Restore settings), only if it exists
# etc-ovpmon.tar.gz /etc/ovpmon: env, helper.conf, tls, deploy.state
# etc-openvpn.tar.gz /etc/openvpn: server.conf, crl.pem, scripts, ipp.txt
# easy-rsa.tar.gz, client-config.tar.gz PKI and client profiles (APP_PROFILER/...)
@@ -1063,6 +1068,12 @@ make_backup() {
else
warn "profiler database not found: $DB_PROFILER (not backed up)"; rm -f "$dir/db/profiler.db"
fi
# optional: settings of the in-app Backup and Restore feature (the package folder itself is never copied)
if [ -f "$DB_BACKUPCFG" ]; then
backup_db "$DB_BACKUPCFG" "$dir/db/backupcfg.db" || { log "backup of $DB_BACKUPCFG failed" >&2; return 1; }
else
log " no Backup and Restore settings database ($DB_BACKUPCFG): skipped"; rm -f "$dir/db/backupcfg.db"
fi
log " configuration (/etc/ovpmon, /etc/openvpn)"
[ -d "$ETC_DIR" ] && { mk_tar "$dir/etc-ovpmon.tar.gz" -C / "${ETC_DIR#/}" || return 1; }
@@ -1098,6 +1109,7 @@ make_backup() {
echo "version=$(cat "$prefix/VERSION" 2>/dev/null || echo unknown)"
echo "db_monitor=$DB_MONITOR"
echo "db_profiler=$DB_PROFILER"
echo "db_backupcfg=$DB_BACKUPCFG"
echo "doas_mode=$DOAS_MODE"
echo "doas_file=$DOAS_FILE"
} > "$dir/MANIFEST"
@@ -1110,7 +1122,8 @@ make_backup() {
chmod 600 "$dir/COMPLETE"
}
# verify_backup DIR: checksums, readable archives, database copies pass the integrity check
# verify_backup DIR: checksums, readable archives, database copies (db/*.db, including backupcfg.db) pass
# the integrity check (PRAGMA integrity_check only: no schema or migration checks)
verify_backup() {
local dir f
dir="$1"
@@ -1240,13 +1253,14 @@ restore_db() {
# restore_all DIR PREFIX MODE: see above. Returns non-zero on the first failure.
restore_all() {
local dir prefix mode ts dbm dbp tmp
local dir prefix mode ts dbm dbp dbc tmp
dir="$1"; prefix="$2"; mode="$3"
ts=$(stamp)
[ -n "${RESTORE_STAMP:-}" ] && ts="$RESTORE_STAMP"
verify_backup "$dir" || { log "backup $dir failed verification: nothing was changed" >&2; return 1; }
dbm=$(manifest_get "$dir" db_monitor)
dbp=$(manifest_get "$dir" db_profiler)
dbc=$(manifest_get "$dir" db_backupcfg)
restore_code "$dir" "$prefix" "$mode" "$ts" || return 1
restore_data_dir "$dir" "$prefix" "$mode" easy-rsa.tar.gz easy-rsa || return 1
@@ -1254,6 +1268,12 @@ restore_all() {
[ -z "$dbm" ] || restore_db "$dir/db/monitor.db" "$dbm" "$ts" || return 1
[ -z "$dbp" ] || restore_db "$dir/db/profiler.db" "$dbp" "$ts" || return 1
# optional: a backup of an older version has no copy (and no manifest entry): the live file stays
if [ -n "$dbc" ] && [ -s "$dir/db/backupcfg.db" ]; then
restore_db "$dir/db/backupcfg.db" "$dbc" "$ts" || return 1
else
log " no Backup and Restore settings in this backup: the live file is kept"
fi
log " configuration (/etc/ovpmon, /etc/openvpn)"
tar -xzpf "$dir/etc-ovpmon.tar.gz" -C / || return 1