当管理的系统越来越多,协助开发通过日志查找问题,相信是很多运维人员在日常工作中最头疼的问题,反复调试,来回调取日志,在这种情况下,系统的日志模式也必须调整为info级别,随之而来的也是日志文件的快速增长,导致要定期进行清理。
于是乎,我采用了日志分离模式,将系统日志统一存放在一台Windows服务器上,因为接下来我要将这些日志文件定时进行压缩,收缩服务器存储空间。
function Auto-Zip{
if(-not (Test-Path $args[0])){
Write-Warning "请指定一个目录"
break
}
dir $args[0]|?{$_ -is [System.IO.DirectoryInfo]}|
foreach{
$LogPath=$_.FullName
$nowDate=(Get-Date).ToString().Split(" ")[0]
dir $LogPath|?{$_ -is [System.IO.FileInfo] -and $_.name -match "2015" -and $_.name -notmatch ".zip$" -and $_.name -notmatch ".rar$"}|
foreach{
$file=$_.FullName
$zipname=$file+".zip"
while(Get-Process -Name winrar -ErrorAction SilentlyContinue){
sleep -milliseconds 500
}
Write-Host "开始压缩! $file" -ForegroundColor Green
winrar a $zipname $file -ibck -t -df
}
}
}
#调用,假如你的日志存放在D:\Logs\nginx
Auto-Zip D:\Logs
转载于:https://blog.51cto.com/bxing/1875916
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)