Download Oak-run JAR form here
Step-01: Create a Freestyle Job on Jenkins


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


Step-03: Setup a string parameter for remote User


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


Step-05: Create a Powershell script to run oak offline compaction on AEM
[code lang=powershell]
# stopping the job if it encounters an 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

[code lang=powershell]
# stopping the job if it encounters an 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

No comments:
Post a Comment
If you have any doubts or questions, please let us know.