diff --git a/hosts/llm-node/scripts/db-shinkan-prod.sh b/hosts/llm-node/scripts/db-shinkan-prod.sh index 721acbf..99d4eb0 100644 --- a/hosts/llm-node/scripts/db-shinkan-prod.sh +++ b/hosts/llm-node/scripts/db-shinkan-prod.sh @@ -43,7 +43,8 @@ chmod 0640 "${DUMP_FILE}" echo "2. Erstelle Manifest, SHA256 und Medien-Index..." MANIFEST_SCRIPT="/etc/backup-orchestrator/scripts/shinkan/shinkan-backup-manifest" if [[ ! -f "$MANIFEST_SCRIPT" ]]; then - MANIFEST_SCRIPT="$(dirname "${BASH_SOURCE[0]}")/../../scripts/shinkan/shinkan-backup-manifest" + REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)" + MANIFEST_SCRIPT="${REPO_ROOT}/scripts/shinkan/shinkan-backup-manifest" fi python3 "${MANIFEST_SCRIPT}" \ @@ -55,7 +56,8 @@ python3 "${MANIFEST_SCRIPT}" \ echo "3. Veroeffentliche Backup-Set im Recovery-Archiv..." PUBLISH_SCRIPT="/etc/backup-orchestrator/scripts/publish-backup-set.sh" if [[ ! -f "$PUBLISH_SCRIPT" ]]; then - PUBLISH_SCRIPT="$(dirname "${BASH_SOURCE[0]}")/../../scripts/common/publish-backup-set.sh" + REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)" + PUBLISH_SCRIPT="${REPO_ROOT}/scripts/common/publish-backup-set.sh" fi bash "${PUBLISH_SCRIPT}" \ diff --git a/orchestrator.py b/orchestrator.py index d673131..b0d1f77 100644 --- a/orchestrator.py +++ b/orchestrator.py @@ -290,8 +290,25 @@ def legacy_schedules(host_cfg=None): return found -def script_issues(job): +def resolve_job_script(job, host_name=None): p = Path(job['script']) + if p.is_file(): + return p + repo_root = Path(__file__).resolve().parent + script_name = p.name + host = host_name or socket.gethostname() + for c in ( + repo_root / 'hosts' / host / 'scripts' / script_name, + repo_root / 'scripts' / 'common' / script_name, + repo_root / 'scripts' / script_name, + ): + if c.is_file(): + return c + return p + + +def script_issues(job, host_name=None): + p = resolve_job_script(job, host_name) if not p.is_file(): return ['MISSING'] issues = [] @@ -313,7 +330,7 @@ def check(jobs, max_parallel, notify, host_cfg=None): print(f'Backup-Orchestrator {VERSION} (host={cfg.get("hostname", socket.gethostname())}): INSPECTION ONLY (no backups, no schedule changes)') print(f'Parallel limit per phase: {max_parallel}') for job in jobs: - issues = script_issues(job) + issues = script_issues(job, cfg.get('hostname')) state = 'enabled' if job['enabled'] else 'disabled' print(f"phase {job['phase']:>2} {job['id']:<24} {state:<8} {job['timeout_seconds']:>5}s {job['script']} [{', '.join(issues) if issues else 'OK'}]") conflicts = legacy_schedules(cfg) @@ -543,12 +560,13 @@ def execute_one(job, folder, hub): hub.emit('JOB_CANCELLED', **result) return result hub.emit('JOB_STARTED', job=job['id'], phase=job['phase'], critical=job['critical'], state='running') + resolved_script = resolve_job_script(job) with logfile.open('wb') as stream: stream.write((f"job={job['id']} started={now_iso()}\n").encode()) stream.flush() try: - proc = subprocess.Popen(_build_script_cmd(job['script']), stdout=stream, stderr=subprocess.STDOUT, - start_new_session=True, cwd=str(Path(job['script']).parent)) + proc = subprocess.Popen(_build_script_cmd(resolved_script), stdout=stream, stderr=subprocess.STDOUT, + start_new_session=True, cwd=str(resolved_script.parent)) except OSError as exc: stream.write((f'EXEC ERROR: {exc}\n').encode()) result = result_for(job, 'error', 127, time.monotonic()-start, logfile, 'Could not start script') @@ -1490,17 +1508,24 @@ def main(): parser.add_argument('--keep', action='store_true', help='Keep isolated test environment running after --restore-test') args = parser.parse_args() - if args.host: - host_dir = resolve_repo_host_dir(args.host) - if not host_dir: - parser.error(f'Unknown host profile: {args.host!r}') - if args.config == DEFAULT_CONFIG: + host_name = args.host or socket.gethostname() + host_dir = resolve_repo_host_dir(host_name) + if args.host and not host_dir: + parser.error(f'Unknown host profile: {args.host!r}') + if host_dir: + if args.config == DEFAULT_CONFIG and not DEFAULT_CONFIG.is_file(): args.config = host_dir / 'jobs.csv' - if args.notify_config == DEFAULT_NOTIFY_CONFIG and (host_dir / 'notifications.json.example').is_file(): + if args.notify_config == DEFAULT_NOTIFY_CONFIG and not DEFAULT_NOTIFY_CONFIG.is_file() and (host_dir / 'notifications.json.example').is_file(): args.notify_config = host_dir / 'notifications.json.example' - if args.targets_config == DEFAULT_TARGETS_CONFIG and (host_dir / 'targets.json').is_file(): + if args.targets_config == DEFAULT_TARGETS_CONFIG and not DEFAULT_TARGETS_CONFIG.is_file() and (host_dir / 'targets.json').is_file(): args.targets_config = host_dir / 'targets.json' + # Fallback to user directories if /var/log or /run/lock are not writable + if args.log_root == DEFAULT_LOG_ROOT and not os.access('/var/log', os.W_OK) and not DEFAULT_LOG_ROOT.is_dir(): + args.log_root = Path.home() / '.local' / 'share' / 'backup-orchestrator' / 'logs' + if args.lock_file == DEFAULT_LOCK_FILE and not os.access('/run/lock', os.W_OK) and not DEFAULT_LOCK_FILE.is_file(): + args.lock_file = Path.home() / '.local' / 'share' / 'backup-orchestrator' / 'lock' + if not 1 <= args.max_parallel <= 16: parser.error('--max-parallel must be 1..16') json_capable = (