-
Notifications
You must be signed in to change notification settings - Fork 1
DB 자동 백업 파이프라인 구축 #260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
DB 자동 백업 파이프라인 구축 #260
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7ee5e86
[SOU-593] 기념품 조회 응답에 찜 수/여부 추가 (#250)
bum0w0 b5800bb
[SOU-571] 찜 기능 테스트 코드 및 API 문서 작성 (#251)
bum0w0 3cc0272
[SOU-601] 탈퇴 유저 삭제 배치 스케줄러 구현 (#252)
bum0w0 4bb2f94
fix: userId UUID 타입 불일치로 인한 NumberFormatException 수정 (#253)
bum0w0 0a12540
feat: 탈퇴 유저 배치 삭제로 정책 변경 및 테스트 수정 (#254)
bum0w0 7ce6d72
feat: 정보 동의한 회원들에게만 알림을 발송하도록 수정 (#255)
hoonjo123 bb14eae
refactor: auth 바운디드 컨텍스트 수정
Develop-KIM fb8fa15
fix: 깃 충돌 수정
Develop-KIM e4b4616
refactor: 정책에 따라 테스트 코드 수정
Develop-KIM a1d13bb
Merge pull request #256 from souzip/refactor/SOU-603-auth
Develop-KIM 93d3bf5
[SOU-622] Docker DB 전환 및 자동 백업 파이프라인 구축
bum0w0 eb17b62
feat: db 백업 자동화 스크립트 추가 (#259)
bum0w0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| version: "3.8" | ||
|
|
||
| services: | ||
| postgres: | ||
| image: postgis/postgis:16-3.4 | ||
| container_name: souzip-prod-db | ||
| restart: always | ||
| networks: | ||
| - souzip-network | ||
| ports: | ||
| - "127.0.0.1:5432:5432" | ||
| env_file: | ||
| - .env.prod | ||
| environment: | ||
| POSTGRES_DB: souzip_prod | ||
| POSTGRES_USER: ${PROD_POSTGRES_USER} | ||
| POSTGRES_PASSWORD: ${PROD_POSTGRES_PASSWORD} | ||
| TZ: Asia/Seoul | ||
| volumes: | ||
| - postgres-data:/var/lib/postgresql/data | ||
| - ./postgres/init:/docker-entrypoint-initdb.d | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U ${PROD_POSTGRES_USER} -d souzip_prod"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 10 | ||
|
|
||
| networks: | ||
| souzip-network: | ||
| external: true | ||
|
|
||
| volumes: | ||
| postgres-data: | ||
| driver: local | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #!/bin/bash | ||
| DATE=$(date +%Y-%m-%d_%H%M) | ||
| BACKUP_DIR="/home/souzip-prod/backups" | ||
| BACKUP_FILE="$BACKUP_DIR/souzip-$DATE.dump" | ||
| BUCKET="souzip-db-backup" | ||
| RETENTION_DAYS=30 | ||
|
|
||
| if [ -f "/home/souzip-prod/souzip/deploy/prod/.env" ]; then | ||
| export PROD_POSTGRES_USER=$(grep '^PROD_POSTGRES_USER=' /home/souzip-prod/souzip/deploy/prod/.env | cut -d= -f2-) | ||
| export PROD_POSTGRES_PASSWORD=$(grep '^PROD_POSTGRES_PASSWORD=' /home/souzip-prod/souzip/deploy/prod/.env | cut -d= -f2-) | ||
| export PROD_DB_DISCORD_WEBHOOK_URL=$(grep '^PROD_DB_DISCORD_WEBHOOK_URL=' /home/souzip-prod/souzip/deploy/prod/.env | cut -d= -f2-) | ||
| export NCP_ACCESS_KEY=$(grep '^NCP_ACCESS_KEY=' /home/souzip-prod/souzip/deploy/prod/.env | cut -d= -f2-) | ||
| export NCP_SECRET_KEY=$(grep '^NCP_SECRET_KEY=' /home/souzip-prod/souzip/deploy/prod/.env | cut -d= -f2-) | ||
| fi | ||
|
|
||
| S3CMD_OPTS="--access_key=$NCP_ACCESS_KEY --secret_key=$NCP_SECRET_KEY --host=kr.object.ncloudstorage.com --host-bucket=%(bucket)s.kr.object.ncloudstorage.com" | ||
|
|
||
| mkdir -p $BACKUP_DIR | ||
|
|
||
| docker exec -e PGPASSWORD=$PROD_POSTGRES_PASSWORD souzip-prod-db \ | ||
| pg_dump -U $PROD_POSTGRES_USER -d souzip_prod -F c > $BACKUP_FILE | ||
|
|
||
| if [ $? -ne 0 ]; then | ||
| echo "[ERROR] DB 백업 실패 - $DATE" | ||
| curl -s -H "Content-Type: application/json" \ | ||
| -X POST \ | ||
| -d "{\"username\": \"Souzip Bot\", \"content\": \"@here DB 백업 실패 - $DATE\"}" \ | ||
| "$PROD_DB_DISCORD_WEBHOOK_URL" > /dev/null | ||
| exit 1 | ||
| fi | ||
| echo "[INFO] DB 백업 완료 - $BACKUP_FILE" | ||
|
|
||
| s3cmd $S3CMD_OPTS put $BACKUP_FILE s3://$BUCKET/souzip-$DATE.dump | ||
|
|
||
| if [ $? -ne 0 ]; then | ||
| echo "[ERROR] Object Storage 업로드 실패 - $DATE" | ||
| curl -s -H "Content-Type: application/json" \ | ||
| -X POST \ | ||
| -d "{\"username\": \"Souzip Bot\", \"content\": \"@here DB 백업 업로드 실패 - $DATE\"}" \ | ||
| "$PROD_DB_DISCORD_WEBHOOK_URL" > /dev/null | ||
| exit 1 | ||
| fi | ||
| echo "[INFO] Object Storage 업로드 완료" | ||
|
|
||
| # 로컬 오래된 백업 삭제 | ||
| find $BACKUP_DIR -name "souzip-*.dump" -mtime +$RETENTION_DAYS -delete | ||
|
|
||
| # Object Storage 오래된 백업 삭제 | ||
| s3cmd $S3CMD_OPTS ls s3://$BUCKET/ | awk '{print $4}' | while read file; do | ||
| file_date=$(echo $file | grep -oP '\d{4}-\d{2}-\d{2}') | ||
| if [ ! -z "$file_date" ]; then | ||
| days_old=$(( ( $(date +%s) - $(date -d "$file_date" +%s) ) / 86400 )) | ||
| if [ $days_old -gt $RETENTION_DAYS ]; then | ||
| s3cmd $S3CMD_OPTS del $file | ||
| echo "[INFO] 오래된 백업 삭제 - $file" | ||
| fi | ||
| fi | ||
| done | ||
|
|
||
| echo "[INFO] DB 백업 프로세스 완료 - $DATE" | ||
|
|
||
| curl -s -H "Content-Type: application/json" \ | ||
| -X POST \ | ||
| -d "{\"username\": \"Souzip Bot\", \"embeds\": [{\"title\": \"DB 백업 완료\", \"color\": 3066993, \"fields\": [{\"name\": \"날짜\", \"value\": \"$DATE\", \"inline\": true}, {\"name\": \"파일\", \"value\": \"souzip-$DATE.dump\", \"inline\": true}]}]}" \ | ||
| "$PROD_DB_DISCORD_WEBHOOK_URL" > /dev/null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| [[wishlist-api]] | ||
| == Wishlist API | ||
|
|
||
| [[wishlist-add]] | ||
| === 찜 등록 (new) | ||
|
|
||
| 기념품을 찜 목록에 추가하는 API입니다. | ||
|
|
||
| * 엔드포인트: `POST /api/wishlists/{souvenirId}` | ||
| * 인증 필요 | ||
| * 이미 찜한 기념품에 다시 찜 요청을 보내면 에러가 반환됩니다. | ||
|
|
||
| operation::wishlists/add[snippets='http-request,path-parameters,http-response,response-fields'] | ||
|
|
||
| [[wishlist-remove]] | ||
| === 찜 취소 (new) | ||
|
|
||
| 찜 목록에서 기념품을 제거하는 API입니다. | ||
|
|
||
| * 엔드포인트: `DELETE /api/wishlists/{souvenirId}` | ||
| * 인증 필요 | ||
| * 찜하지 않은 기념품을 취소하려 하면 에러가 반환됩니다. | ||
|
|
||
| operation::wishlists/remove[snippets='http-request,path-parameters,http-response,response-fields'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
프로덕션 배포 스크립트와 기존 blue/green compose는
.env를 기준으로 동작하는데, 새 DB compose만env_file: .env.prod를 사용해 변수 소스를 다르게 잡고 있습니다. 운영 서버에.env.prod가 없거나 값이 분리되어 있으면PROD_POSTGRES_USER/PROD_POSTGRES_PASSWORD치환이 비어 DB 컨테이너 기동이 실패할 수 있으므로, 기존 배포 체계와 동일한 env 파일로 통일하거나 배포 스크립트에서 동일 파일을 보장해야 합니다.Useful? React with 👍 / 👎.