The compression of Powershell

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.