前一篇有提到我還需要備份 字典的 Content , 如法泡製 , 相關內容如下:
先用 crontab 增加一項目:
crontab -l 的內容如下: (擷取 相關的 )
0 23 * * 5 /home/jeff/bin/backup-content.sh > /home/jeff/backup-content.txt 2>&1
相對的 ,寫一個 shell file . 如下:
動作和 之前 SVN 備份差不多 , 只是這次直接對 NAS 上 進行備份 , 並且使用 7z 壓縮程式 !! (tar 好像超過 4G 會有問題 ) .
#!/bin/sh
#
# vi:set ts=4:
## ===== defind echo color
COLOR_ECHO="echo -e" ## in Fedora the color echo need have -e argument.
COLOR_NORMAL="\033[0m"
COLOR_BOLD="\033[1m"
COLOR_RED="\033[31m"
COLOR_GREEN="\033[32m"
COLOR_YELLOW="\033[33m"
## ===== define source and distnation dir .
BACKUP_SRC="/home/${USER}/NAS/Project/Content"
BACKUP_DEST="/home/${USER}/NAS/Project/backup"
NAS_KEEP_ITEM=12
################################################
#### check log file size.
################################################
LOG_MAX_SZ=`echo "1048576 * 100" | bc -l `
LOG_FILE=/home/${USER}/backup-content.log
TXT_FILE=/home/${USER}/backup-content.txt
if [ -e ${LOG_FILE} ];then
_file_sz=`ls -l ${LOG_FILE} | awk '{print $5}'`
if [ ${_file_sz} -gt ${LOG_MAX_SZ} ];then
rm ${LOG_FILE}
fi
fi
################################################
#### chekc NAS direct
################################################
if [ ! -e /home/${USER}/NAS ];then
${COLOR_ECHO} "${COLOR_BOLD}""${COLOR_RED}""#### NAS file system not exist !! ""${COLOR_NORMAL}"
exit 1
elif [ ! -e ${BACKUP_DEST} ];then
${COLOR_ECHO} "${COLOR_BOLD}""${COLOR_RED}""#### backup dir not exist !! ""${COLOR_NORMAL}"
exit 1
fi
#### Check NAS content source dir
if [ ! -e ${BACKUP_SRC} ];then
${COLOR_ECHO} "${COLOR_BOLD}""${COLOR_RED}""#### Content source dir not exist !! ""${COLOR_NORMAL}"
exit 1
fi
################################################
#### Check 7z tools
################################################
COMPRESS_7Z="/usr/local/bin/7z"
VER_7Z=`${COMPRESS_7Z} | grep Copyright | sed 's/Copyright.*//g' | awk '{print $2}'`
## echo "VER_7Z:${VER_7Z}"
## echo "COMPRESS_7Z:${COMPRESS_7Z}"
if [ -z "${VER_7Z}" ];then
${COLOR_ECHO} "${COLOR_BOLD}""${COLOR_RED}""#### Compress Tool 7Z not found !! ""${COLOR_NORMAL}"
exit 1
else
${COLOR_ECHO} "${COLOR_BOLD}""${COLOR_GREEN}""#### 7Z Version is ${VER_7Z} . ""${COLOR_NORMAL}"
fi
################################################
#### Start back up
################################################
_cur_date=`date +%Y_%m_%d`
_bak_name=${BACKUP_DEST}/Content_${_cur_date}.7z
${COLOR_ECHO} "${COLOR_BOLD}""${COLOR_GREEN}""#### Strating Compress ${BACKUP_SRC} ...... ""${COLOR_NORMAL}"
## echo "***************"" 7z a ${_bak_name} ${BACKUP_SRC} "
${COMPRESS_7Z} a ${_bak_name} ${BACKUP_SRC}
################################################
#### Remove oldset back up files .
################################################
## rm oldest back up file
_lists=`find ${BACKUP_DEST}/* | xargs ls -t | grep -n ".7z"`
## echo "_lists:${_lists}"
for _del_item in ${_lists} ; do
_list_id=`echo ${_del_item} | sed 's/:.*//g' `
_item_name=`echo ${_del_item} | sed 's/.*://g' `
if [ ${_list_id} -gt ${NAS_KEEP_ITEM} ];then
## echo "***************"" rm -vf ${_item_name} "
rm -vf ${_item_name}
fi
done
################################################
if [ -e ${TXT_FILE} ];then
cat ${TXT_FILE} >> ${LOG_FILE}
fi
################################################
沒有留言:
張貼留言