How do we solve not enough space as logs of Internet Information System
Environment
Introduction
Server was continuously not enough space as logs of IIS
Solution
Found that was caused by our DSLibrary's logs, therefore, changing its directory. Righ click "Properties". Select tab "Web Site" - "Properties"
Also, scheduled to run a powershell script to zip the older logs
- Microsoft Internet Information System (IIS)
Introduction
Server was continuously not enough space as logs of IIS
Solution
Found that was caused by our DSLibrary's logs, therefore, changing its directory. Righ click "Properties". Select tab "Web Site" - "Properties"
Also, scheduled to run a powershell script to zip the older logs
#@example command .\ZipLogs.ps1 -path "C:\tmp\Folder 1"
#
#@example for scheduled task powershell & 'C:\bin\ZipLogs.ps1 -path \"C:\tmp\Folder 1\"'
param (
[string]$path = "D:\Logfiles\W3SVC1",
[int]$day = -90
)
$files = "*.log"
$temp = (Get-Childitem -path env:temp).value
$foldername = ((Get-Item $path).name + (Get-Date -format yyyyMMdd))
$zipfilename = ($path + "\" + $foldername + ".zip")
# Folders for archive
$tempfolder = $temp + "\" + $foldername
if (-not (Test-Path($tempfolder))) {
New-Item -type directory -path ($tempfolder)
} else {
echo "Duplicated folder: " + $tempfolder
return
}
# Move 90days older items
Get-Childitem $path -recurse | where-object {$_.lastwritetime -lt (Get-Date).adddays($day)} | where-object {-not $_.PSIsContainer} | Foreach-Object {Move-Item $_.FullName ($tempfolder)}
# Zip items
if (-not (Test-Path($zipfilename))) {
$7zip = "hklm:\software\7-zip\"
# Use 7zip better for a large file
if (Test-Path $7zip) {
$startInfo = New-Object System.Diagnostics.ProcessStartInfo
$startInfo.FileName = ((get-itemproperty $7zip).Path + '\7z.exe')
$startInfo.Arguments = ' a "' + $zipfilename + '" "' + $path + '\' + $files + '"'
$startInfo.WindowStyle = "Hidden"
$startInfo.CreateNoWindow = $true
$process = [System.Diagnostics.Process]::Start($startInfo)
$process.WaitForExit()
} else {
# Header of zipping
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)
$files = dir ($tempfolder + "\" + $files) -Recurse
foreach ($file in $files) {
$zipPackage.CopyHere($file.Fullname)
#To ensure that file is zipped
Start-Sleep -milliseconds 500
}
}
} else {
echo "Duplicated file: " + $zipfilename
return
}
# Remove temporary items
Remove-Item $tempfolder -Recurse