Documentation - Three levels: DOCS/General (overview, configuration), DOCS/Deployment (choose a method, first steps), details per method in Containers/ and System_Services/; new root README and DOCS/README map. - Remove superseded pages (Deployment.md, Deployment_Docker/Native.md, Index.md); split the two scenario guides by section. - Isolate the Timeweb/Hysteria2 records in DEPLOYMENTS/timeweb-hysteria2/ (not linked from DOCS, listed in .graphifyignore). - Add DOCS/code_review/ with a time-stamped analysis of the code base. Gatherer (BUG-02, BUG-03) - Session key (CN, address, connected_since_ts), baseline from the active_sessions snapshot, grace period for sessions missing from the status. - Status file integrity (TITLE/TIME/END) and freshness; a torn read skips the tick. - Cache applied after commit; main loop survives exceptions, backs off, and stops cleanly on SIGTERM/SIGINT; new client rows start with the first frame's totals; five tests. JWT signing key (SEC-01) - No built-in default: Core and Profiler refuse to start with a missing, placeholder or short (< 32) key; shipped config.ini has an empty value. - Same rule in install.sh, update.sh (issues a new key when missing or weak), docker lib/entrypoint; five tests, conftest.py for the test key. Each change has a plan and a summary under DOCS/Changes/. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
92 lines
3.9 KiB
Bash
Executable File
92 lines
3.9 KiB
Bash
Executable File
#!/bin/sh
|
|
# Restore an installation from a backup directory (made by backup.sh or update.sh).
|
|
#
|
|
# deploy/native/restore.sh BACKUP_DIR [--prefix DIR] [--yes] [--start]
|
|
#
|
|
# BACKUP_DIR e.g. /var/backups/ovpmon/20261005T101500Z
|
|
# --prefix install directory (default: from /etc/ovpmon/deploy.state, else /opt/OpenVPN-Monitoring-Simple)
|
|
# --start start the services after the restore (default: only print the command)
|
|
#
|
|
# The application services are stopped (after confirmation). The CURRENT state is first saved to
|
|
# <backups>/<timestamp>-pre-restore (OVPMON_NO_SAFETY_BACKUP=1 skips it); then code, databases,
|
|
# /etc/ovpmon, /etc/openvpn, PKI, client profiles, helper, service definitions, nginx site, UI and doas
|
|
# rules are put back from the backup. OpenVPN is not touched. The packages and the ovpmon user must
|
|
# exist (on a new host run install.sh first, then restore).
|
|
# See DOCS/Deployment/System_Services/README.md
|
|
set -eu
|
|
|
|
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
|
. "$SCRIPT_DIR/lib.sh"
|
|
|
|
usage() {
|
|
sed -n '2,15p' "$0" | sed 's/^# \{0,1\}//'
|
|
}
|
|
|
|
PREFIX=""
|
|
ASSUME_YES=0
|
|
START=0
|
|
SRC=""
|
|
FORCE=1
|
|
RESTORE_STAMP=$(stamp)
|
|
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--prefix) [ $# -ge 2 ] || die "--prefix needs a value"; PREFIX="$2"; shift 2 ;;
|
|
--yes|-y) ASSUME_YES=1; shift ;;
|
|
--start) START=1; shift ;;
|
|
-h|--help) usage; exit 0 ;;
|
|
-*) usage >&2; die "unknown option: $1" ;;
|
|
*) [ -z "$SRC" ] || die "only one backup directory can be given"; SRC="$1"; shift ;;
|
|
esac
|
|
done
|
|
[ -n "$SRC" ] || { usage >&2; die "BACKUP_DIR is required"; }
|
|
[ -d "$SRC" ] || die "not a directory: $SRC"
|
|
SRC=$(abs_dir "$SRC")
|
|
|
|
trap release_lock EXIT
|
|
trap 'exit 130' INT
|
|
trap 'exit 143' TERM
|
|
need_root
|
|
check_os
|
|
require_init
|
|
check_gnu_tar
|
|
acquire_lock
|
|
|
|
[ -n "$PREFIX" ] || PREFIX=$(state_get OVPMON_PREFIX)
|
|
[ -n "$PREFIX" ] || PREFIX=$(manifest_get "$SRC" prefix)
|
|
[ -n "$PREFIX" ] || PREFIX="$DEFAULT_PREFIX"
|
|
valid_prefix "$PREFIX" || die "invalid install directory '$PREFIX'"
|
|
getent passwd "$SERVICE_USER" >/dev/null 2>&1 || die "user $SERVICE_USER does not exist: run install.sh first"
|
|
|
|
BK_PREFIX=$(manifest_get "$SRC" prefix)
|
|
if [ -n "$BK_PREFIX" ] && [ "$BK_PREFIX" != "$PREFIX" ]; then
|
|
die "the backup was made for install directory '$BK_PREFIX', this host uses '$PREFIX' (use --prefix $BK_PREFIX)"
|
|
fi
|
|
log "backup: $SRC"
|
|
[ -f "$SRC/MANIFEST" ] && sed 's/^/ /' "$SRC/MANIFEST"
|
|
[ -f "$SRC/COMPLETE" ] || warn "the backup is not marked COMPLETE (an interrupted backup?)"
|
|
[ "$(manifest_get "$SRC" init)" = "$INIT" ] || warn "the backup comes from a host with service manager '$(manifest_get "$SRC" init)', this one uses '$INIT': service definitions and the helper configuration are restored as saved"
|
|
log "verifying the backup"
|
|
verify_backup "$SRC" || die "the backup is damaged or incomplete: nothing was changed"
|
|
|
|
log "code, databases, configuration, PKI and client profiles will be REPLACED by this backup (the current state is saved first)"
|
|
confirm "Stop the services and restore?" || die "aborted by the user"
|
|
|
|
stop_app_services || die "could not stop the application services"
|
|
if [ "${OVPMON_NO_SAFETY_BACKUP:-0}" != 1 ]; then
|
|
_safe="$BACKUP_ROOT/$(stamp)-pre-restore"
|
|
log "saving the current state first: $_safe"
|
|
mkdir -p "$BACKUP_ROOT"; chmod 700 "$BACKUP_ROOT"
|
|
make_backup "$_safe" pre-restore "$PREFIX" || die "the safety backup failed: nothing was changed"
|
|
fi
|
|
restore_all "$SRC" "$PREFIX" full || die "the restore failed (see above). The backup is intact: $SRC"
|
|
log "restore complete"
|
|
|
|
if [ "$START" = 1 ]; then
|
|
svc_defs_reload || true
|
|
start_app_services || die "the services did not start after the restore"
|
|
health_check "$(state_get OVPMON_HTTPS_PORT)" || die "the health checks failed after the restore"
|
|
else
|
|
log "start the services when ready: $(for _s in $SERVICES; do printf '%s ' "$_s"; done)(rc-service <name> start / systemctl start <name>)"
|
|
fi
|