Wednesday, December 12, 2012

How to remove non referenced node from DAM in CQ 5.5

Use Case: Clean your DAM to remove non referenced node.

Solution: You can use following script to remove all non referenced node from DAM.

# !/bin/bash
# Author: upadhyay.yogesh@gmail.com
# The host and port of the source server
SOURCE="localhost:4502"
# The user credentials on the source server (username:password)
SOURCE_CRED="admin:admin"
#Filter path
ROOT_PATH="/content/dam/<Your PATH>"
ALL_PATHS=`curl -s -u $SOURCE_CRED "$SOURCE/bin/querybuilder.json?path=$ROOT_PATH&type=dam:Asset&p.limit=-1" | tr ",[" "\n" | sed 's/ /%20/g' | grep path | awk -F \" '{print $4 "\n"}'`
echo "$ALL_PATHS"
for SINGLE_PATH in $ALL_PATHS
do
REFERENCE_COUNT=`curl -s -u $SOURCE_CRED "$SOURCE/bin/wcm/references.json?path=$SINGLE_PATH" | tr ",[" "\n" | sed 's/ /%20/g' | grep path | awk -F \" '{print $4 "\n"}'`
if [ "$REFERENCE_COUNT" == "" ] ; then
  echo "Removing $SINGLE_PATH"
  #curl -u $SOURCE_CRED -F:operation=delete $SOURCE$SINGLE_PATH
fi
done

Post Cleaning Step:

1) Run Data store garbage collection see http://www.wemblog.com/2012/03/how-to-run-online-backup-using-curl-in.html or http://helpx.adobe.com/crx/kb/DataStoreGarbageCollection.html for that)
2) Remove these nodes from publish as well if they are not deactivated already (usually deleting activated node should delete it from publish as well, But please check)

Caution: As always please test this. Also this might not cover Image referenced through CSS or your code. This only covers Image referenced through Image or Image related component.

Note: You can also use JSAWK https://github.com/micha/jsawk for better parsing of response.


7 comments:

  1. I'm blinded by the pure awesomeness of this script! :)) Thanks a lot!

    ReplyDelete
  2. This site is truly amazing my one of friend told me about this. And the theme is quite beautiful as well as the updated stuff also attract visitors to come and visit again. I would definitely bookmark it and would come back to you soon. Keep on updating.

    ReplyDelete
  3. Any example of how this can be done from a java class

    ReplyDelete
  4. Hi,
    This script will work for CQ5.6 as well ?
    And If I want to recreate this script to remove only videos from DAM, what change I could make ?
    Regards

    ReplyDelete
  5. Is it possible to get batch file equivalent for this script as my CQ is running on windows.

    ReplyDelete