自动脚本到拉链IIS记录?
-
09-06-2019 - |
题
我想写的脚本/批次,这将帮了我的每日IIS记录和邮他们通过个月。
ex080801.日志是在格式前月.日志
ex080801.登ex080831.日志得到压缩和登录文件的删除。
我们之所以这样做是因为上一个沉重的网站登录文件某一天可能500兆到1gb因此,我们zip他们,将他们通过98%和倾倒的现实的日志的文件。我们使用webtrend分析的记录文件和它能够读到的一个压缩文件。
没有任何人有任何想法,如何编写脚本,这或愿意分享一些代码?
其他提示
这是我的脚本,这基本上适应大卫的,拉链上个月的记录,移动他们,并删除原来的日志的文件。这可以适用于Apache日志。唯一的问题是你可能需要编辑的替换指令,如果你DOS日期功能的产出之日起的一周。你还需要安装7-zip。
你也可以下载IISlogslite但它压缩每天的文件变成一个单一的拉链文件,该文件我没有找到有用的。有一个vbscript浮动有关的网页,做同样的事情。
------------------------------------------------------------------------------------- @echo on :: Name - iislogzip.bat :: Description - Server Log File Manager :: :: History :: Date Authory Change :: 27-Aug-2008 David Crow Original (found on stack overflow) :: 15-Oct-2008 AIMackenzie Slimmed down commands :: ======================================================== :: setup variables and parameters :: ======================================================== :: generate date and time variables set month=%DATE:~3,2% set year=%DATE:~8,2% ::Get last month and check edge conditions set /a lastmonth=%month%-1 if %lastmonth% equ 0 set /a year=%year%-1 if %lastmonth% equ 0 set lastmonth=12 if %lastmonth% lss 10 set lastmonth=0%lastmonth% set yymm=%year%%lastmonth% set logpath="C:\WINDOWS\system32\LogFiles" set zippath="C:\Program Files\7-Zip\7z.exe" set arcpath="C:\WINDOWS\system32\LogFiles\WUDF" :: ======================================================== :: Change to log file path :: ======================================================== cd /D %logpath% :: ======================================================== :: zip last months IIS log files, move zipped file to archive :: then delete old logs :: ======================================================== %zippath% a -tzip ex%yymm%-logs.zip %logpath%\ex%yymm%*.log move "%logpath%\*.zip" "%arcpath%" del %logpath%\ex%yymm%*.log
我们用一个脚本如下。Gzip是从cygwin项目。我敢肯定你可以修改的语法使用拉链工具。"跳过"的说法是数量的文件没有归档断--我们保留11天的"当前"的目录。
@echo off
setlocal
For /f "skip=11 delims=/" %%a in ('Dir D:\logs\W3SVC1\*.log /B /O:-N /T:C')do move "D:\logs\W3SVC1\%%a" "D:\logs\W3SVC1\old\%%a"
d:
cd "\logs\W3SVC1\old"
gzip -n *.log
Endlocal
exit
你可以抓住的命令行实用工具包 DotNetZip 要获得工具创建的拉链从脚本。有一个漂亮的小工具Zipit.exe 上运行的命令行,增加了文件或目录的附件。这是快速、高效率。
一个更好的选择可能是刚刚做了压缩内置。
function ZipUp-Files ( $directory )
{
$children = get-childitem -path $directory
foreach ($o in $children)
{
if ($o.Name -ne "TestResults" -and
$o.Name -ne "obj" -and
$o.Name -ne "bin" -and
$o.Name -ne "tfs" -and
$o.Name -ne "notused" -and
$o.Name -ne "Release")
{
if ($o.PSIsContainer)
{
ZipUp-Files ( $o.FullName )
}
else
{
if ($o.Name -ne ".tfs-ignore" -and
!$o.Name.EndsWith(".cache") -and
!$o.Name.EndsWith(".zip") )
{
Write-output $o.FullName
$e= $zipfile.AddFile($o.FullName)
}
}
}
}
}
[System.Reflection.Assembly]::LoadFrom("c:\\\bin\\Ionic.Zip.dll");
$zipfile = new-object Ionic.Zip.ZipFile("zipsrc.zip");
ZipUp-Files "DotNetZip"
$zipfile.Save()
这里是powershell的答案,可以创造奇迹:
param([string]$Path = $(read-host "Enter the path"))
function New-Zip
{
param([string]$zipfilename)
set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
(dir $zipfilename).IsReadOnly = $false
}
function Add-Zip
{
param([string]$zipfilename)
if(-not (test-path($zipfilename)))
{
set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
(dir $zipfilename).IsReadOnly = $false
}
$shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($zipfilename)
foreach($file in $input)
{
$zipPackage.CopyHere($file.FullName)
Start-sleep -milliseconds 500
}
}
$FilesToZip = dir $Path -recurse -include *.log
foreach ($file in $FilesToZip) {
New-Zip $file.BaseName
dir $($file.directoryname+"\"+$file.name) | Add-zip $($file.directoryname+"\$($file.basename).zip")
del $($file.directoryname+"\"+$file.name)
}
我们使用这powershell脚本: http://gallery.technet.microsoft.com/scriptcenter/31db73b4-746c-4d33-a0aa-7a79006317e6
它采用7-zip和验证文件之前删除它们
Regex会做的绝招...创建一个perl/python/php script做的工作。
我敢肯定windows批文件不可能做regex.