#!/bin/bash # ============================================================================= # Document Server - 프로덕션 배포용 정리 스크립트 # 테스트 파일, 개발용 데이터, 로그 파일 등을 정리합니다 # ============================================================================= set -e # 색상 정의 RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' log_info() { echo -e "${BLUE}[INFO]${NC} $1" } log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } # 환경 설정 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" cd "$PROJECT_DIR" echo "=== 🧹 프로덕션 배포용 정리 시작 ===" echo "" # 1. 테스트 파일 제거 log_info "🗑️ 테스트 파일 제거 중..." # 테스트 HTML 파일들 TEST_FILES=( "test-document.html" "test-upload.html" "test.html" "cache-buster.html" "frontend/test-upload.html" "frontend/test.html" ) for file in "${TEST_FILES[@]}"; do if [ -f "$file" ]; then rm "$file" log_success "제거: $file" fi done # 2. 개발용 이미지 파일 제거 log_info "🖼️ 테스트 이미지 파일 제거 중..." # RAF 이미지 파일들 (테스트용) find . -name "*.RAF_compressed.JPEG" -delete 2>/dev/null || true find . -name "*.RAF" -delete 2>/dev/null || true log_success "테스트 이미지 파일 제거 완료" # 3. 로그 파일 정리 log_info "📝 로그 파일 정리 중..." LOG_FILES=( "backend.log" "frontend.log" ) for file in "${LOG_FILES[@]}"; do if [ -f "$file" ]; then rm "$file" log_success "제거: $file" fi done # 4. Python 캐시 파일 정리 log_info "🐍 Python 캐시 파일 정리 중..." find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true find . -name "*.pyc" -delete 2>/dev/null || true find . -name "*.pyo" -delete 2>/dev/null || true log_success "Python 캐시 파일 정리 완료" # 5. 개발용 업로드 파일 정리 log_info "📁 개발용 업로드 파일 정리 중..." # 백엔드 uploads 디렉토리 if [ -d "backend/uploads" ]; then rm -rf backend/uploads/documents/* 2>/dev/null || true rm -rf backend/uploads/thumbnails/* 2>/dev/null || true log_success "백엔드 업로드 파일 정리 완료" fi # 프론트엔드 uploads 디렉토리 if [ -d "frontend/uploads" ]; then rm -rf frontend/uploads/* 2>/dev/null || true log_success "프론트엔드 업로드 파일 정리 완료" fi # 루트 uploads 디렉토리 if [ -d "uploads" ]; then rm -rf uploads/documents/* 2>/dev/null || true rm -rf uploads/pdfs/* 2>/dev/null || true rm -rf uploads/thumbnails/* 2>/dev/null || true log_success "루트 업로드 파일 정리 완료" fi # 6. 가상환경 제거 (프로덕션에서는 Docker 사용) log_info "🐍 가상환경 제거 중..." if [ -d "backend/venv" ]; then rm -rf backend/venv log_success "가상환경 제거 완료" fi # 7. 개발용 설정 파일 정리 log_info "⚙️ 개발용 설정 파일 정리 중..." # 환경 변수 파일들 (프로덕션에서 새로 생성) DEV_CONFIG_FILES=( ".env" ".env.local" ".env.development" "backend/.env" ) for file in "${DEV_CONFIG_FILES[@]}"; do if [ -f "$file" ]; then rm "$file" log_success "제거: $file" fi done # 8. 불필요한 문서 파일 정리 log_info "📚 개발용 문서 파일 정리 중..." DEV_DOCS=( "VIEWER_REFACTORING.md" ) for file in "${DEV_DOCS[@]}"; do if [ -f "$file" ]; then rm "$file" log_success "제거: $file" fi done # 9. 빈 디렉토리 정리 log_info "📂 빈 디렉토리 정리 중..." find . -type d -empty -delete 2>/dev/null || true # 10. 권한 정리 log_info "🔐 파일 권한 정리 중..." # 스크립트 파일 실행 권한 확인 chmod +x scripts/*.sh 2>/dev/null || true # 설정 파일 권한 설정 find . -name "*.conf" -exec chmod 644 {} \; 2>/dev/null || true find . -name "*.yml" -exec chmod 644 {} \; 2>/dev/null || true find . -name "*.yaml" -exec chmod 644 {} \; 2>/dev/null || true log_success "파일 권한 정리 완료" # 11. 정리 결과 요약 echo "" echo "=== 📊 정리 결과 ===" # 현재 디렉토리 크기 TOTAL_SIZE=$(du -sh . | cut -f1) echo "전체 크기: $TOTAL_SIZE" # 주요 디렉토리 크기 echo "" echo "주요 디렉토리:" du -sh backend frontend scripts nginx 2>/dev/null | while read size dir; do echo " $dir: $size" done echo "" echo "=== ✅ 정리 완료 ===" echo "" echo "🚀 이제 프로덕션 배포 준비가 완료되었습니다!" echo "" echo "다음 단계:" echo "1. NAS에 업로드" echo "2. ./scripts/deploy-synology.sh 실행" echo "3. 배포 완료!" log_success "프로덕션 정리 스크립트 완료"