You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AEM中如何指定保留特定非最新页面版本达指定时长?

AEM Specific Version Retention: Answers & Practical Solutions

Great questions! Let’s break down how to handle targeted version retention in AEM since the default settings don’t cover these exact use cases.


1. Can you set a custom retention period for a specific page version in AEM?

Yes, but you won’t find this functionality out of the box with the default Version Manager. The global Max Version Age and Max Number Versions settings apply to all versions of a page uniformly. To retain a specific version for a set duration, you’ll need to implement custom logic. Here are two reliable approaches:

Approach 1: Custom Metadata + Scheduled Cleanup Job

  • Add retention metadata to your target version
    When you identify the version you want to keep (e.g., a v2.0 release you need for a year), add a custom property to its metadata. For example, create a custom:retentionEndDate property on the version’s jcr:content/metadata node, set to the date when it’s okay to delete the version.

    You can do this programmatically with the AEM API:

    // Get the version you want to retain
    Version targetVersion = versionManager.getVersion("my-page-version-2.0");
    // Access its metadata node
    Node versionMetadata = targetVersion.getFrozenNode().getNode("jcr:content/metadata");
    // Set the retention end date (e.g., current date + 365 days)
    Calendar retentionEnd = Calendar.getInstance();
    retentionEnd.add(Calendar.DAY_OF_YEAR, 365);
    versionMetadata.setProperty("custom:retentionEndDate", retentionEnd);
    // Save the change
    versionMetadata.getSession().save();
    
  • Build a scheduled cleanup service
    Create an OSGi scheduled job (runs daily, for example) that scans page versions. For each version:

    1. Check if it has the custom:retentionEndDate property
    2. If the current date is past the retention end date, use VersionManager.removeVersion() to delete it
    3. Leave versions without this property to follow the global retention rules

Approach 2: Version Tags + Filtered Cleanup

  • Tag the version you want to retain
    Use AEM’s built-in version tagging feature to mark the specific version (e.g., add a tag like retention:keep-for-365d). You can do this directly in the AEM UI when viewing a page’s version history, or programmatically via the API.

  • Adjust cleanup logic to respect tags
    Extend or replace the default version cleanup job to skip versions with your retention tag until the desired period is up. For example, track when the tag was applied, and only remove the version once 365 days have passed since tagging.


2. Can you retain a specific non-latest version for X days, and are there alternative rules beyond latest versions?

AEM’s out-of-the-box cleanup only cares about keeping the most recent N versions or versions within a set age window—it doesn’t have built-in rules to retain non-latest versions. But with the custom methods above, you absolutely can:

  • You can target any version (whether it’s the latest or not) by adding metadata or tags, then build logic to keep it for your specified duration.
  • For more complex needs, you could even build a custom policy engine that supports multiple rules (e.g., "keep all versions tagged legal-archive forever, keep version 1.5 for 180 days, etc.").

Important Implementation Tips

  • Performance first: Don’t scan every page version in one go. Use batch processing or target specific paths to avoid overwhelming your AEM instance.
  • Permissions: Make sure your OSGi service has the jcr:versionManager permission to read and modify version histories.
  • Test rigorously: Validate your logic in a staging environment first—accidentally deleting critical versions can cause major headaches.

内容的提问来源于stack exchange,提问作者Sara

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 08:02:40