MusicBot
MusicBot copied to clipboard
[Suggestion] Implement audio cache auto cleanup feature
Currently I'm hosting MisicBot at VPS with tiny 5GB drive. It was completely filled out with audio_cache in one month and bot became unusable (impossible to add new music requests).
Suggestion: implement auto cleanup feature for the auto_cleanup folder. Of course it can be done by external script but embedded feature looks better here. We need to add some cache_max_size parameter and implement Bot behavior when limit is overused. For example delete some fixed percent or number of most unused/most old files.
https://github.com/SexualRhinoceros/MusicBot/blob/master/config/example_options.ini#L72
https://github.com/SexualRhinoceros/MusicBot/blob/master/config/example_options.ini#L72
This is not what I mean actually. This option completely disables caching. The good solution is to cache often used files and delete unused if they overcome the storage size limit.
Is there any update on when this might be implemented? I would like to be able to leave alone, self regulating.
Well... I did my solution with bash script. Just set proper value of TARGET_DIR and desirable MAX_DIR_SIZE in bytes. Script should be launched via cron daemon like
# m h dom mon dow command
0 5 * * * /opt/cleanup/clean_audio_cache.sh 2>&1 >/dev/null
#!/bin/bash
TARGET_DIR='/opt/MusicBot/audio_cache'
MAX_DIR_SIZE=1500000
if [ ! -d $TARGET_DIR ]; then echo "$TARGET_DIR does not exists"; exit; fi
cd $TARGET_DIR
DIR_SIZE=`du -s . | cut -f 1`
if [ "$DIR_SIZE" -gt "$MAX_DIR_SIZE" ]
then
echo "$DIR_SIZE > $MAX_DIR_SIZE"
echo "Delete extra files"
ls -ltu | tail -n 100 | tr -s ' ' | cut -d ' ' -f 9 | xargs rm
echo "Done!"
else
echo "$DIR_SIZE < $MAX_DIR_SIZE"
echo "Nothing to delete"
fi
I was able to add it to my crontab it have it run every Thursday! Thank you!