[mythtvnz] Balancing free space after adding a recording drive

Stephen Worthington stephen_agent at jsw.gen.nz
Sun Jul 29 09:00:48 BST 2012


I recently was starting to run out of space for recordings, so I added
another 3 Tbyte WD Green drive to my MythTV box and set it up as a
recording storage group.  As usual after adding a new drive, most of
the free space for recordings was on that drive and relatively little
was left on the other three.  For MythTV to work best, it needs the
free space to be spread around all the drives, so that it can record
to as many of them as it needs to when recording many programs at the
same time.  MythTV is pretty good at keeping the free space balanced
during normal operation, if you use the normal settings.  It is only
on adding a drive that this problem occurs.

What I have done in the past is to do a directory listing of the old
storage groups and edit that into a bash file of mv commands to move
files to the new drive.  The problem with this is that you really need
to only be moving files when there is no recording going on, as the
heavy disk usage of copying can disrupt recordings.  So you have to
guess how many files you can move before the next recording starts (or
you want to watch something), and then put an exit statement in your
bash file at the right point.  This is very difficult to judge, and if
you get it wrong, using Ctrl-C to stop the script means you have to
clean up carefully later as you may have a partially moved recording
file that needs to be recopied, or the *.png files matching a
recording still need to be moved.  So you normally need to get the
bash file to log what is has done and not done.  And when adding a big
drive, you have to do this many times over a number of days to get
everything you need moved to the new drive - it takes quite a long
time to move Tbytes of data, even with fast modern drives.

So this time, since I was feeling like writing some code, I decided to
write a script to at least semi-automate the process, and I have now
got that working pretty well and my drives are all nicely balanced.

It turned out to be not a bad bit of script, so now that it is all
working, I thought that someone else might be in the same situation
and could also use it.  It is a bit big for posting here, so I have
cleaned it up a bit, and put it on my web server:

  http://www.jsw.gen.nz/mythtv/balance_storage.sh

I am very much still learning bash, so if anyone does have a look at
it, I would appreciate any comments about bugs, or better ways to do
things.



More information about the mythtvnz mailing list