내 계정 파일, 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에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 5246 | node.js |
swallow
|
2년 전 | 1102 | |
| 5245 | PHP |
swallow
|
2년 전 | 2522 | |
| 5244 | PHP |
swallow
|
2년 전 | 1283 | |
| 5243 | JavaScript |
swallow
|
2년 전 | 683 | |
| 5242 | node.js |
swallow
|
2년 전 | 664 | |
| 5241 | node.js |
swallow
|
2년 전 | 773 | |
| 5240 | MySQL |
swallow
|
2년 전 | 800 | |
| 5239 | MySQL | 2년 전 | 775 | ||
| 5238 | JavaScript | 2년 전 | 976 | ||
| 5237 | 웹서버 |
swallow
|
2년 전 | 3984 | |
| 5236 | PHP |
swallow
|
2년 전 | 897 | |
| 5235 | PHP |
swallow
|
2년 전 | 1375 | |
| 5234 | 기타 | 2년 전 | 750 | ||
| 5233 | jQuery |
swallow
|
2년 전 | 2031 | |
| 5232 | 2년 전 | 612 | |||
| 5231 | 2년 전 | 1166 | |||
| 5230 | 2년 전 | 1067 | |||
| 5229 | PHP |
swallow
|
2년 전 | 1018 | |
| 5228 | MySQL | 2년 전 | 720 | ||
| 5227 | PHP |
swallow
|
2년 전 | 833 | |
| 5226 | PHP |
swallow
|
2년 전 | 1807 | |
| 5225 | PHP | 2년 전 | 574 | ||
| 5224 | node.js |
swallow
|
2년 전 | 4078 | |
| 5223 | PHP |
swallow
|
2년 전 | 1314 | |
| 5222 | 기타 |
techstar
|
2년 전 | 556 | |
| 5221 | PHP | 2년 전 | 648 | ||
| 5220 |
swallow
|
2년 전 | 901 | ||
| 5219 | 2년 전 | 874 | |||
| 5218 | 2년 전 | 520 | |||
| 5217 | 2년 전 | 995 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기