dsyoon 3b0f3e7824 [백업] Gitea 미러 갱신 시 git 출력이 결과 JSON에 섞여 실패하던 문제 수정
미러가 이미 있으면 git remote update가 'Fetching origin'을 stdout에 출력해
결과 JSON 파싱이 실패했다(첫 실행 이후 매번 gitea 단계 실패).
git 하위 프로세스의 stdout을 stderr로 돌린다.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 16:19:53 +09:00

ncue_backup

ncue.net PostgreSQL, MariaDB, Gitea 저장소를 매일 백업하는 스크립트 모음입니다.
백업 방식은 ai_platform의 scripts/pg-backup.sh 패턴을 따릅니다.

백업 대상

구분 대상 스크립트
PostgreSQL 연결 가능한 모든 DB (ai_web_platform, meeting_ai, ncue, tts 등) scripts/pg-backup.sh
MariaDB 사용자 DB 전체 (giteadb, wordpress, roundcube 등) scripts/mr-backup.sh
Gitea 접근 가능한 모든 Git 저장소 mirror scripts/gitea-backup.sh

Gitea 메타데이터 DB(giteadb)는 MariaDB 백업에 포함됩니다. Git 소스는 mirror 백업으로 별도 보관합니다.

사전 요구사항

  • pg_dump, psql (PostgreSQL 클라이언트)
  • mysqldump, mysql (MariaDB 클라이언트)
  • git, curl, python3, gzip
  • pymysql (MariaDB 클라이언트 미설치 시 Python 폴백용, pip install -r requirements.txt)

macOS 예시:

brew install libpq mariadb
echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc

설정

cp .env.example .env
# .env 편집 (DB 접속 정보, Gitea 토큰, BACKUP_DIR)

주요 환경 변수:

변수 설명
PG_DB_* PostgreSQL 접속 정보
MR_DB_* MariaDB 접속 정보
GIT_BASE_URL Gitea URL (기본 https://git.ncue.net)
GIT_USER, GIT_TOKEN Gitea mirror 인증
BACKUP_DIR 백업 루트 (기본 프로젝트/backup)
BACKUP_RETENTION_DAYS 보관 일수 (기본 30)

실행

통합 백업 (권장):

bash scripts/daily-backup.sh

개별 백업:

bash scripts/pg-backup.sh
bash scripts/mr-backup.sh
bash scripts/gitea-backup.sh

백업 결과 구조

backup/
├─ 20260526/
│  ├─ postgresql/
│  │  ├─ 00_manifest.txt
│  │  ├─ ncue.dump
│  │  └─ ...
│  ├─ mariadb/
│  │  ├─ 00_manifest.txt
│  │  ├─ giteadb.sql.gz
│  │  └─ ...
│  └─ gitea/
│     ├─ 00_manifest.txt
│     ├─ 00_repos.json
│     └─ mirrors -> ../../_gitea_mirrors/
├─ _gitea_mirrors/              # Gitea mirror 영구 저장 (증분 업데이트)
│  └─ owner__repo.git/
└─ latest -> 20260526/

매일 cron 등록

0 2 * * * cd /home/dsyoon/workspace/ncue_backup && /usr/bin/bash scripts/daily-backup.sh >> /var/log/ncue-backup.log 2>&1

복원 참고

  • PostgreSQL: pg_restore -d dbname file.dump
  • MariaDB: gunzip -c file.sql.gz | mysql -u user -p dbname
  • Gitea mirror: git clone /path/to/mirrors/owner__repo.git restored-repo

변경 이력

  • 2026-05-26: PostgreSQL/MariaDB/Gitea 일일 백업 스크립트 초기 구성
Description
No description provided
Readme 43 KiB
Languages
Shell 82%
Python 18%