Skip to content

AEM OAK Offline Compaction on Remote Windows Server

Disclaimer:

This is just a custom guide to run compaction on AEM Author/Publish service  on remote windows server, this could be more technical and advanced guide, if you do not understand or don’t know what you are doing, I kindly request you to take extreme caution. The components used here are billable. SKYDEVOPS/I/WE do not take any responsibility if the guide causes any serious damage or issues, which you have to take full responsibility.

Tools Needed:

  1. Download Oak-run JAR form here

Step-01: Create a Free style Job on Jenkins

Screen Shot 2018-05-03 at 3.05.26 PM

Step-02: Setup a parameterised build job, create a string parameter for remote Host

Screen Shot 2018-05-03 at 3.07.01 PM

Step-03: Setup a string parameter for remote User

Screen Shot 2018-05-03 at 3.33.27 PM

Step-04: Setup a String parameter for Remote User Password

Screen Shot 2018-05-03 at 3.34.21 PM

Step-05: Create a Powershell script to run oak offline compaction on  AEM

[code lang=powershell]

# stopping the job if it encounters error
$ErrorActionPreference = ‘Stop’
$WarningPreference = ‘SilentlyContinue’

# Credentials are stored in env and dynamic variables
$SecurePassword = $env:Password | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $env:User, $SecurePassword

# Invoke a command on the remote machine.
Invoke-Command -ComputerName $env:Computer -Credential $cred -ScriptBlock {

$ServiceName = ‘AEM6A’
$arrService = Get-Service -Name $ServiceName
$compactionPATH = ‘C:\Users\SKYDEVOPS\Desktop\AEM\compaction’
$compactionARGS = ‘-Dsun.arch.data.model=32 -Doak.compaction.eagerFlush=true -Dcompaction-progress-log=5000000 -Dupdate.limit=2500000 -Dcompress-interval=150000000’
$compArgsLogBoook = “${compactionARGS} -Dlogback.configurationFile=${compactionPATH}\logback-compaction.xml”
$segmentstorePATH = ‘C:\Users\SKYDEVOPS\Desktop\AEM\author\crx-quickstart\repository\segmentstore’
$TIMESTAMP=$(get-date -f yyyy_MM_dd_hhmmss)
$BACKUP_PATH=”C:\Users\SKYDEVOPS\Desktop\backups”
$ARCHIVEPATH=”${BACKUP_PATH}archive_$TIMESTAMP”;
function Get-Size
{
param([string]$pth)
“{0:n2}” -f ((gci -path $pth -recurse | measure-object -property length -sum).sum /1mb) + ” MB”
}

if ($arrService.status -eq ‘Running’) {
write-host $ServiceName is currently $arrService.status
write-host “Stopping $ServiceName”
Stop-Service $ServiceName -warningaction SilentlyContinue
Start-Sleep -seconds 30
$arrService.Refresh()
if ($arrService.status -eq ‘STOPPED’) {
write-host $ServiceName is STOPPED
$sizeBefore = Get-Size $segmentstorePATH
write-host “Size of the segmentstore before Compation: $sizeBefore”
write-host “Backing up segmentstore”
compress-archive -Path $segmentstorePATH -CompressionLevel optimal -DestinationPath “${BACKUP_PATH}\segmentstore_archive_$TIMESTAMP.zip”
write-host “Backup Complete”
write-host “Starting Compaction”
java -server -Xmx3g ${compArgsLogBoook} -jar ${compactionPATH}\oak-run-1.6.1.jar compact ${segmentstorePATH} >> “${BACKUP_PATH}\oak-tar-compact-$TIMESTAMP.log”
write-host Compation Completed
$sizeAfter = Get-Size $segmentstorePATH
write-host “Size of the segmentstore after Compation: $sizeAfter”
write-host Starting $ServiceName
Start-Service $ServiceName
if ($arrService.status -eq ‘Running’) {
write-host $ServiceName Started
}
}
}
elseif ($arrService.status -eq ‘STOPPED’) {
write-host $ServiceName is STOPPED
$sizeBefore = Get-Size $segmentstorePATH
write-host “Size of the segmentstore before Compation: $sizeBefore”
write-host “Backing up segmentstore”
compress-archive -Path $segmentstorePATH -CompressionLevel optimal -DestinationPath “${BACKUP_PATH}\segmentstore_archive_$TIMESTAMP.zip”
write-host “Backup Complete”
write-host “Starting Compaction”
java -server -Xmx3g ${compArgsLogBoook} -jar ${compactionPATH}\oak-run-1.6.1.jar compact ${segmentstorePATH} >> “${BACKUP_PATH}\oak-tar-compact-$TIMESTAMP.log”
write-host Compation Completed
$sizeAfter = Get-Size $segmentstorePATH
write-host “Size of the segmentstore after Compation: $sizeAfter”
write-host Starting $ServiceName
Start-Service $ServiceName
if ($arrService.status -eq ‘Running’) {
write-host $ServiceName Started
}
}
}

[/code]

Step-06: logbook-compaction.xml

Screen Shot 2018-05-03 at 4.23.55 PM.png

Shashi View All

-== Superman ==-

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: