μλν κ°λ₯ν λͺ¨λ μ 무λ₯Ό μλν νλΌ.
μ΅κ·Ό νμ¬μμ λΉμ© μ κ°μ μν΄ DB μ€λ μ· λ³΄κ΄ κΈ°κ°μ νλ£¨λ‘ μ€μΈλ€λ λ°©μΉ¨μ΄ λ΄λ €μλ€.
κΈ°μ‘΄μλ λ©°μΉ μ© μ μ§λλ μλ μ€λ μ·μ΄ νλ£¨λ§ λ³΄κ΄λλ€ λ³΄λ, κ·Έ μ΄νμλ λ°μ΄ν°λ₯Ό 볡ꡬνκΈ° μ΄λ €μ΄ μν©μ΄ μκΈΈ μ μμλ€.
κ·Έλμ μ€λ μ·μ΄ μλ λ€λ₯Έ λ°©λ²μΌλ‘ λ°±μ μ μ μ§ν νμκ° μμκ³ ,
MySQL Dump + AWS S3 μ‘°ν©μΌλ‘ λ§€μΌ μλμΌλ‘ λ°μ΄ν° λ°±μ νλ μ€ν¬λ¦½νΈλ₯Ό μμ±νλ€.
#!/bin/bash
# crontabμΌλ‘ μ€νν κ²½μ° μ€ν¬λ¦½νΈλ μ€ν νκ²½μ κ²½λ‘λ₯Ό μ°Έμ‘°νλ―λ‘ μ€μΉ νμΌλ€μ κ²½λ‘λ₯Ό λͺ¨λ₯Έλ€.
# λ°λΌμ mysqldump, aws λ±μ μ€ννμΌμ λμμν€κΈ° μν΄ λ€μκ³Ό κ°μ΄ κ²½λ‘λ₯Ό λͺ
μν΄ μ£Όμ΄μΌ νλ€.
PATH=/usr/local/bin:/usr/bin:/bin:/opt/homebrew/bin
# 1. μ€λ λ μ§λ₯Ό λ³μλ‘ μ μ₯
TODAY=$(date +%Y-%m-%d)
# 2. λ°±μ
ν΄λ μμ±
BACKUP_DIR=~/Workspace/backup/$TODAY
mkdir -p "$BACKUP_DIR"
# 3. ν
μ΄λΈ λͺ©λ‘
TABLES=("cheer_message" "game_result" "reward_history" "sale_link_history" "share_link_history" "user")
LOG_DIR=/Users/shhan/Workspace/backup/log
mkdir -p "$LOG_DIR"
LOG_FILE="$LOG_DIR/my_bump_$TODAY.log"
echo "Dump start at $TODAY" >> "$LOG_FILE" 2>&1
# 4. DB μ 보
HOST="prd-elypecs.cluster-cos1iw8cmzag.ap-northeast-2.rds.amazonaws.com"
PORT=3306
USER="my_table"
PASSWORD="password1234" # κ°μ§ λΉλ° λ²νΈ
DATABASE="hanul_bori_prd"
# 5. κ° ν
μ΄λΈ λ€ν
for TABLE in "${TABLES[@]}"; do
echo "Dumping table: $TABLE"
mysqldump \
-h "$HOST" \
-P "$PORT" \
-u "$USER" \
-p"$PASSWORD" \
--no-create-info \
--no-tablespaces \
"$DATABASE" "$TABLE" \
> "$BACKUP_DIR/$TABLE.sql" 2>> "$LOG_FILE"
if [ $? -ne 0 ]; then
echo "β Failed to dump table: $TABLE" >> "$LOG_FILE" 2>&1
else
echo "β
Dumped: $TABLE.sql" >> "$LOG_FILE" 2>&1
fi
done
# 6. S3 μ
λ‘λ
echo "Uploading to S3..." >> "$LOG_FILE" 2>&1
aws s3 sync "$BACKUP_DIR" "s3://prd-data-backup-hanul-bori/$TODAY" >> "$LOG_FILE" 2>&1
if [ $? -eq 0 ]; then
echo "β
S3 upload complete!" >> "$LOG_FILE" 2>&1
else
echo "β S3 upload failed." >> "$LOG_FILE" 2>&1
fi
$(date +%Y-%m-%d)λ₯Ό μ¬μ©ν΄ YYYY-MM-DD νμμ ν΄λλ₯Ό λ§λ€μλ€.TABLES=("...") λ°°μ΄μ μνλ ν
μ΄λΈλͺ
μ λ£μ΄ νμν λ°μ΄ν°λ§ λ°±μ
νλλ‘ νλ€..sql νμΌμ μ μ₯νκ³ , mysqldump μ€ν λ‘κ·Έμ μλ¬λ λ³λμ log ν΄λμ μ μ₯νλ€.aws s3 sync λͺ
λ Ήμ΄λ‘ λ°±μ
ν΄λ μ 체λ₯Ό ν΄λΉ λ μ§ κ²½λ‘μ μ
λ‘λνλ€.μ€ν¬λ¦½νΈλ₯Ό μ€ννλ λ μ§λ³ ν΄λ μμ SQL λ€ν νμΌμ΄ μμ±λλ€.
backup/
βββ 2025-08-08/
β βββ cheer_message.sql
β βββ game_result.sql
β βββ reward_history.sql
β βββ sale_link_history.sql
β βββ share_link_history.sql
β βββ user.sql
βββ log/
βββ my_dump_2025-08-08.log

