티스토리 뷰

생활 속/홈서버

RT-N56U Shell Script 백업

이치로 2013. 11. 8. 10:51


여기에 간략하게 방법이 나와 있고, 참고해서 아래와 같이 만들어서 쓴다.


#!/bin/bash

# Variables
export TODAY=`date "+%Y-%m-%d"`
BAK_DESTI="/media/TOSHIBA_EXT/bak_RT-N56U"
PAST_DAY="+60"


# Delete old backup directories
find $BAK_DESTI -mindepth 1 -mtime "$PAST_DAY" -type d -exec rm -rf {} \;

# Create new backup directory
/bin/mkdir -p ${BAK_DESTI}/$TODAY


#################################
# Backup
#################################

# First, stop all applications which started from /opt/etc/init.d.
/opt/etc/init.d/S80nginx stop

mount -t ext3 /dev/sda1 /mnt
cd /mnt
tar -jcvf ${BAK_DESTI}/${TODAY}/opt.tar.bz2 ./opt
tar -jcvf ${BAK_DESTI}/${TODAY}/www.tar.bz2 ./www
cd /etc/storage
umount /mnt

/opt/etc/init.d/S80nginx start

# backup extra things
cp /etc/storage/ddns.sh ${BAK_DESTI}/$TODAY
cp /etc/storage/ddns.log ${BAK_DESTI}/$TODAY
cp /etc/storage/backup.sh ${BAK_DESTI}/$TODAY
cp /etc/storage/started_script.sh ${BAK_DESTI}/$TODAY


오래된 백업 자료를 지우는 방법은 다른 식으로도 구현할 수 있던데, N56U에 내장된 바이너리는 뭔가 기능이 제한적이어서 저게 그나마 최선이었다. 이제 이걸 crontab에 등록을 해야하는데, 이 역시 여기 나와 있는대로 따라하면 된다. 예전에 추가한 DDNS까지 포함한 결과는 아래와 같다.


    #  min | hour |  day |  mon | date
    # 0-59 | 0-23 | 0-31 | 1-12 | 0-7 = SUN-SUN
    echo "* */2 * * * /etc/storage/ddns.sh" >> /var/spool/cron/crontabs/$Login
    # every 2 hour
    echo "0 3 * * 0 /ect/storage/backup.sh" >> /var/spool/cron/crontabs/$Login
    # Every Sunday 3:00 am


뭐 이정도면 충분할 듯...



'생활 속 > 홈서버' 카테고리의 다른 글

My Book Live 벽돌 복구  (0) 2013.11.22
XPenology 이미지 다운로드  (0) 2013.11.14
RT-N56U에서 rsync server 구축하기  (0) 2013.11.06
시놀로지 사설 패키지 및 서버  (0) 2013.10.21
RT-N56U에 nginx 올리기  (0) 2013.05.26
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/03   »
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
31
글 보관함