This commit is contained in:
Oleg Sheynin 2024-07-19 10:37:45 -04:00
parent 0b9feb8610
commit 7251b29f73
2 changed files with 49 additions and 1 deletions

View File

@ -1 +1 @@
0.9.4
0.9.5

48
utils/prune_data.sh Executable file
View File

@ -0,0 +1,48 @@
#!/bin/bash
Src=${1}
Days=${2}
if [ "${Src}" == "" ]
then
echo "Usage: $0 <source_dir> [<num_days>]"
exit 1
fi
if [ "${Days}" == "" ]
then
Days=30
fi
declare -A Settings=()
Settings[Src]=${Src}
Settings[PruneDate]=$(date -d "${Days} days ago" '+%Y-%m-%d')
src=${Settings[Src]}
prune_date=${Settings[PruneDate]}
echo Before Pruning....
duf ${src}
echo "Finding files older than ${prune_date}..."
Cmd="find ${src} -type f ! -newermt \"${prune_date}\""
echo ${Cmd}
files=($(eval ${Cmd}))
echo "The following files will be removed:"
echo "===================================="
for f in $files ; do echo $f; done
echo "===================================="
echo "Total files to be pruned: ${#files[*]}"
Cmd="${Cmd} -delete"
echo ${Cmd}
eval ${Cmd}
echo "Removing empty directories..."
Cmd="find ${src} -type d -empty -print -delete"
echo ${Cmd}
eval ${Cmd}
echo After Pruning....
duf ${src}
echo $0 Done