定期备份脚本案列
用tar压缩7天前日志
删除7天压缩完日志
删除压缩完356天前日志
#!/bin/bash
#delete expire log
#script name drop_log
#script default remove 7 day log and remove remove archived a year ago
#make date 2015/06/15
result_client=`find /orafile/app/smsclient/runlogs/ -mtime +7 -name "*log.*"|awk -F '/' '{print $6}'`
result_server=`find /orafile/app/smsserver/runlogs/ -mtime +7 -name "*log.*"|awk -F '/' '{print $6}'`
a=`echo $result_client|wc -c`
b=`echo $result_server|wc -c`
if [ $a -gt 1 ] ; then #判断有没有压缩记录
#for log_list in $result_client
#do
#auto_seq=$((auto_seq+1))
rj=`date +%Y%m%d`
if [ -f /orafile/runlogs/client$rj.tar.gz ] ; then #判断文件有没有存在
echo "file already exists"
else
cd /orafile/app/smsclient/runlogs/
tar -czvf /orafile/runlogs/client$rj.tar.gz $result_client >/dev/null #这里指定压缩路径
RESULT=$?
if [ $RESULT -eq 0 ] ; then
echo "client log The backup successful"
else
echo "client log The backup failed"
fi
if [ $RESULT -eq 0 ] ; then
cd /orafile/app/smsclient/runlogs/ #切换要删除目录
rm -f $result_client #删除已经压缩日志
RESULT=$?
if [ $RESULT -eq 0 ] ; then
echo "client log The delete successful"
else
echo "client log The delete failed"
fi
fi
fi
#done
else
echo "There is no backup"
fi
if [ $b -gt 1 ] ; then #判断有没有压缩记录
#for log_list_1 in $result_server
#do
#auto_1_seq=$((auto_1_seq+1))
if [ -f /orafile/runlogs/server$rj.tar ] ; then #判断文件有没有存在
echo "file already exists"
else
cd /orafile/app/smsserver/runlogs/
tar -czvf /orafile/runlogs/server$rj.tar.gz $result_server >/dev/null #这里指定压缩路径
RESULT=$?
if [ $RESULT -eq 0 ] ; then
echo "server log The backup successful"
else
echo "server log The backup failed"
fi
if [ $RESULT -eq 0 ] ; then
cd /orafile/app/smsserver/runlogs/ #切换要删除目录
rm -f $result_server #删除已经压缩日志
RESULT=$?
if [ $RESULT -eq 0 ] ; then
echo "server log The delete successful"
else
echo "server log The delete failed"
fi
fi
fi
#done
else
echo "There is no backup"
fi
RESULT=$?
if [ $RESULT -eq 0 ] ; then
find /orafile/runlogs/ -mtime +365 -name "*.tar" -exec rm -f {} \; #修改要删除压缩备份路径默认365天
else
echo "remove archived a year ago failed"
fi
用tar压缩7天前日志
删除7天压缩完日志
删除压缩完356天前日志
#!/bin/bash
#delete expire log
#script name drop_log
#script default remove 7 day log and remove remove archived a year ago
#make date 2015/06/15
result_client=`find /orafile/app/smsclient/runlogs/ -mtime +7 -name "*log.*"|awk -F '/' '{print $6}'`
result_server=`find /orafile/app/smsserver/runlogs/ -mtime +7 -name "*log.*"|awk -F '/' '{print $6}'`
a=`echo $result_client|wc -c`
b=`echo $result_server|wc -c`
if [ $a -gt 1 ] ; then #判断有没有压缩记录
#for log_list in $result_client
#do
#auto_seq=$((auto_seq+1))
rj=`date +%Y%m%d`
if [ -f /orafile/runlogs/client$rj.tar.gz ] ; then #判断文件有没有存在
echo "file already exists"
else
cd /orafile/app/smsclient/runlogs/
tar -czvf /orafile/runlogs/client$rj.tar.gz $result_client >/dev/null #这里指定压缩路径
RESULT=$?
if [ $RESULT -eq 0 ] ; then
echo "client log The backup successful"
else
echo "client log The backup failed"
fi
if [ $RESULT -eq 0 ] ; then
cd /orafile/app/smsclient/runlogs/ #切换要删除目录
rm -f $result_client #删除已经压缩日志
RESULT=$?
if [ $RESULT -eq 0 ] ; then
echo "client log The delete successful"
else
echo "client log The delete failed"
fi
fi
fi
#done
else
echo "There is no backup"
fi
if [ $b -gt 1 ] ; then #判断有没有压缩记录
#for log_list_1 in $result_server
#do
#auto_1_seq=$((auto_1_seq+1))
if [ -f /orafile/runlogs/server$rj.tar ] ; then #判断文件有没有存在
echo "file already exists"
else
cd /orafile/app/smsserver/runlogs/
tar -czvf /orafile/runlogs/server$rj.tar.gz $result_server >/dev/null #这里指定压缩路径
RESULT=$?
if [ $RESULT -eq 0 ] ; then
echo "server log The backup successful"
else
echo "server log The backup failed"
fi
if [ $RESULT -eq 0 ] ; then
cd /orafile/app/smsserver/runlogs/ #切换要删除目录
rm -f $result_server #删除已经压缩日志
RESULT=$?
if [ $RESULT -eq 0 ] ; then
echo "server log The delete successful"
else
echo "server log The delete failed"
fi
fi
fi
#done
else
echo "There is no backup"
fi
RESULT=$?
if [ $RESULT -eq 0 ] ; then
find /orafile/runlogs/ -mtime +365 -name "*.tar" -exec rm -f {} \; #修改要删除压缩备份路径默认365天
else
echo "remove archived a year ago failed"
fi
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29065182/viewspace-1972575/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29065182/viewspace-1972575/