[编写整理:simonzhang 2010-03-15 2012-04-08修改]
在linux下有大量日志需要压缩备份,并定期清理长期保存的备份日志。对于多处日志存放使用数组进行循环处理。脚本修改好后,设置定时任务即可。
#!/bin/sh ############################################## # AUTHOR: simonzhang # back log # Ver : 1.1 For Production # description: # 2010-03-12 ############################################## ####### set log patch log_path=("/usr/local/nginx/logs/" "/usr/local/tomcat6/logs/" ) ####### set backup log patch bak_log_path=("/usr/local/nginx/logs/back" "/usr/local/tomcat6/logs/back") ####### set backup 3 day ago log backupdays=3 #######clear 180 day ago compress log deletedays=180 ####### start for (( i=0 ; i<${#log_path[@]} ; i++ )) do cd ${log_path[i]} if [ ! -f ${bak_log_path[i]} ] ; then /bin/mkdir -p ${bak_log_path[i]} fi /usr/bin/find * -ctime +$backupdays -maxdepth 0 -not -name *.pid -not -name error* -exec zip -m {}.zip {} \; /bin/mv *.zip ${bak_log_path[$i]} cd ${bak_log_path[$i]} echo /usr/bin/find * -ctime +$deletedays -maxdepth 0 -exec rm {} \; done ############ end
发表评论