일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- DNS
- ext4
- pid
- ext3
- Linux
- windows
- 솔라리스
- PORT
- rsync
- Kernel
- rm -rf
- Disk
- iptables
- 좌절교육
- Python
- Performance
- http
- 리눅스
- goaccess
- Hack
- Cache
- rm
- 디스크
- CPU
- Bash
- 칭찬교육
- cadre
- PERL
- apachetop
- 쇼펜의상속자 #킨텍스메가쇼 #섬유향수탈취제
- Today
- Total
Ben's
ext3 snapshot backup 본문
#!/bin/bash
#
# created by nhko 090612
# version 0.3
#############################################################
# ** 추가된 기능 **
#############################################################
# 프로그램 중복실행 체크
# 백업 디스크 유무 체크
# rsync 패스 자동검색
# 프로그램 실행 전 check_disk.pl 수행
# 백업 파일명 수정
# source 를 /home/download 전체로 지정.
# 원하는 파일은 찾는 시간보다 한시간 후를 기준으로 해야 한다.
#############################################################
# Define the variable
DATE=`date +%y%m%d%H%M`;
SDATE=`date +%F-%T`;
/bin/mkdir -p /var/lock/snapshot
# Create array
declare -a FILENAME
FILENAME[1]=`date +%y%m%d%H%M`
# Check the rsync path
/usr/bin/whereis rsync | awk '{print $2}' > /var/lock/snapshot/rsyncpath
COPY=`cat /var/lock/snapshot/rsyncpath`;
# Check the Start time
/bin/mkdir -p /root/log
echo "Start Time... "$SDATE >> /root/log/snapshot_start.log;
# SYNC the DISK
/bin/sync; /bin/sleep 5;
# Check the free space of disk
/root/system_tools/monitor/check_disk.pl > /var/lock/snapshot/check_disk
if [ -s /var/lock/snapshot/check_disk ]
then
echo "Check the free space of disk"
exit 1;
fi
# Check the target disk
/bin/mount | grep snapshot > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "Target is not exist"
exit 1;
fi
# Check the process duplication
if [ -f /var/lock/snapshot/sn ]
then
echo "This Script is running"
/bin/rm -f /var/lock/snapshot/sn
echo "Touch file was deleted. Try again"
exit 1;
fi
# Make a touch file
/bin/touch /var/lock/snapshot/sn
############################################################################
# BACKUP PROCESS ###########################################################
# remount a target directory(ro -> rw)
/bin/mount -o remount,rw /dev/sdb8 /snapshot
echo "success the remount"
# delete a expire file(7일 보관)
/bin/rm -f /tmp/COUNTLIST
cd /snapshot; find . -maxdepth 1 -type d -mtime +7 | egrep -v 'backup|\.$' | awk '{print "/bin/rm -rf /snapshot/"$0}' > /tmp/COUNTLIST
/bin/chmod 700 /tmp/COUNTLIST && /tmp/COUNTLIST
# disconect inode
if [ ! -z ${FILENAME[1]} ]
then
/bin/cp -al /snapshot/backup.0 /snapshot/${FILENAME[1]} >> /root/system_tools/log/hardlinkcopy.log
touch -r /var/lock/snapshot/rsyncpath /snapshot/${FILENAME[1]}
echo "disconnect inode"
fi
echo "$COPY";
# rsync data
/bin/mkdir -p /snapshot/backup.0/var
/bin/mkdir -p /snapshot/backup.0/sysadmin
/bin/mkdir -p /snapshot/backup.0/root
/bin/mkdir -p /snapshot/backup.0/cron
$COPY -a --delete /home/mysql/var/ /snapshot/backup.0/var >> /root/system_tools/log/rsync_mysqlvar.log
$COPY -a --delete /home/sysadmin/ /snapshot/backup.0/sysadmin >> /root/system_tools/log/rsync_sysadmin.log
$COPY -a --delete /root/ /snapshot/backup.0/root >> /root/system_tools/log/rsync_root.log
$COPY -a --delete /var/spool/cron/ /snapshot/backup.0/cron >> /root/system_tools/log/rsync_cron.log
touch -r /var/lock/snapshot/rsyncpath /snapshot/backup.0
echo "rsync a data"
# remount a target directory(rw -> ro)
/bin/mount -o remount,ro /dev/sdb8 /snapshot
echo "success the remount"
############################################################################
# Check the End time
EDATE=`date +%F-%T`;
echo "End Time... "$EDATE >> /root/log/snapshot_end.log;
# SYNC the DISK
/bin/sync; /bin/sleep 5;
# Remove the touch file
/bin/rm -f /var/lock/snapshot/sn
'리눅스 > bash' 카테고리의 다른 글
basename 유용할 듯. (0) | 2013.04.16 |
---|---|
nl (0) | 2013.04.03 |
debian 한글 설정 (0) | 2013.01.28 |
쉘 스크립트에서 글자 색 적용 (0) | 2013.01.21 |
문자별로 필드 구분시키기 (0) | 2013.01.21 |