Created
January 26, 2024 08:45
-
-
Save aitseitz/02e9cf62ab0060440b456ba9566d25ee to your computer and use it in GitHub Desktop.
Cleanup Alfresco's Lost&Found Folder in the Repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "$(date +"%Y-%m-%d %H:%M:%S,%3N") - This Script automatically cleanups the nodes underneath Lost & Found folder" | |
# Variables: | |
ALFRESCO_HOST_URL='https://localhost:8443' | |
AUTH_PASS="YWRtaW46YWRtaW4=" | |
LOST_N_FOUND_FOLDER_NODE_ID="2f849cd8-9737-477d-9584-1af99a3b4b0e" | |
# Optional Variables | |
MAX_ITEMS=1000 | |
WAIT_TIME=.2 # option to set a wait in seconds time to prevent to many delete api calls in production | |
DELETE_PERMANENT=true | |
DIRECTORY=$(pwd) | |
LOG_DATE=$(date '+%Y-%m-%d_%H-%M') | |
LOG_NAME=$(basename $0) | |
LOGFILE="${DIRECTORY}/${LOG_DATE}_${LOG_NAME}.log" | |
OUTPUT_FILE="${DIRECTORY}/${LOG_DATE}_${LOG_NAME}.json" | |
if ! [ -d "${LOGFILE}" ];then | |
touch "${LOGFILE}" | |
echo "$(date +"%Y-%m-%d %H:%M:%S,%3N") - Logfile created: $LOGFILE" | |
fi | |
function saveChildrenNodeIDsToOutputfile(){ | |
curl -X GET "${ALFRESCO_HOST_URL}/alfresco/api/-default-/public/alfresco/versions/1/nodes/${LOST_N_FOUND_FOLDER_NODE_ID}/children?skipCount=0&maxItems=${MAX_ITEMS}" \ | |
-H "accept: application/json" \ | |
-H "authorization: Basic ${AUTH_PASS}" \ | |
--output ${OUTPUT_FILE} | |
#--compressed | |
# Filter Children Node UUIDs from result: | |
CHILDREN_NODE_IDS=$(jq -r '.list.entries[].entry.id' "${OUTPUT_FILE}") | |
} | |
function deleteNodeID(){ | |
DELETE_NODE_ID=$1 | |
echo "$(date +"%Y-%m-%d %H:%M:%S,%3N") - API-Call to delete nodeid: ${DELETE_NODE_ID}" | tee -a "${LOGFILE}" | |
# API Call to DELETE a nodeid | |
curl -X DELETE "${ALFRESCO_HOST_URL}/alfresco/api/-default-/public/alfresco/versions/1/nodes/${DELETE_NODE_ID}?permanent=${DELETE_PERMANENT}" \ | |
-H "accept: application/json" \ | |
-H "authorization: Basic ${AUTH_PASS}" | |
} | |
saveChildrenNodeIDsToOutputfile | |
if [[ -z ${CHILDREN_NODE_IDS} ]] | |
then | |
echo "$(date +"%Y-%m-%d %H:%M:%S,%3N") - No Childen Node IDs found en Lost & Found Folder found" | tee -a "${LOGFILE}" | |
echo " " | tee -a "${LOGFILE}" | |
exit 0 | |
else | |
echo "$(date +"%Y-%m-%d %H:%M:%S,%3N") - Amount of Lost & Found Children to process" | tee -a "${LOGFILE}" | |
echo "${CHILDREN_NODE_IDS}" | wc -l | tee -a "${LOGFILE}" | |
echo "" | tee -a "${LOGFILE}" | |
echo "$(date +"%Y-%m-%d %H:%M:%S,%3N") - Start Deletion of these children nodeids:" | tee -a "${LOGFILE}" | |
echo "" | tee -a "${LOGFILE}" | |
# Loop each line from CHILDREN_NODE_IDS | |
while IFS= read -r NODE_ID; do | |
deleteNodeID ${NODE_ID} | |
sleep ${WAIT_TIME} | |
done <<< "${CHILDREN_NODE_IDS}" | |
fi | |
echo "" | |
exit 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cleanup Alfresco's in lost&found folder from orphan child nodes
Script Information
This cleanup_alfresco_lost_and_found.sh script was created to delete nodes underneath the lost&found folder
Script Options
Before running the script, adjust the admin credentials & specify the UUID of the lost&found folder with
The script iterates to all children underneath the lost& found folder and deletes them.
With the options
you can decide how many childnodes should be deleted and in case of a production system if you want to add a delay with WAIT_TIME.
Historical Background of the Script
Due to an hardware failure (mount points to contentstore have not been available for some time)
we got the folloing errors in the log:
Error-Message could be reproduced with a Testtransform from xlsx to pdf which produces an TestTransform.xls in the company home.

This Testtransform was called from an external monitoring system to check wether transformers are working correctly.
Due to the hardware failure, the deletion of that Testtransform.xlsx was still available underneath company home. Calling the Transformation a second time we've been able to reproduce the error message
Quick solution was to delete the TestTransform.xls manually underneath company home folder.
Because it took some time to figure out what happend and therefore we endet up having lot nodes underneath the "lost&found" folder.
This Script helped us to clean up the orphan childnodes underneath the lost&found folder.
Additional Usefull Sql Queries: