#!/bin/bash
##back web directory scripts
#需要备份的目录写入与脚本同级目录test.txt文件中
DIR="/data/server/www"
BACK_DIR="/backup/webbak"
LOG_FILE="$BACK_DIR/wwwback.log"
mkdir -p $BACK_DIR
cat /sh/test.txt |while read line
do
cd $DIR
DATE="$line-`date +'%Y%m%d%H'`"
/bin/tar -zcf $BACK_DIR/$DATE.tar.gz $line
echo ----------"$(date +"%y-%m-%d %H:%M:%S")"------------ >> $LOG_FILE
echo createFile:"$DATE.tar.gz" >> $LOG_FILE
find "$BACK_DIR" -ctime +3 -type f -name "*.tar.gz" -print > /tmp/deleted.txt
echo -e "delete files:
" >> $LOG_FILE
#循环删除匹配到的文件
cat /tmp/deleted.txt | while read LINE
do
rm -rf $LINE
echo $LINE>> $LOG_FILE
done
done
echo "---------------------------------------------------------------" >> $LOG_FILE
需要备份的网站目录
cat /sh/test.txt
abc.com
def.com