#在指定日期运行
today=$(date +%Y-%m-%d)
month=${today:5:2}
date=${today:8:2}
if [ "$date" != "4" ]; then
echo "it will be run at yyyy-MM-04"
exit
fi
#只保留两个月
function check_dir()
{
dir_name=$1
if [ "${today:0:4}" = "${dir_name:0:4}" ]; then
mdstr=${dir_name#*"-"}
mstr=${mdstr%"-"*}
if [ "${mstr:0:1}" = "0" ]; then
mstr=${mstr#*"0"}
fi
res=$(($month-$mstr))
if [ $res -lt 2 ]; then
return 1
fi
fi
return 0
}
backuplog="/backup/backup_report.log"
over="/log/over_"
back="/backup/report/"
logtype1="logtype1"
logtype2="logtype2"
logtype3="logtype3"
logtype4="logtype4"
logtype_array=($logtype1 $logtype2 $logtype3 $logtype4)
length=${#logtype_array[*]}
while [ $index -lt $length ]
do
over_path=$over${logtype_array[$index]}"/"
back_path=$back${logtype_array[$index]}"/"
`echo "------------------------------------------------------" >> $backuplog`
`echo ${logtype_array[$index]}" backup start!" >> $backuplog`
`echo "------------------------------------------------------" >> $backuplog`
`echo "" >> $backuplog`
for dir in `ls $over_path`
do
if `check_dir $dir`; then
nowdate=`date`
`echo "$nowdate now backup $dir" >> $backuplog`
cd $back_path
if [ ! -d "$dir" ]; then
`mkdir $dir`
fi
cd $over_path$dir
`tar -zcf $dir".tar.gz" *`
`mv $dir".tar.gz" $back_path$dir"/"`
cd $over_path
`rm -rf $dir`
fi
done
`echo "" >> $backuplog`
`echo "------------------------------------------------------" >> $backuplog`
`echo ${report_array[$index]}" backup end!" >> $backuplog`
`echo "------------------------------------------------------" >> $backuplog`
index=`expr $index + 1`
done
?