Versions cleaner
Jahia module to clean versions by:
- keeping the last N versions
- removing the orphaned versions
Comment installer
- In Jahia, go to "Administration --> Server settings --> System components --> Modules"
- Upload the JAR versions-cleaner-X.X.X.jar
- Check that the module is started
FAQ
Configuration (scheduled job)
The scheduled job is configured via an OSGi configuration file.
Create or edit digital-factory-config/jahia/org.jahia.community.versionscleaner.cfg:
| Property | Default value | Description |
|---|---|---|
disabled |
true |
Disable the scheduled purge |
cronExpression |
0 30 1 * * ? |
Quartz cron expression for the job |
reindexDefaultWorkspace |
false |
Reindex default workspace before cleaning |
checkIntegrity |
false |
Check and fix integrity of references |
nbVersionsToKeep |
2 |
Number of versions to keep |
maxExecutionTimeInMs |
60000 |
Max execution time in ms (0 = Infinite) |
deleteOrphanedVersions |
false |
Delete orphaned versions |
Example .cfg to enable the scheduled job:
disabled=false cronExpression=0 30 1 * * ? nbVersionsToKeep=5 deleteOrphanedVersions=true maxExecutionTimeInMs=600000
Note: Config changes require a module restart to reschedule the job.
GraphQL API
All operations require admin permission.
Query
| Name | Returns | Description |
|---|---|---|
versionsCleanerIsRunning |
Boolean |
True if a clean is currently running |
Mutation
| Name | Returns | Description |
|---|---|---|
versionsCleanerRun(...) |
Boolean |
Starts a clean asynchronously; returns false if already running |
Mutation parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
nbVersionsToKeep |
Long |
-1 |
Versions to keep per non-orphan history. Negative = skip non-orphans. |
deleteOrphanedVersions |
Boolean |
false |
Delete orphaned version histories |
checkIntegrity |
Boolean |
false |
Check and fix reference integrity |
reindexDefaultWorkspace |
Boolean |
false |
Reindex default workspace first |
maxExecutionTimeInMs |
Long |
0 |
Max execution time in ms (0 = unlimited) |
pauseDuration |
Long |
0 |
Pause in ms between deletions |
subtreePath |
String |
null |
Restrict scan to a subtree of the version storage |
forceRestartFromBeginning |
Boolean |
false |
Ignore saved position; restart from the beginning |
Example:
mutation {
versionsCleanerRun(
nbVersionsToKeep: 2
deleteOrphanedVersions: true
maxExecutionTimeInMs: 600000
)
}
Admin UI
The admin UI is accessible at /jahia/administration/versionsCleaner (under Server / System Components).
It provides a form to configure and launch a one-off clean operation immediately from the browser. The UI polls the server while the operation is running and shows a progress indicator.
Commands
versions-cleaner:run
Run a scan of the versions tree and perform the configured actions.
Options:
| Name | Alias | Default | Description |
|---|---|---|---|
-r |
--reindex-default-workspace |
false |
Reindex the default workspace before cleaning |
-c |
--check-integrity |
false |
Check the integrity of the versions |
-n |
--nb-versions-to-keep |
-1 |
Number of versions to keep on non-orphaned histories |
-t |
--max-execution-time-in-ms |
0 |
Max execution time in ms (0 = Infinite) |
-o |
--delete-orphaned-versions |
false |
Delete orphaned versions |
-p |
--subtree-path |
Subtree of the versions tree to scan | |
-pause |
0 |
Pause duration in ms between deletions | |
-skip |
--skip-subtree |
Paths to skip (can be specified multiple times) | |
-threshold-long-history-purge-strategy |
1000 |
Version count threshold for one-by-one deletion | |
-force-restart-from-the-beginning |
false |
Restart from the beginning, ignoring the saved position |
Examples:
# Reduce non-orphan histories, keeping max 2 versions: versions-cleaner:run -n 2 # Delete all orphan histories: versions-cleaner:run -o # Combined cleanup with 10-minute time limit: versions-cleaner:run -n 2 -o -t 600000
How to interrupt an execution?
Use the predefined script for the Extended Groovy Console at META-INF/extendedGroovyConsole/stopVersionPurgeProcess.groovy.
Or run in any Groovy console (on the same JVM as the running purge):
System.setProperty("versions-cleaner.interrupt", "true")
MIT License
Copyright (c) 2022 - present Florent BOURASSÉ
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.