When the management of the system more and more, to assist the development through the log to find the problem, I believe that many operations personnel in the daily work of the most headache problem, repeated debugging, back and forth to tune the log, in this case, the system's log mode must also be adjusted to the info level, followed by the rapid growth of log files, result in periodic cleanup.
As a result, I used the log separation mode to keep the system logs on a single Windows Server, because I'm going to compress these log files periodically and shrink the server storage space.
Function auto-zip{ if (-not (test-path $args [0]) { Write-Warning "Please specify a directory" 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 " -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 "Start compressing! $file" -ForegroundColor Green winrar a $zipname $file -ibck -t -df } }} #调用, If your logs are stored in D:\logs\nginxauto-zip d:\logs,
This article is from the "bxing" blog, make sure to keep this source http://bxing.blog.51cto.com/1677994/1875916
The compression of Powershell