신규백업과 증분백업 구분
Some checks are pending
Git Repository Mirroring / mirror (push) Has started running

This commit is contained in:
Lectom C Han
2025-12-16 09:49:17 +09:00
parent 4a13289f23
commit 2027880b9a
2 changed files with 22 additions and 16 deletions

View File

@@ -151,6 +151,7 @@ jobs:
# Check if repository exists on Gitea
repo_exists=false
just_created=false
http_status=$(curl -s -o /dev/null -w "%{http_code}" -H "${AUTH_HEADER}" "${BASE_GITEA_URL}/api/v1/repos/${CENTER_ORG}/${repo_name}")
if [ "${http_status}" == "404" ]; then
@@ -166,6 +167,7 @@ jobs:
fi
echo "Repository created successfully."
repo_exists=true
just_created=true
rm -f "${create_tmp}"
elif [ "${http_status}" != "200" ]; then
echo "::error::Error checking repository. HTTP status: ${http_status}"
@@ -175,7 +177,9 @@ jobs:
echo "Repository 'center_dev/${repo_name}' already exists."
repo_exists=true
fi
if ${repo_exists}; then
if ${just_created}; then
backup_mode="신규 전체 백업"
elif ${repo_exists}; then
backup_mode="증분 업데이트 (pull/fetch)"
else
backup_mode="신규 전체 백업"
@@ -200,20 +204,9 @@ jobs:
# Create a temporary directory for cloning
CLONE_DIR=$(mktemp -d)
echo "Working directory: ${CLONE_DIR}"
if ${repo_exists}; then
echo "Cloning existing target repository for update (bare)..."
if ! git clone --bare "${GITEA_REMOTE}" "${CLONE_DIR}"; then
echo "::error::Failed to clone existing target repository ${GITEA_REMOTE}"
notify_status "error" "${repo_name}" "${branch_name}" "${backup_mode}" "${start_epoch}" "target clone 실패"
rm -rf "${CLONE_DIR}"
return
fi
cd "${CLONE_DIR}"
git remote add source "${source_repo_url}"
else
echo "Cloning source repository for first-time push (bare)..."
if ! git clone --bare "${source_repo_url}" "${CLONE_DIR}"; then
if ${just_created}; then
echo "Target repo newly created; cloning source branch for initial push..."
if ! git clone --bare --no-tags --single-branch --branch "${branch_name}" "${source_repo_url}" "${CLONE_DIR}"; then
echo "::error::Failed to clone source repository ${source_repo_url}"
notify_status "error" "${repo_name}" "${branch_name}" "${backup_mode}" "${start_epoch}" "source clone 실패"
rm -rf "${CLONE_DIR}"
@@ -222,10 +215,21 @@ jobs:
cd "${CLONE_DIR}"
git remote rename origin source
git remote add origin "${GITEA_REMOTE}"
else
cd "${CLONE_DIR}"
if ! git init --bare; then
echo "::error::Failed to init bare repository"
notify_status "error" "${repo_name}" "${branch_name}" "${backup_mode}" "${start_epoch}" "bare init 실패"
cd "${ROOT_DIR}"
rm -rf "${CLONE_DIR}"
return
fi
git remote add origin "${GITEA_REMOTE}"
git remote add source "${source_repo_url}"
fi
echo "Fetching latest branch '${branch_name}' from source..."
if ! git fetch source "+refs/heads/${branch_name}:refs/heads/${branch_name}"; then
if ! git fetch --no-tags source "+refs/heads/${branch_name}:refs/heads/${branch_name}"; then
echo "::error::Failed to fetch branch '${branch_name}' from source repo"
notify_status "error" "${repo_name}" "${branch_name}" "${backup_mode}" "${start_epoch}" "source fetch 오류"
cd "${ROOT_DIR}"

View File

@@ -14,3 +14,5 @@
2025-12-16 09:04:36 KST 업데이트: mirror.yml에서 대상 저장소를 `git clone --mirror` 대신 `--bare`로 받도록 변경하여 `fatal: --mirror can't be combined with refspecs` 오류를 제거. 기존 저장소가 있을 때는 Gitea 원격을 bare 클론 후 `source` 리모트를 원본 SSH에 추가하고 브랜치만 fetch → `origin``main`으로 강제 푸시하도록 정리. 새 저장소일 때는 원본을 bare 클론해 `origin``source`로 rename 후 Gitea를 `origin`으로 추가, 같은 fetch→push 동작 수행. 작업 루트 경로를 `ROOT_DIR`에 저장해 fetch/push 실패 시에도 항상 원위치로 돌아가며 임시 디렉터리를 정리하도록 수정.
2025-12-16 09:42:00 KST 업데이트: mirror.yml에 NOTIFY_WEBHOOK 기반 상태 알림(start/success/error, 소요시간 포함) 추가 및 heredoc 제거로 문법 오류 수정. 브랜치명 매핑을 확장해 Develop_Net8_* 접두사는 제거, Develop_/develop_ 접두사는 제거하여 `develop_boxzainer``boxzainer`로 푸시되도록 수정하고, 접두사 없는 `develop` 등은 그대로 사용.
2025-12-16 09:42:00 KST 추가 업데이트: mirror.yml에서 타겟이 존재할 때 `git ls-remote`로 main 커밋을 조회하고 소스 브랜치 커밋과 동일하면 클론/푸시를 건너뛰도록 최적화. 알림에 skip 상태를 추가해 동일 커밋 시 건너뛰는 로그를 남기도록 개선.
2025-12-16 09:46:30 KST 추가 업데이트: mirror.yml에서 기존 타겟 클론을 없애고 임시 bare repo를 직접 init 후 source 브랜치만 fetch(--no-tags)하여 푸시하도록 변경, 불필요한 대상 전체 클론을 제거해 데이터 전송 최소화.
2025-12-16 09:48:20 KST 추가 업데이트: mirror.yml에서 타겟이 새로 생성된 경우 소스 브랜치를 `git clone --bare --single-branch`로 전체 클론 후 push, 기존 타겟이 있을 때만 빈 bare repo를 init해 필요한 브랜치만 fetch→push 하도록 분기. 생성된 경우에도 백업 모드/알림이 “신규 전체 백업”으로 정확히 표시되도록 just_created 플래그를 추가.