AEM — how to automatically save your content | part 1

Ilies Ait Hamouda
4 min readAug 25, 2019

Or, the art of taking a backup of only what y ou need and not the whole AEM instance.

Adobe Experience Manager

Hi there,

Recently, i had to replace someone who left the company for another contract and i had to maintain an AEM web site project. Having no real experience in AEM forced me to experience a new technologie and think differently.

At first, it was hard for me to distinguish the back-end (which is the bundle) and the front-end (which is the html and js) because they were in the same repository and they can communicate easily. Slowly, I started to understand that there’s also another project that contains the “content”.

Basically, the content is all the data entered while editing the page or setting the properties of a page. It’s saved as a bunch of nodes inside a repository hierarchy called the JCR (java content repository).

This content is not idempotent, it can be different from dev to prod. That means if someone bring the content of prod into dev, the content in dev will be overwritten. So how can we avoid this kind of situation ? by making a backup of the content project regulary. How do we do that ? let’s dive into the subject:

First, we need to create and set the content project

To be able to do that, we need maven installed globally.
please follow this link.

Once maven installed, you need to create an AEM project with maven archetype 13 with this command:

mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeGroupId=com.adobe.granite.archetypes -DarchetypeArtifactId=aem-project-archetype -DarchetypeVersion=13 -DarchetypeCatalog=https://repo.adobe.com/nexus/content/groups/public/

You will have to enter the details for your project as project’s name, artifactId, groupId, package, version and so on…

Once all required fields set, you will find a repository under the current path and a sub repository called ui.content. That is our content for the new project.

Now you’ll need to set the settings.xml.

for those who’s using maven for the first time, the settings xml is a configuration that maven need to communicate with the remote server to get the bunches of dependencies you need and to also upload new versions.

For AEM content project. Here is an exemple of the settings.xml:

<?xml version=”1.0" encoding=”UTF-8"?>
<! —
#%L
wcm.io
%%
Copyright © 2014 wcm.io
%%
Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#L%
<settings xmlns=”http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=”http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>default</id>
<repositories><repository>
<id>central</id>
<url>http://repo1.maven.org/maven2/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>adobe-public-releases</id>
<name>Adobe Public Repository</name>
<url>https://repo.adobe.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>wcm-io-apache-intermediate-release</id>
<url>http://wcm.io/maven/repositories/apache-intermediate-release</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>oss-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<layout>default</layout>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>apache-snapshots</id>
<url>http://repository.apache.org/snapshots</url>
<layout>default</layout>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories><pluginRepositories><pluginRepository>
<id>central</id>
<url>http://repo1.maven.org/maven2/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>adobe-public-releases</id>
<name>Adobe Public Repository</name>
<url>https://repo.adobe.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>wcm-io-apache-intermediate-release</id>
<url>http://wcm.io/maven/repositories/apache-intermediate-release</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>oss-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<layout>default</layout>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>apache-snapshots</id>
<url>http://repository.apache.org/snapshots</url>
<layout>default</layout>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories></profile></profiles><activeProfiles>
<activeProfile>default</activeProfile>
</activeProfiles>
</settings>

Now that the settings xml is configured correctly, we can focus on the content project.

in the pom.xml of the project, you’ll need to add a plugin in the build section as follow:

<plugin><groupId>io.wcm.maven.plugins</groupId><artifactId>wcmio-content-package-maven-plugin</artifactId><version>1.6.18</version><executions><execution><phase>compile</phase><goals><goal>download</goal></goals><configuration><serviceURL>${serviceAem.serviceURL}</serviceURL><userId>${serviceAem.username}</userId><password>${serviceAem.password}</password><unpack>true</unpack><unpackDirectory>./src/main/content/</unpackDirectory><unpackDeleteDirectories>yes</unpackDeleteDirectories><excludeFiles><exclude>^META-INF/.*</exclude><! — exclude renditions that are automatically generated →<exclude>.*/cq5dam\.thumbnail\..*</exclude></excludeFiles><excludeProperties><exclude>jcr\:created</exclude><exclude>jcr\:createdBy</exclude><exclude>jcr\:lastModified</exclude><exclude>jcr\:lastModifiedBy</exclude><exclude>cq\:lastModified</exclude><exclude>cq\:lastModifiedBy</exclude><exclude>cq\:lastReplicated</exclude></excludeProperties></configuration></execution></executions></plugin>

This part is used to download the content from the AEM server given in the properties with the username and password:

<properties><serviceAem.serviceURL>http://your-aem-instance-domain:4502/crx/packmgr/service</serviceAem.serviceURL><serviceAem.username>your-user</serviceAem.username><serviceAem.password>your-password</serviceAem.password></properties>

Once this set. you can run a test and try to compile and package the content with the following command:

mvn clean install

That’s all Folks for the first part, a second article will follow soon and we’ll need GIT configured and a Jenkins instance working.

Nobody said it will be easy !!! 😄

Please, leave comment if you need assistance or if you enjoyed the post.

Clap if you enjoyed the reading 👏!!!

--

--