내 계정 파일, DB 백업 스크립트
아래 코드를 backup.sh 내 계정에 업로드 하세요.
www 또는 public_html 안에 넣으면 안됩니다. 웹폴더 상위 폴더에 넣으세요.
ssh 접속해서 chmod +x ./backup.sh 해주세요.
하단 소스 파일에 백업할 대상의 상대 경로 또는 절대 경로를 넣어 주시고 저장될 경로도 넣어주세요.
DB 정보 넣어주시고 저장 후 콘솔에서
./backup.sh 하시면 됩니다. 이 때 DB 비번 물어보니 넣어주세요.
[code]
#!/bin/bash
# Variables
BACKUP_DIR="./public_html" # 백업할 디렉토리 경로
SAVE_DIR="./" # 저장될 경로
SAVE_FILE="backup_$(date +%Y%m%d).tar" # 파일명에 날짜 추가
DB_BACKUP_FILE="db_backup_$(date +%Y%m%d).sql" # DB 백업 파일명에 날짜 추가
DB_HOST="localhost" # DB host
DB_USERNAME="DB아이디" # DB username
DB_NAME="DB명" # DB name
SPLIT_SIZE="500M" # 분할 압축 크기 지정
# Check if source directory exists
if [ ! -d "$BACKUP_DIR" ]; then
echo "Source directory '$BACKUP_DIR' does not exist. Exiting."
exit 1
fi
# Check if save directory exists
if [ ! -d "$SAVE_DIR" ]; then
echo "Save directory '$SAVE_DIR' does not exist. Exiting."
exit 1
fi
# DB backup
echo "Enter your DB password:"
read -s DB_PASS
mysqldump --no-tablespaces -h "$DB_HOST" -u "$DB_USERNAME" -p"$DB_PASS" "$DB_NAME" > "$DB_BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Database backup was successful."
# Compress the DB dump file
gzip "$DB_BACKUP_FILE"
echo "Database backup file has been compressed."
else
echo "Database backup failed. Exiting."
exit 1
fi
# File backup
SAVE_PATH="${SAVE_DIR}/${SAVE_FILE}"
tar --exclude='sess_*' -cvf "$SAVE_PATH" -C "$BACKUP_DIR" .
if [ $? -eq 0 ]; then
echo "File backup was successful."
# Split the tar file into multiple parts of 500MB each
split -b "$SPLIT_SIZE" -d "$SAVE_PATH" "${SAVE_DIR}/tar_"
echo "File backup has been split."
else
echo "File backup failed. Exiting."
exit 1
fi
[/code]
chatGPT와 대화? 하면서 만들어 봤습니다.
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4946 | node.js | 6년 전 | 2608 | ||
| 4945 | node.js | 6년 전 | 2379 | ||
| 4944 | node.js | 6년 전 | 2519 | ||
| 4943 | node.js | 6년 전 | 2269 | ||
| 4942 | node.js | 6년 전 | 2245 | ||
| 4941 | node.js | 6년 전 | 2717 | ||
| 4940 | node.js | 6년 전 | 1867 | ||
| 4939 | node.js | 6년 전 | 1995 | ||
| 4938 | node.js | 6년 전 | 2459 | ||
| 4937 | node.js | 6년 전 | 2248 | ||
| 4936 | node.js | 6년 전 | 2318 | ||
| 4935 | node.js | 6년 전 | 2136 | ||
| 4934 | node.js | 6년 전 | 2440 | ||
| 4933 | node.js | 6년 전 | 2245 | ||
| 4932 | node.js | 6년 전 | 2686 | ||
| 4931 | node.js | 6년 전 | 2070 | ||
| 4930 | node.js | 6년 전 | 1998 | ||
| 4929 | node.js | 6년 전 | 8630 | ||
| 4928 | node.js | 6년 전 | 3749 | ||
| 4927 | node.js | 6년 전 | 2392 | ||
| 4926 | node.js | 6년 전 | 2504 | ||
| 4925 | node.js | 6년 전 | 2081 | ||
| 4924 | node.js | 6년 전 | 3373 | ||
| 4923 | node.js | 6년 전 | 2220 | ||
| 4922 | node.js | 6년 전 | 1989 | ||
| 4921 | node.js | 6년 전 | 2046 | ||
| 4920 | node.js | 6년 전 | 1764 | ||
| 4919 | node.js | 6년 전 | 2031 | ||
| 4918 | node.js | 6년 전 | 2176 | ||
| 4917 | node.js | 6년 전 | 2393 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기