https://www.netcentric.biz/blog/2015/02/tarmk.html
Growth of repositories in CQ, and now AEM, have always been a pain point for most operations teams, and it is sometimes not clear where the problem stems from. It's possible that wrong filters may have been applied, too many nodes were created, or huge renditions were also produced. Other times, it may even be a bug. In any case, Adobe has released the offline compaction method last year which is working great, and they also introduced the online compaction method. Online compaction allows you to trigger a repository compaction from within a running AEM instance via the brand new Operations & Maintenance Dashboard. It also lets you easily schedule it to ensure you have no performance hits during peak usage. Actions in the Dashboard can also be triggered via other means besides the web browser so automation of various processes is a goal that can now be achieved.
ONLINE COMPACTION
Before running any compactions make sure you have a consistent backup you can easily restore to in case its needed. These features are hot off the press!
1. First, get the latest hotfix of Oak which provides you this functionality from the package share for AEM 6.0 (Oak 1.0.22), with AEM 6.1 (Oak 1.2.7) it is built in!
2. Install it (there is a restart of AEM required afterwards) don't restart just stop after it is finished (make sure you tail the logs!)
3. ssh into your machine and use the oak-run.jar matching your oak version to clean up old checkpoints
-> http://mvnrepository.com/artifact/org.apache.jackrabbit/oak-run
4. To clean up the checkpoints follow the steps below
java -jar oak-run.jar checkpoints install-folder/crx-quickstart/repository/segmentstore
java -jar oak-run.jar checkpoints install-folder/crx-quickstart/repository/segmentstore rm-all
5. Now start your AEM again and go to the system console -> JMX -> search for "CompactionStrategy"
6. Make sure the PausedCompaction is set to false as well as CloneBinaries
7. Go to the maintenance dashboard -> http://localhost:4502/libs/granite/operations/content/maintenance/window.html/mnt/overlay/granite/operations/config/maintenance/_granite_daily
8. On there trigger the revision cleanup and tail to logs for progress
9. The log's will tell you how much it cleaned up but you can allways check with -> du -h --max-depth=1 and compare before and after results of your repository folder
If your curious about more functionality (backup etc.) of the oak-run.jar have a look on the jackrabbit github -> https://github.com/apache/jackrabbit-oak/tree/trunk/oak-run
OFFLINE COMPACTION
Offline compaction can be used any time the AEM instance is stopped. This is also a prerequisite to running online compaction if you haven't removed old checkpoints previously.
To see the full effect of the online compaction later, just remove the checkpoints and don't actually run the offline compaction.
- Stop your AEM instance
- Use the oak-run.jar tool to find any old checkpoints -> download -> http://mvnrepository.com/artifact/org.apache.jackrabbit/oak-run
java -jar oak-run.jar checkpoints your-install-folder/crx-quickstart/repository/segmentstore
- Next, delete the unreferenced checkpoints
java -jar oak-run.jar checkpoints your-install-folder/crx-quickstart/repository/segmentstore rm-all
- The final step is to run the compaction and wait for it to complete (tail the logs!)
java -jar oak-run.jar compact your-install-folder/crx-quickstart/repository/segmentstore
CLOSING WORDS OF WISDOM
Make sure you keep track of repository growth as it can easily impact performance or cause a possible outage of the instance due to the system running out of storage space.
With AEM 6, Service Pack 1 and Service Pack 2 are a necessity and should be installed. The later hotfix mentioned applies the latest Oak Fixes and raises it to a version of 1.0.11 of the Oak Core.
Note that some Service Packs and Hotfixes, such as the one for Oak, require a restart! Ensure it gets thoroughly tested beforehand, and plan it into your continuous release cycle for the next deployment to stay up to date.
UPDATE 16.03.2015:
1. If interested in details of the hotfixes have a look on Adobes Hotfix Page
2. A new Hotfix 5916 was released which addreses some possible issues with the Oak garbage collection
------------------------------------------------------------------------
本地测试
C:/Users/David/Desktop/AEMCQ>java -jar oak-run.jar checkpoints C:/Users/David/Desktop/AEMC
Q/crx-quickstart/repository/segmentstore
Reducing the repository size
Download this jar file:
http://docs.adobe.com/content/docs/en/aem/6-0/deploy/upgrade/microkernels-in-aem-6-0/_jcr_content/par/download/file.res/oak-run-1.0.5.jar
Step 1: shut down AEM
Step 2: Use the tool to find checkpoints using the below commands:
java -jar oak-run.jar checkpoints install-folder/crx-quickstart/repository/segmentstore
Step 3: Then, delete the checkpoints using the below command:
java -jar oak-run.jar checkpoints install-folder/crx-quickstart/repository/segmentstore rm-all
Step 4: Finally, run the compaction and wait for it to complete:
java -jar oak-run.jar compact install-folder/crx-quickstart/repository/segmentstore
Step 5: start the AEM server and perform an environment check and you’re done.
java -jar oak-run-1.0.32.jar checkpoints C:/Users/David/Desktop/AEMCQ/crx-quickstart/repository/segmentstore
java -jar oak-run-1.0.32.jar checkpoints C:/Users/David/Desktop/AEMCQ/crx-quickstart/repository/segmentstore rm-all
java -jar oak-run-1.0.32.jar compact C:/Users/David/Desktop/AEMCQ/crx-quickstart/repository/segmentstore