#!/usr/bin/env bash set -euo pipefail BACKUP_DIR="/gitea/backups" TMP_BASE="/tmp/soloforge-restore-test" CONTAINER_IMAGE="gitea/gitea:latest" # for future deeper tests if desired mkdir -p "$TMP_BASE" latest="$(ls -1t "$BACKUP_DIR"/gitea-dump-*.zip 2>/dev/null | head -n1 || true)" if [[ -z "$latest" ]]; then echo "[restore-test] No backup files found in $BACKUP_DIR" forge-alert.sh "ERROR" "restore-test" "No backup files found in $BACKUP_DIR" exit 1 fi echo "[restore-test] Using latest backup: $latest" # Basic ZIP integrity test echo "[restore-test] Running unzip -t ..." if ! unzip -t "$latest" >/dev/null 2>&1; then echo "[restore-test] unzip -t failed for $latest" forge-alert.sh "ERROR" "restore-test" "Backup failed unzip test: $(basename "$latest")" exit 1 fi # Optional: extraction smoke test tmpdir="$(mktemp -d "$TMP_BASE/restore-test-XXXXXX")" echo "[restore-test] Extracting into $tmpdir ..." if ! unzip -qq "$latest" -d "$tmpdir"; then echo "[restore-test] unzip extract failed for $latest" forge-alert.sh "ERROR" "restore-test" "Backup failed extraction: $(basename "$latest")" rm -rf "$tmpdir" exit 1 fi # Clean up rm -rf "$tmpdir" echo "[restore-test] Backup passed unzip + extraction checks." forge-alert.sh "INFO" "restore-test" "Backup $(basename "$latest") passed restore tests."