diff --git a/Dockerfile b/Dockerfile index c38d57e..3b14a08 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,14 @@ - ARG UBUNTU_VERSION=22.04 FROM ubuntu:$UBUNTU_VERSION ENV PARENT_PATH=/data/xnat -ENV DAYS_TO_CLEAN=60 +ENV DAYS_TO_CLEAN=100 + +COPY cleanup_cache.sh /cleanup_cache.sh +RUN chmod +x /cleanup_cache.sh -# Clean logs files older than $DAYS_TO_CLEAN days -CMD /usr/bin/find $PARENT_PATH/home/logs -type f -name '*.log.*' -mtime +$DAYS_TO_CLEAN -delete\ - && /usr/bin/find $PARENT_PATH/cache -type f -mtime +$DAYS_TO_CLEAN -delete\ - && /usr/bin/find $PARENT_PATH/build -type f -mtime +$DAYS_TO_CLEAN -delete \ No newline at end of file +CMD /usr/bin/find $PARENT_PATH/home/logs -mindepth 1 -type f -name '*.log.*' -mtime +$DAYS_TO_CLEAN -delete && \ + /usr/bin/find $PARENT_PATH/prearchive -mindepth 1 -type f -mtime +$DAYS_TO_CLEAN -delete && \ + /usr/bin/find $PARENT_PATH/archive -mindepth 1 -type f -mtime +$DAYS_TO_CLEAN -delete && \ + /usr/bin/find $PARENT_PATH/build -mindepth 1 -type f -mtime +$DAYS_TO_CLEAN -delete && \ + /usr/bin/find $PARENT_PATH/inbox -mindepth 1 -type f -mtime +$DAYS_TO_CLEAN -delete && \ + /cleanup_cache.sh diff --git a/cleanup_cache.sh b/cleanup_cache.sh new file mode 100644 index 0000000..755948e --- /dev/null +++ b/cleanup_cache.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +usage=$(df --output=pcent $PARENT_PATH/cache/ | awk 'NR==2 {gsub("%",""); print $1}') # Get the usage of the cache folder + +if [ $usage -gt 75 ]; then + DAYS_TO_CLEAN=$((DAYS_TO_CLEAN / usage)) +fi + +/usr/bin/find $PARENT_PATH/cache -mindepth 1 -type f -mtime +$DAYS_TO_CLEAN -delete