Skip to content

Commit

Permalink
Merge pull request #4 from brown-bnc/feat-clean-by-usage
Browse files Browse the repository at this point in the history
scale days to clean by usage percentage
  • Loading branch information
fordmcdonald authored May 17, 2024
2 parents 94cc57c + 5a7b62b commit 5e23fad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
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
9 changes: 9 additions & 0 deletions cleanup_cache.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5e23fad

Please sign in to comment.