fix: resolve job scripts from repo when not installed to /etc

This commit is contained in:
Lars committed 2026-10-29 21:41:55 +01:00
1 parent 03e09fd0d0
commit 6882fe397c
2 files changed
+40 -13

No files matched your search

+4 -2
View File
@@ -43,7 +43,8 @@ chmod 0640 "${DUMP_FILE}"
echo "2. Erstelle Manifest, SHA256 und Medien-Index..." echo "2. Erstelle Manifest, SHA256 und Medien-Index..."
MANIFEST_SCRIPT="/etc/backup-orchestrator/scripts/shinkan/shinkan-backup-manifest" MANIFEST_SCRIPT="/etc/backup-orchestrator/scripts/shinkan/shinkan-backup-manifest"
if [[ ! -f "$MANIFEST_SCRIPT" ]]; then 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 fi
python3 "${MANIFEST_SCRIPT}" \ python3 "${MANIFEST_SCRIPT}" \
@@ -55,7 +56,8 @@ python3 "${MANIFEST_SCRIPT}" \
echo "3. Veroeffentliche Backup-Set im Recovery-Archiv..." echo "3. Veroeffentliche Backup-Set im Recovery-Archiv..."
PUBLISH_SCRIPT="/etc/backup-orchestrator/scripts/publish-backup-set.sh" PUBLISH_SCRIPT="/etc/backup-orchestrator/scripts/publish-backup-set.sh"
if [[ ! -f "$PUBLISH_SCRIPT" ]]; then 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 fi
bash "${PUBLISH_SCRIPT}" \ bash "${PUBLISH_SCRIPT}" \
+36 -11
View File
@@ -290,8 +290,25 @@ def legacy_schedules(host_cfg=None):
return found return found
def script_issues(job): def resolve_job_script(job, host_name=None):
p = Path(job['script']) 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(): if not p.is_file():
return ['MISSING'] return ['MISSING']
issues = [] 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'Backup-Orchestrator {VERSION} (host={cfg.get("hostname", socket.gethostname())}): INSPECTION ONLY (no backups, no schedule changes)')
print(f'Parallel limit per phase: {max_parallel}') print(f'Parallel limit per phase: {max_parallel}')
for job in jobs: for job in jobs:
issues = script_issues(job) issues = script_issues(job, cfg.get('hostname'))
state = 'enabled' if job['enabled'] else 'disabled' 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'}]") 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) conflicts = legacy_schedules(cfg)
@@ -543,12 +560,13 @@ def execute_one(job, folder, hub):
hub.emit('JOB_CANCELLED', **result) hub.emit('JOB_CANCELLED', **result)
return result return result
hub.emit('JOB_STARTED', job=job['id'], phase=job['phase'], critical=job['critical'], state='running') 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: with logfile.open('wb') as stream:
stream.write((f"job={job['id']} started={now_iso()}\n").encode()) stream.write((f"job={job['id']} started={now_iso()}\n").encode())
stream.flush() stream.flush()
try: try:
proc = subprocess.Popen(_build_script_cmd(job['script']), stdout=stream, stderr=subprocess.STDOUT, proc = subprocess.Popen(_build_script_cmd(resolved_script), stdout=stream, stderr=subprocess.STDOUT,
start_new_session=True, cwd=str(Path(job['script']).parent)) start_new_session=True, cwd=str(resolved_script.parent))
except OSError as exc: except OSError as exc:
stream.write((f'EXEC ERROR: {exc}\n').encode()) stream.write((f'EXEC ERROR: {exc}\n').encode())
result = result_for(job, 'error', 127, time.monotonic()-start, logfile, 'Could not start script') 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') parser.add_argument('--keep', action='store_true', help='Keep isolated test environment running after --restore-test')
args = parser.parse_args() args = parser.parse_args()
if args.host: host_name = args.host or socket.gethostname()
host_dir = resolve_repo_host_dir(args.host) host_dir = resolve_repo_host_dir(host_name)
if not host_dir: if args.host and not host_dir:
parser.error(f'Unknown host profile: {args.host!r}') parser.error(f'Unknown host profile: {args.host!r}')
if args.config == DEFAULT_CONFIG: if host_dir:
if args.config == DEFAULT_CONFIG and not DEFAULT_CONFIG.is_file():
args.config = host_dir / 'jobs.csv' 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' 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' 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: if not 1 <= args.max_parallel <= 16:
parser.error('--max-parallel must be 1..16') parser.error('--max-parallel must be 1..16')
json_capable = ( json_capable = (