MusicBot icon indicating copy to clipboard operation
MusicBot copied to clipboard

[Suggestion] Implement audio cache auto cleanup feature

Open strongestFairy opened this issue 8 years ago • 5 comments

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.

strongestFairy avatar Jun 29 '16 06:06 strongestFairy

https://github.com/SexualRhinoceros/MusicBot/blob/master/config/example_options.ini#L72

arunesh90 avatar Jun 29 '16 10:06 arunesh90

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.

strongestFairy avatar Jun 29 '16 13:06 strongestFairy

Is there any update on when this might be implemented? I would like to be able to leave alone, self regulating.

zach78954 avatar Sep 08 '16 22:09 zach78954

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

strongestFairy avatar Sep 09 '16 15:09 strongestFairy

I was able to add it to my crontab it have it run every Thursday! Thank you!

zach78954 avatar Sep 11 '16 21:09 zach78954