Squeezing A Automanaged Drive

So I run MythTV, and when I rebuild/transferred all my recordings to my new server I gave it an extra 0.3TB space, giving it a total of 1.3TB. Well a few months on I’m regretting my decision.

So looking into deleting recordings, and then freeing the space seemed like a massive job, so instead I’ve written some code to consume hard drive space at a 1GB per 6 hours (4GB per day) to force the inbuilt recording management to delete the old recording faster for me.

Yeah okay it’ll take 3 months to make the space, but it only took me an hour to write this, compared to fighting for weeks with new recordings taking space that I’ve freed.

Hopefully it can help you too somewhere, if you’ve found and will use it shout out, be interesting to hear how it helped.

#!/bin/sh

# This script is running daily to squeeze the myth storage group
# smaller so I can get it to fit on a 1TB HDD again.
# I really don't feel like myth really needs that much storage for recordings

INCREASINGFILE=/mnt/storage/increasingfile
CURRENTSIZE=$(ls -lt /mnt/storage/increasingfile | awk '{print $5}')
MAXSIZE=422592708000
MAXSIZEGB=$(($MAXSIZE / 1073741824))
INCREMENT=1073741824
INCREMENTGB=$(($INCREMENT / 1073741824))

CURRENTSIZEGB=$(($CURRENTSIZE / 1073741824))

echo $INCREASINGFILE is at $CURRENTSIZEGB GB of $MAXSIZEGB GB

if [ "$CURRENTSIZE" -le "$MAXSIZE" ]
then
INCREASE=$(($CURRENTSIZE + $INCREMENT))
INCREASEGB=$(($INCREASE / 1073741824))
echo Increasing a further $INCREMENTGB GB totalling $INCREASEGB GB
fallocate /mnt/storage/increasingfile -l $INCREASE
else
echo "Script has hit $MAXSIZE ($MAXSIZEGB GB) maximium, stopping."
fi

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.