- #!/bin/bash
- #author: InBi
- #date: 2011-08-05
- #role: backup files periodically.
- #website: <a href="http://www.itwhy.org/2011/07-28/707.html">http://www.itwhy.org/2011/07-28/707.html
- ##################################################
- LogFile=/backup/log/`date +"%Y-%m"`.log
- SourceDir=/var/RDfile
- BakDir=/backup
- RetainDay=20
- ProjectLst=/backup/project.lst
- ##################################################
- DATE=`date +"%Y-%m-%d"`
- echo "backup start at $(date +"%Y-%m-%d %H:%M:%S")" >$LogFile
- echo "--------------------------------------------------" >>$LogFile
- cd $BakDir
- PROJECTLIST=`cat $ProjectLst`
- for Project in $PROJECTLIST
- do
- ProjectData=$SourceDir/$Project
- DestDir=$BakDir/$Project
- PackFile=$DATE.$Project.tgz
- if [ -f $BakDir/$PackFile ]
- then
- echo "backup file have exist !" >>$LogFile
- else
- cp -RHpf $ProjectData $DestDir >/dev/null
- tar -zcvf $PackFile $Project >/dev/null
- echo "backup $Project done into $PackFile" >>$LogFile
- rm -rf $Project
- fi
- done
- find $Bakdir -type f -mtime +$RetainDay -name "*.$Project.tgz" -exec rm {} \\; >/dev/null
- echo "--------------------------------------------------" >>$LogFile
- echo "backup end at $(date +"%Y-%m-%d %H:%M:%S")" >>$LogFile
- echo " " >> $LogFile
- exit 0
- #该片段来自于http://www.codesnippet.cn/detail/130320132400.html
来源: http://www.codesnippet.cn/detail/130320132400.html