Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Though I'd share the plexdrive chunk cleanup I'm using #37

Open
ghost opened this issue May 24, 2017 · 1 comment
Open

Though I'd share the plexdrive chunk cleanup I'm using #37

ghost opened this issue May 24, 2017 · 1 comment

Comments

@ghost
Copy link

ghost commented May 24, 2017

It got min age to always keep, max age to always delete, and will stay within the set free space for the chunks inbetween:

#!/bin/bash

if pidof -o %PPID -x "$0"; then
echo "Already running, exit"
exit 1
fi

PLEXDRIVETEMP=/tmp/plexdrive/GoogleAJ/chunks
MINDISKSPACE=50000000
CURDISKSPACE=$(df -k $PLEXDRIVETEMP | tail -1 | awk '{print $4}')
FORCEMINAGE=120
FORCEMAXAGE=1440

HRDISKSPACE=$(echo "$CURDISKSPACE" | awk '{ sum=$1 ; hum[10242]="Gb";hum[1024]="Mb";hum[0]="Kb"; for (x=10243; x>=1024; x/=1024){ if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x];break } }}')
echo "Starting with $HRDISKSPACE free diskspace"
HRCHUNKSPACE=$(du -s $PLEXDRIVETEMP | awk '{ sum=$1 ; hum[10242]="Gb";hum[1024]="Mb";hum[0]="Kb"; for (x=10243; x>=1024; x/=1024){ if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x];break } }}')
echo "Starting with $HRCHUNKSPACE used chunkspace"

find $PLEXDRIVETEMP -mmin +$FORCEMAXAGE -amin +$FORCEMAXAGE -cmin +$FORCEMAXAGE -type f -delete

while [[ $CURDISKSPACE -le $MINDISKSPACE ]]
do
IFS= read -r -d $'\0' line < <(find $PLEXDRIVETEMP -mmin +$FORCEMINAGE -amin +$FORCEMINAGE -cmin +$FORCEMINAGE -type f -printf '%T@ %p\0' 2>/dev/null | sort -z -n)
CHUNK="${line#* }"
if [[ -z "$CHUNK" ]]; then
break
fi
echo "$CHUNK"
rm $CHUNK
CURDISKSPACE=$(df -k $PLEXDRIVETEMP | tail -1 | awk '{print $4}')
done

find $PLEXDRIVETEMP -mindepth 1 -empty -delete

CURDISKSPACE=$(df -k $PLEXDRIVETEMP | tail -1 | awk '{print $4}')
HRDISKSPACE=$(echo "$CURDISKSPACE" | awk '{ sum=$1 ; hum[10242]="Gb";hum[1024]="Mb";hum[0]="Kb"; for (x=10243; x>=1024; x/=1024){ if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x];break } }}')
echo "Ended with $HRDISKSPACE free diskspace"
HRCHUNKSPACE=$(du -s $PLEXDRIVETEMP | awk '{ sum=$1 ; hum[10242]="Gb";hum[1024]="Mb";hum[0]="Kb"; for (x=10243; x>=1024; x/=1024){ if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x];break } }}')
echo "Ended with $HRCHUNKSPACE used chunkspace"

@sbcrumb
Copy link

sbcrumb commented May 31, 2017

Thanks this works well for me. Can you tell me what these fields are in
MINDISKSPACE=50000000 is this Kb,GB or MB
FORCEMINAGE=120 is this days mins hours?
FORCEMAXAGE=1440 same as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant