April 1, 2020
Estimated Post Reading Time ~

How to transfer file from one CRX to other modified after certain date using CURL in CQ

Use case: You want to copy all files modified after a certain date and time from one instance to another. this is also used for migration projects.

Solution You can use the following Unix script to do that (Example refer /var/dam) change it based on your requirement

Approach: Initially I thought, I will build a list of all the pages and then use vlt rcp. But the problem with this approach is, on the destination, you might not have Path (Subfolder) and in that case, you will get path not found exception using vlt. Instead, you can use a reciprocal approach and find all pages created "before" certain date and then exclude them (Good for smaller size folder, not good for huge data) from all vlt copy from the parent folder (Make sure that that exists in destination).

Prerequisite makes sure that you have VLT configured. Please see http://dev.day.com/docs/en/crx/current/how_to/how_to_use_the_vlttool.html for that

Solution
#!/bin/bash
# Author: upadhyay.yogesh@gmail.com

# The host and port of the source server
SOURCE="localhost:4504"

# The user credentials on the source server (username:password)
SOURCE_CRED="admin:admin"

# The host and port of the target server
TARGET="localhost:4508"

# The user credentials on the target server (username:password)
TARGET_CRED="admin:admin"

#Filter path
FILTER_PATH="/var/dam"

#Root Path
ROOT_PATH="/var/dam"

FILTER_COUNT=0

SPACE=" "
#############################################################################

#Query to get all files uploaded after certain date
#echo "Creating path list"
ALL_PATHS=`curl -s -u $SOURCE_CRED "$SOURCE/bin/querybuilder.json?path=$FILTER_PATH&type=nt:file&&p.limit=-1&daterange.property=jcr:created&daterange.upperBound=2011-11-11&daterange.upperOperation=<&orderby=jcr:created&orderby.sort=desc" | tr ",[" "\n" | grep path | awk -F \" '{print $4 "\n"}'`
echo "$ALL_PATHS"
for SINGLE_PATH in $ALL_PATHS
do
EXCLUDE=${EXCLUDE}${SINGLE_PATH}${SPACE}
done
vlt rcp -e '$EXCLUDE' -r http://$SOURCE_CRED@$SOURCE/crx/-/jcr:root$ROOT_PATH http://$TARGET_CRED@$TARGET/crx/-/jcr:root$ROOT_PATH
echo "vlt rcp -e \"$EXCLUDE\" -r http://$SOURCE_CRED@$SOURCE/crx/-/jcr:root$ROOT_PATH http://$TARGET_CRED@$TARGET/crx/-/jcr:root$ROOT_PATH"


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.