From 7116215477dbdad94cbf85c52bd6940e0104a39c Mon Sep 17 00:00:00 2001 From: Lars Date: Thu, 29 Oct 2026 16:02:37 +0100 Subject: [PATCH] fix(publish): use relative symlink for latest, set 0644 perms, populate rowCounts from dump --- scripts/common/publish-backup-set.sh | 7 +++++- scripts/shinkan/shinkan-backup-manifest | 32 ++++++++++++++++++------- scripts/shinkan/shinkan-restore | 10 ++++++++ 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/scripts/common/publish-backup-set.sh b/scripts/common/publish-backup-set.sh index 3a71b3d..6139c51 100644 --- a/scripts/common/publish-backup-set.sh +++ b/scripts/common/publish-backup-set.sh @@ -55,11 +55,16 @@ if [[ -f "$MEDIA_FILE" ]]; then cp -p -- "$MEDIA_FILE" "$STAGING_DIR/" fi +# Ensure all backup artifacts are readable across hosts (e.g. llmadmin on llm-node) +chmod 0755 "$STAGING_DIR" +chmod 0644 "$STAGING_DIR"/* + mv -T -- "$STAGING_DIR" "$FINAL_DIR" STAGING_DIR="" +# Use relative symlink so the latest link works regardless of mount point path on different hosts TEMP_LINK="$TARGET_DIR/.latest-$$" -ln -s -- "$FINAL_DIR" "$TEMP_LINK" +ln -s -- "$TIMESTAMP" "$TEMP_LINK" mv -Tf -- "$TEMP_LINK" "$TARGET_DIR/latest" echo "OK: Backup-Satz veroeffentlicht unter $FINAL_DIR (latest aktualisiert)" diff --git a/scripts/shinkan/shinkan-backup-manifest b/scripts/shinkan/shinkan-backup-manifest index cac9bdd..9d459bd 100644 --- a/scripts/shinkan/shinkan-backup-manifest +++ b/scripts/shinkan/shinkan-backup-manifest @@ -138,21 +138,35 @@ def query_db_metadata(tcfg, dump_path): except Exception: pass - # Fallback: parse migrations from plain SQL dump if container query was unavailable - if not migrations and detect_dump_format(dump_path) == 'plain': + # Fallback: parse migrations and table row counts from plain SQL dump + if detect_dump_format(dump_path) == 'plain': in_copy = False + curr_table = None + tcount = 0 with Path(dump_path).open('r', encoding='utf-8', errors='replace') as fp: for line in fp: if not in_copy: - if line.startswith('COPY public.schema_migrations ') or line.startswith('COPY schema_migrations '): - in_copy = True - continue + if line.startswith('COPY public.') or line.startswith('COPY '): + parts = line.split() + if len(parts) >= 2: + tbl = parts[1].replace('public.', '').replace('"', '').split('(')[0].strip() + curr_table = tbl + tcount = 0 + in_copy = True else: if line.startswith('\\.'): - break - parts = line.rstrip('\r\n').split('\t') - if len(parts) >= 2: - migrations.append(parts[1]) + if curr_table: + if not row_counts or curr_table not in row_counts: + row_counts[curr_table] = tcount + in_copy = False + curr_table = None + tcount = 0 + else: + tcount += 1 + if curr_table == 'schema_migrations' and not migrations: + parts = line.rstrip('\r\n').split('\t') + if len(parts) >= 2: + migrations.append(parts[1]) def sort_key(stem): m = re.match(r'^(\d+)', stem) diff --git a/scripts/shinkan/shinkan-restore b/scripts/shinkan/shinkan-restore index 88b5bc7..a356167 100644 --- a/scripts/shinkan/shinkan-restore +++ b/scripts/shinkan/shinkan-restore @@ -316,6 +316,16 @@ def main(): write_result(args.result, {'status': 'error', 'exit_code': EXIT_EXEC_ERROR, 'detail': msg}) return EXIT_EXEC_ERROR + # Verify active media_assets count in staging database + act_res = psql_exec(tcfg, staging_db, "SELECT COUNT(*)::int FROM media_assets WHERE lifecycle_state = 'active';") + if act_res.returncode == 0 and act_res.stdout.strip().isdigit(): + act_cnt = int(act_res.stdout.strip()) + if act_cnt < 1: + drop_db_if_exists(tcfg, staging_db) + msg = f'Plausibility check failed: expected active media_assets, found {act_cnt}' + write_result(args.result, {'status': 'error', 'exit_code': EXIT_EXEC_ERROR, 'detail': msg}) + return EXIT_EXEC_ERROR + if args.sessions == 'clear': print('5. Clearing active user sessions in staging DB (--sessions clear)...') psql_exec(tcfg, staging_db, 'TRUNCATE TABLE sessions;')