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

+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