μ΄μ κ°μ΄ ν΄λκ° μμ±λμκ³ λ€μκ³Ό κ°μ΄ νμΌμ΄ μ μμ μΌλ‘ μ λ‘λ λκ²μ νμΈν μ μμλ€.

μ΄μ μ μμ±ν μ€ν¬λ¦½νΈλ₯Ό crontab -e λͺ
λ Ήμ΄ μ€ν ν μνλ μκ°μ λ§μΆ° λ±λ‘νλ€.
μ
무μκ°μ PCλ₯Ό μΌλ κ²μ΄λ―λ‘ μ€ν 3μμ νλ² κ·Έλ¦¬κ³ μ λ
μλ μ£Όλ‘ κ³΅λΆλ₯Ό νλκΉ 9μμ νλ² λ±λ‘ν΄ λμλ€.
μ€μ μκ°μ νΌν μ΄μ λ λΉμΌμ μμΈ λ‘κ·Έλ₯Ό λΉμΌμ λ°±μ
νκΈ° μν¨μ΄λ€.
0 17 * * * /Users/shhan/Workspace/backup/sql/hanul_bori_dump.sh
53 21 * * * /Users/shhan/Workspace/backup/sql/hanul_bori_dump.sh
crontab λμμ΄ μ€ν¨ν μ΄μ λ PATH λλ¬Έμ΄μλ€. μ€ν¬λ¦½νΈκ° μ€νλ λ crontabμ μν΄ μ€νμ΄ λλ©΄ νκ²½μ΄ usr/local/bin μ λ μ΅μνμ κ²½λ‘λ§ κΈ°λ³Έκ°μΌλ‘ μ€νλκΈ° λλ¬Έμ μ€ν¬λ¦½νΈ μμ μλ mysqldumpμ awsλͺ
λ Ήμ΄λ₯Ό μ€νν μ μκΈ° λλ¬Έμ λ°μν μλ¬μλ€.
Dumping table: cheer_message
β Failed to dump table: cheer_message
Dumping table: game_result
β Failed to dump table: game_result
Dumping table: reward_history
β Failed to dump table: reward_history
Dumping table: sale_link_history
β Failed to dump table: sale_link_history
Dumping table: share_link_history
β Failed to dump table: share_link_history
Dumping table: user
β Failed to dump table: user
Uploading to S3...
β S3 upload failed.
#!/bin/bash
# μ€ν¬λ¦½νΈμ PATH μΆκ°
PATH=/usr/local/bin:/usr/bin:/bin:/opt/homebrew/bin
λ§€μΌ μλμΌλ‘ μμ ν λ»ν μ 무λ₯Ό μλν νλ μ΅κ΄μ λ§€μ° μ€μνλ€. μλμΌλ‘ μμ μ νλκ² λΉλ‘ μμ μμ μΌμ§λΌλ μμ΄κ² λλ©΄ μ΄ λν λΉμ©μΌλ‘ μμ©νλ©° λΆνμν μκ°μ λλΉνκ² λλ κ²μ΄λ€.
κ°λ°κ³Ό κΈ°μ μ νμ©νλ€λ κ²μ μ΄λ κ² νμνν μΌμ΄λ©° κ°λ₯ν λͺ¨λ μ 무λ₯Ό μλμΌλ‘ μ²λ¦¬νμ¬ μΆμ μ§μ ν₯μμν¬ μ μλλ‘ μ°½μμ±μ κ°μ§κ³ νμ©ν΄ 보μμΌ ν¨μ λκΌλ€.