server 자동 백업 / 삭제 (data + mysql)

2012.04.15 10:08

엘카 조회 수:13586

참고 문서  

# vi /bin/backup.sh

#!/bin/bash
### 변수 설정 ###
home=/home/ # 홈 경로
backup_path=/root/backup/ # 저장할 경로
delete_date="+6" # 6일이 지난 백업본 삭제
www=public_html # 웹 디렉토리 이름
vm_shared=/mnt/hgfs/vm_shared/ # VMware 공유폴더

### 예전 자료 삭제 ###
find $backup_path*.tar.gz -mtime $delete_date -print -exec rm -rf {} \;

### 서비스 종료 ###
wall "Run Backup"
/usr/local/apache/bin/apachectl stop # 아파치 종료
service mysqld stop # mysql 종료

### 압축 ###
mkdir $backup_path # 혹시 backup 폴더 삭제한 경우;;
for folder in $home*/$www
do
 filename=`date +%Y%m%d-%H%M`_${folder#$home} # 20120325_elkha/public_html
 tar cvfz $backup_path${filename%/$www}.tar.gz $folder # tar cvfz /manage/backup/20120325_elkha.tar.gz /home/elkha/public_html
done
zip -r $backup_path`date +%Y%m%d-%H%M`-mysql.zip /var/lib/mysql # 파일명: /home/"20120325-mysql.zip"
### yum install zip # zip 쓰는 이유는 무식하게 통채로 압축했는데 db별로 제공하려면 분할삭제가 필요

### 서비스 시작 ###
/usr/local/apache/bin/apachectl start # 아파치 시작
service mysqld start # mysql 시작
wall "End Backup"

### 백업 파일 이동 ###
if [ -d $vm_shared ];then
 # 오늘 날짜의 파일들을 모두 이동
 mv $backup_path`date +%Y%m%d`* $vm_shared
 # db파일은 용량이 작으니 웹 파일만 삭제한다.
 find $vm_shared*.tar.gz -mtime $delete_date -print -exec rm -rf {} \;
fi
# chmod 755 backup.sh
# chmod -x backup.sh
# vi /etc/crontab
	0 5 * * 1,4 root /bin/backup.sh
	# 월요일(1), 목요일(4) 새벽5시에 실행한다

외부백업은 ftp를 이용하는게 보통입니다만.. vmware 에다 OS를 설치한거라 복사/삭제 하는 것으로 백업을 종료합니다.

파일이 삭제되더라도 클라우드 프로그램을 이용, 웹에 파일이 보관됩니다.

많이 알려진 클라우드 프로그램으로는 ucloud - 50G(kt사용자), NDrive - 30G, Daum Cloud - 50G 등이 있습니다.

번호 제목 날짜 조회 수
81 vmware with centos 7 secret 2019.08.23 0
80 php-fpm tcp to socket secret 2020.01.25 0
79 net::ERR_CONNECTION_REFUSED secret 2021.10.11 0
78 my.cnf secret 2019.04.11 1
77 To download large files with rsync command. 2023.05.04 21
76 The best configuration of php7.4-fpm / 8GB 2023.05.04 23
75 The best configuration of php7.4-fpm / 1.5GB 2023.05.04 29
74 windows hardware encrypt ssd 2024.01.23 239
73 php 에서 비동기 처리하는 방법 2023.06.22 315
72 gearman 은 무엇인가? 2023.06.21 320
71 apache2 AllowOverride config 2023.05.23 328
70 mysqldump from remote db to my local server. 2023.05.04 421
69 yum install php 7.1 [6] 2018.10.10 687
68 mysql 백업 (shell script) file 2018.10.14 697
67 munin 설치 2018.10.13 787
66 yum install mariadb [2] 2018.10.10 1143
65 웹 백업 (쉘 스크립트) file 2018.10.14 1194
64 certbot apache multiple domain 2019.04.10 1416
63 yum install php-apcu 2019.03.12 1542
62 yum install latest redis file 2019.03.27 1682