Skip to content

AEM Log Rotation Powershell

Following is the powershell script to rotate logs depending on the retention policy.

$DAYS_TO_DELETE="-2"
$CurrentDate = Get-Date
$TIMESTAMP=$(get-date -f yyyy_MM_dd_hhmmss)
$DatetoDelete = $CurrentDate.AddDays($DAYS_TO_DELETE)
$LOGPATH="C:UsersSKYDEVOPSDesktoplogs"
$BACKUP_PATH="C:UsersSKYDEVOPSDesktopbackups"
$ARCHIVEPATH="${BACKUP_PATH}archive_$TIMESTAMP";

if ((Test-Path -path $BACKUP_PATH)) {
mkdir $ARCHIVEPATH > $null
}
else {
Write-Output "Backup Directory Not Found"
}

if ((Test-Path -path $LOGPATH)) {
echo " "
Write-Output "AEM logs Found, compressing and rotating logs"
}
else {
echo " "
Write-Output "AEM logs not found, Exiting"
Exit
}

# Moving logs to archive directory
Get-ChildItem -Path $LOGPATH -Exclude "upgrade.log", "startup.log", "request.log", "error.log", "history.log", "access.log", "audit*.log" | Where-Object { $_.LastWriteTime -lt $DatetoDelete } | Move-Item -Destination "$ARCHIVEPATH"

# Compressing
compress-archive -Path $ARCHIVEPATH -CompressionLevel optimal -DestinationPath "${BACKUP_PATH}archive_$TIMESTAMP.zip"
Remove-Item -Path $ARCHIVEPATH -Recurse

Shashi View All

-== Superman ==-

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: