Files
ncue_backup/README.md
dsyoon 3c9d9283bd Add daily backup scripts for PostgreSQL, MariaDB, and Gitea.
Enable scheduled backups of ncue.net databases and git.ncue.net repository mirrors via .env-driven shell scripts.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-26 17:02:53 +09:00

2.8 KiB

ncue_backup

ncue.net PostgreSQL, MariaDB, Gitea 저장소를 매일 백업하는 스크립트 모음입니다.
백업 방식은 ai_platformscripts/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 /Users/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 일일 백업 스크립트 초기 구성