Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,54 +68,6 @@ jobs:
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Backup prod database before deploy
uses: appleboy/ssh-action@v0.1.8
with:
host: ${{ secrets.PROD_SERVER_IP }}
username: ${{ secrets.PROD_SERVER_USER }}
key: ${{ secrets.PROD_SERVER_SSH_KEY }}
port: ${{ secrets.PROD_SERVER_PORT }}
script: |
set -euo pipefail

cd "${{ secrets.PROD_WORK_DIR }}"

set -a
source .env
set +a

BACKUP_DIR="${PWD}/dumps"
TS="$(date '+%Y%m%d_%H%M%S')"
DUMP_FILE="${BACKUP_DIR}/${TS}.sql"

mkdir -p "${BACKUP_DIR}"

# n일 지난 백업 정리 (원하면 주석 해제)
find "${BACKUP_DIR}" -type f -name "*.sql" -mtime +5 -delete
cleanup() { unset MYSQL_PWD || true; }
trap cleanup EXIT

: "${MYSQL_HOST:?MYSQL_HOST is required}"
: "${MYSQL_PORT:=3306}"
: "${MYSQL_USERNAME:?MYSQL_USERNAME is required}"
: "${MYSQL_PASSWORD:?MYSQL_PASSWORD is required}"
: "${MYSQL_DATABASE:?MYSQL_DATABASE is required}"

export MYSQL_PWD="${MYSQL_PASSWORD}"

mysqldump \
-h "${MYSQL_HOST}" \
-P "${MYSQL_PORT}" \
-u "${MYSQL_USERNAME}" \
--single-transaction --quick \
--routines --triggers --events \
--default-character-set=utf8mb4 \
--set-gtid-purged=OFF \
"${MYSQL_DATABASE}" > "${DUMP_FILE}"

test -s "${DUMP_FILE}"
ls -lh "${DUMP_FILE}"

- name: Deploy to prod server
uses: appleboy/ssh-action@v0.1.8
with:
Expand Down
49 changes: 0 additions & 49 deletions .github/workflows/deploy-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,55 +68,6 @@ jobs:
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Backup stage database before deploy
uses: appleboy/ssh-action@v0.1.8
with:
host: ${{ secrets.STAGE_SERVER_IP }}
username: ${{ secrets.STAGE_SERVER_USER }}
key: ${{ secrets.STAGE_SERVER_SSH_KEY }}
port: ${{ secrets.STAGE_SERVER_PORT }}
envs: DB_HOST,DB_PORT,DB_USER,DB_PASSWORD,DB_NAME,DB_BACKUP_DIR
script: |
set -euo pipefail

cd "${{ secrets.STAGE_WORK_DIR }}"

set -a
source .env
set +a

BACKUP_DIR="${PWD}/dumps"
TS="$(date '+%Y%m%d_%H%M%S')"
DUMP_FILE="${BACKUP_DIR}/${TS}.sql"

mkdir -p "${BACKUP_DIR}"

# n일 지난 백업 정리 (원하면 주석 해제)
find "${BACKUP_DIR}" -type f -name "*.sql" -mtime +5 -delete
cleanup() { unset MYSQL_PWD || true; }
trap cleanup EXIT

: "${MYSQL_HOST:?MYSQL_HOST is required}"
: "${MYSQL_PORT:=3306}"
: "${MYSQL_USERNAME:?MYSQL_USERNAME is required}"
: "${MYSQL_PASSWORD:?MYSQL_PASSWORD is required}"
: "${MYSQL_DATABASE:?MYSQL_DATABASE is required}"

export MYSQL_PWD="${MYSQL_PASSWORD}"

mysqldump \
-h "${MYSQL_HOST}" \
-P "${MYSQL_PORT}" \
-u "${MYSQL_USERNAME}" \
--single-transaction --quick \
--routines --triggers --events \
--default-character-set=utf8mb4 \
--set-gtid-purged=OFF \
"${MYSQL_DATABASE}" > "${DUMP_FILE}"

test -s "${DUMP_FILE}"
ls -lh "${DUMP_FILE}"

- name: Deploy to stage server
uses: appleboy/ssh-action@v0.1.8
with:
Expand Down