mirror of
https://github.com/dreamforceinc/wDayzLogRotation.git
synced 2026-02-04 07:12:52 +03:00
Update wDayzLogRotation.ps1
Changed validation of parameters.
This commit is contained in:
@@ -7,18 +7,18 @@
|
|||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
# powershell.exe -File "wDayzLogRotation.ps1" "Z:\Servers\DayZServer" "Instance_1" "D:\server tools\BEC"
|
# powershell.exe -File "wDayzLogRotation.ps1" "Z:\Servers\DayZServer" "Instance_1" "D:\server tools\BEC"
|
||||||
#
|
|
||||||
# ----------[ Configuration ]----------
|
|
||||||
$date = Get-Date # Get current system date
|
|
||||||
$daysAmount = 7 # Number of days to store logs
|
|
||||||
$noDelete = $false # For tests - don't delete logs
|
|
||||||
$serverLocation = $args[0] # Path to server's location
|
|
||||||
$instance = $args[1] # Instance's NAME (relative to server's root path!) of folder
|
|
||||||
$becLocation = $args[2] # Path to BEC
|
|
||||||
|
|
||||||
if (!$serverLocation) { $serverLocation = "Z:\DayZServer" }
|
# ------------------------------[ Configuration ]------------------------------
|
||||||
if (!$instance) { $instance = "Instance" }
|
$daysAmount = 7 # Number of days to store logs
|
||||||
if (!$becLocation) { $becLocation = "${serverLocation}\BEC" }
|
$serverLocation = "Z:\DayZServer" # Path to server's location
|
||||||
|
$instance = "Instance_1" # Instance's NAME.
|
||||||
|
$becLocation = "${serverLocation}\BEC" # Path to BEC
|
||||||
|
$noDelete = $false # For tests - don't delete logs
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
if ($args[0]) { $serverLocation = $args[0] }
|
||||||
|
if ($args[1]) { $instance = $args[1] }
|
||||||
|
if ($args[2]) { $becLocation = $args[2] }
|
||||||
|
|
||||||
if ([System.IO.Path]::IsPathRooted($instance)) {
|
if ([System.IO.Path]::IsPathRooted($instance)) {
|
||||||
$instanceDir = "${instance}"
|
$instanceDir = "${instance}"
|
||||||
@@ -32,12 +32,12 @@ if (![System.IO.Path]::IsPathRooted($becLocation)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$destDir = "${instanceDir}\RotatedLogs"
|
$destDir = "${instanceDir}\RotatedLogs"
|
||||||
$destDelDir = $destDir
|
|
||||||
$daysAmount = [Math]::Abs($daysAmount)
|
$daysAmount = [Math]::Abs($daysAmount)
|
||||||
$becLogDir = "${becLocation}\Log\${instance}"
|
$becLogDir = "${becLocation}\Log\${instance}"
|
||||||
$becDestDir = "${destDir}\BEC"
|
$becDestDir = "${destDir}\BEC"
|
||||||
|
|
||||||
Write-Host "Start Log rotation powershell script"
|
Write-Host "Start Log rotation powershell script"
|
||||||
|
$date = Get-Date
|
||||||
|
|
||||||
# # Debug output
|
# # Debug output
|
||||||
# Write-Host "serverLocation: '${serverLocation}'"
|
# Write-Host "serverLocation: '${serverLocation}'"
|
||||||
@@ -68,7 +68,8 @@ Write-Host "Total: $($fileList.Length)"
|
|||||||
$fileList = Get-Item -Path $destDir\*.rpt, $destDir\*.log, $destDir\*.adm | Where-Object { $_.LastWriteTime -lt $date.AddDays(-($daysAmount)) }
|
$fileList = Get-Item -Path $destDir\*.rpt, $destDir\*.log, $destDir\*.adm | Where-Object { $_.LastWriteTime -lt $date.AddDays(-($daysAmount)) }
|
||||||
# Write-Host $fileList -Separator "`r`n"
|
# Write-Host $fileList -Separator "`r`n"
|
||||||
|
|
||||||
Write-Host "Removing RPTs and LOGs:"
|
Write-Host "Removing RPTs, ADMs and LOGs:"
|
||||||
|
$destDelDir = $destDir
|
||||||
if ($noDelete) {
|
if ($noDelete) {
|
||||||
$destDelDir = "${destDir}\DeletedLogs"
|
$destDelDir = "${destDir}\DeletedLogs"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user