fix: mysqldump 비밀번호 경고 제거 (defaults-extra-file 방식)
- 커맨드라인 --user/--password → 임시 .my.cnf 파일 방식으로 변경 - mysqldump 실행 전 임시 파일 생성, 완료 후 삭제 - "Using a password on the command line interface" 경고 해소 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -47,23 +47,37 @@ ensure_dirs() {
|
||||
mkdir -p "$DAILY_DIR" "$WEEKLY_DIR" "$LOG_DIR"
|
||||
}
|
||||
|
||||
create_mycnf() {
|
||||
local tmp_cnf
|
||||
tmp_cnf=$(mktemp /tmp/.my.cnf.XXXXXX)
|
||||
chmod 600 "$tmp_cnf"
|
||||
cat > "$tmp_cnf" <<MYCNF
|
||||
[mysqldump]
|
||||
user=${DB_USER}
|
||||
password=${DB_PASS}
|
||||
host=${DB_HOST}
|
||||
port=${DB_PORT}
|
||||
MYCNF
|
||||
echo "$tmp_cnf"
|
||||
}
|
||||
|
||||
backup_database() {
|
||||
local db_name="$1"
|
||||
local output_file="${DAILY_DIR}/${db_name}_${TIMESTAMP}.sql.gz"
|
||||
local mycnf
|
||||
mycnf=$(create_mycnf)
|
||||
|
||||
log "INFO" "백업 시작: ${db_name}"
|
||||
|
||||
if mysqldump \
|
||||
--host="$DB_HOST" \
|
||||
--port="$DB_PORT" \
|
||||
--user="$DB_USER" \
|
||||
--password="$DB_PASS" \
|
||||
--defaults-extra-file="$mycnf" \
|
||||
--single-transaction \
|
||||
--routines \
|
||||
--triggers \
|
||||
--quick \
|
||||
--lock-tables=false \
|
||||
"$db_name" 2>>"$LOG_FILE" | gzip > "$output_file"; then
|
||||
rm -f "$mycnf"
|
||||
|
||||
local file_size
|
||||
file_size=$(stat -f%z "$output_file" 2>/dev/null || stat -c%s "$output_file" 2>/dev/null || echo 0)
|
||||
@@ -91,6 +105,7 @@ backup_database() {
|
||||
|
||||
return 0
|
||||
else
|
||||
rm -f "$mycnf"
|
||||
log "ERROR" "mysqldump 실패: ${db_name}"
|
||||
ERRORS+=("${db_name}: mysqldump 실패")
|
||||
DB_RESULTS+=("{\"db\":\"${db_name}\",\"file\":\"\",\"size_bytes\":0,\"status\":\"dump_error\"}")
|
||||
|
||||
Reference in New Issue
Block a user