shell 多个程序 log 的备份(二)

LogPath=$HOME/log
if [ ! -d "$LogPath" ]; then
mkdir $LogPath
fi

LD1=`date  -d'-4 day' +'%F'`
LD2=`date  -d'-5 day' +'%F'`
LD3=`date  -d'-6 day' +'%F'`
LE1=`date  -d'-4 day' +'%Y%m%d'`
LE2=`date  -d'-5 day' +'%Y%m%d'`
LE3=`date  -d'-6 day' +'%Y%m%d'`

for d in FpOffering GessFpServer GessMoniSvr GessNetServer GessServer
do
cd $HOME/ylink/$d/log

if [ -d "$LD1" ]; then
tar cvf $d.${LD1}.tar ${LD1}
gzip  ./$d.${LD1}.tar
mv *.gz $HOME/log
rm -rf ${LD1}
fi

if [ -d "$LD2" ]; then
tar cvf $d.${LD2}.tar ${LD2}
gzip  ./$d.${LD2}.tar
mv *.gz $HOME/log
rm -rf ${LD2}
fi

if [ -d "$LD3" ]; then
tar cvf $d.${LD3}.tar ${LD3}
gzip  ./$d.${LD3}.tar
mv *.gz $HOME/log
rm -rf ${LD3}
fi

if [ -d "$LE1" ]; then
tar cvf $d.${LE1}.tar ${LE1}
gzip  ./$d.${LE1}.tar
mv *.gz $HOME/log
rm -rf ${LE1}
fi

if [ -d "$LE2" ]; then
tar cvf $d.${LE2}.tar ${LE2}
gzip  ./$d.${LE2}.tar
mv *.gz $HOME/log
rm -rf ${LE2}
fi

if [ -d "$LE3" ]; then
tar cvf $d.${LE3}.tar ${LE3}
gzip  ./$d.${LE3}.tar
mv *.gz $HOME/log
rm -rf ${LE3}
fi

cd
done

cd $HOME/ylink/FpOffering/log
tar zcvf $HOME/log/`date +'%Y%m%d'`shauapi.tar.gz api_shau*
rm -rf api_shau*
cd

logfile_postfix=monitor.log
logfile_simplelog=simplelog.log
for d in HostSupervise
do
cd $HOME/ylink/$d/log

if [ -f "$LE1$logfile_postfix" ]; then
tar cvf $d.${LD1}.tar ${LE1}$logfile_postfix ${LE1}$logfile_simplelog
gzip  ./$d.${LD1}.tar
mv *.gz $HOME/log
rm -rf ${LE1}$logfile_postfix ${LE1}$logfile_simplelog
fi

if [ -f "$LE2$logfile_postfix" ]; then
tar cvf $d.${LD2}.tar ${LE2}$logfile_postfix ${LE2}$logfile_simplelog
gzip  ./$d.${LD2}.tar
mv *.gz $HOME/log
rm -rf ${LE2}$logfile_postfix ${LE2}$logfile_simplelog
fi

if [ -f "$LE3$logfile_postfix" ]; then
tar cvf $d.${LD3}.tar ${LE3}$logfile_postfix ${LE3}$logfile_simplelog
gzip  ./$d.${LD3}.tar
mv *.gz $HOME/log
rm -rf ${LE3}$logfile_postfix ${LE3}$logfile_simplelog
fi

cd
done

猜你喜欢

转载自blog.csdn.net/u012599988/article/details/78249426