98 lines
2.3 KiB
Bash
Executable File
98 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
. "$SCRIPT_DIR/common.sh"
|
|
|
|
WHATIF=0
|
|
KEEP_DATA=0
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--what-if) WHATIF=1 ;;
|
|
--keep-data) KEEP_DATA=1 ;;
|
|
*) echo "Unknown argument: $arg" >&2; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
RESTORE_ROOT="/mnt/user/backups/restore-lab/gitea"
|
|
REPORT_ROOT="/mnt/user/backups/restore-reports"
|
|
DATA_DIR="$RESTORE_ROOT/data"
|
|
EXTRACT_DIR="$BORG_RESTORE_HOST_ROOT/gitea-extract"
|
|
COMPOSE_FILE="$SCRIPT_DIR/gitea-compose.test.yml"
|
|
REPORT_FILE="$REPORT_ROOT/gitea-$(date +%F).md"
|
|
|
|
if [ "$WHATIF" -eq 1 ]; then
|
|
cat <<EOF
|
|
Gitea restore test
|
|
Mode: WhatIf
|
|
RestoreRoot: $RESTORE_ROOT
|
|
ReportRoot: $REPORT_ROOT
|
|
Expected Borg source path: local/gitea/data
|
|
EOF
|
|
exit 0
|
|
fi
|
|
|
|
require_cmd docker
|
|
require_cmd curl
|
|
require_path "$BORG_PASSPHRASE_FILE_DEFAULT"
|
|
require_path "$COMPOSE_FILE"
|
|
|
|
cleanup() {
|
|
cleanup_compose "$COMPOSE_FILE"
|
|
if [ "$KEEP_DATA" -ne 1 ]; then
|
|
rm -rf "$DATA_DIR"
|
|
fi
|
|
rm -rf "$EXTRACT_DIR"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
rm -rf "$EXTRACT_DIR" "$RESTORE_ROOT"
|
|
mkdir -p "$RESTORE_ROOT"
|
|
|
|
archive="$(latest_archive_name)"
|
|
repo="$(borg_repo_url)"
|
|
borg_extract "/restore/gitea-extract" "local/gitea/data"
|
|
mv "$EXTRACT_DIR/local/gitea/data" "$DATA_DIR"
|
|
|
|
repo_sample="$(find "$DATA_DIR/git/repositories" -maxdepth 3 -type d | sed -n '2p')"
|
|
|
|
docker compose -f "$COMPOSE_FILE" up -d >/dev/null
|
|
sleep 8
|
|
status="$(curl -s -o /tmp/gitea-body.html -w '%{http_code}' http://127.0.0.1:13000)"
|
|
grep -qi "Gitea" /tmp/gitea-body.html
|
|
if timeout 5 bash -lc '</dev/tcp/127.0.0.1/12222' >/dev/null 2>&1; then
|
|
ssh_state="open"
|
|
else
|
|
echo "Gitea SSH port not reachable" >&2
|
|
exit 1
|
|
fi
|
|
|
|
write_report "$REPORT_FILE" <<EOF
|
|
# Gitea Restore Test Report - $(date +%F)
|
|
|
|
- Service: \`gitea\`
|
|
- Source repo: \`$repo\`
|
|
- Archive: \`$archive\`
|
|
- Restore target: \`$DATA_DIR\`
|
|
- Test container: \`restoretest-gitea\`
|
|
- Test endpoints:
|
|
- Web: \`http://127.0.0.1:13000\`
|
|
- SSH: \`127.0.0.1:12222\`
|
|
- Result: \`SUCCESS\`
|
|
|
|
## Checks
|
|
|
|
- Borg extract into isolated restore-lab: \`ok\`
|
|
- HTTP status: \`$status\`
|
|
- HTML content: \`Gitea\`
|
|
- SSH port: \`$ssh_state\`
|
|
- Repository sample: \`$repo_sample\`
|
|
|
|
## Notes
|
|
|
|
- Test ran without Traefik and without the productive domain.
|
|
- Test data was cleaned after success: \`$([ "$KEEP_DATA" -eq 1 ] && echo no || echo yes)\`
|
|
EOF
|
|
|
|
echo "Gitea restore test ok -> $REPORT_FILE"
|