<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, May 3, 2020, 2:10 AM Stephen Worthington, <<a href="mailto:stephen_agent@jsw.gen.nz">stephen_agent@jsw.gen.nz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sat, 2 May 2020 23:32:41 -0400, you wrote:<br>
<br>
>On Sat, May 2, 2020, 11:23 PM Stephen Worthington, <<a href="mailto:stephen_agent@jsw.gen.nz" target="_blank" rel="noreferrer">stephen_agent@jsw.gen.nz</a>><br>
>wrote:<br>
><br>
>> On Sat, 2 May 2020 14:38:50 -0400, you wrote:<br>
>><br>
>> >A little MythTV math problem.<br>
>> ><br>
>> >I have a 9 year old 3 TB recording drive with an xfs file system that's<br>
>> >never been defragmented and currently has a fragmentation factor of<br>
>> 95.88%.<br>
>> ><br>
>> >If I run xfs_fsr on it for two hours everyday at 5am, how long would you<br>
>> >expect it to take to get to a better place? Days, weeks, months?<br>
>><br>
>> For MythTV recording drives, fragmentation is not usually a problem.<br>
>> MythTV expires recordings when the free space gets too low (somewhere<br>
>> below 20 Gibytes), so there is always enough free space for the next<br>
>> recording.  That usually means that the fragmentation does not get<br>
>> bad.  I use JFS myself, which is also somewhat resistant to<br>
>> fragmentation problems.  I do not know enough about XFS to say how<br>
>> well it handles fragmentation.<br>
>><br>
>> You did not mention how full your recording drive is.  If it has lots<br>
>> of free space, then fragmentation is not going to be an issue.  But if<br>
>> you are running it as full as MythTV allows, then depending on how<br>
>> good XFS is, it could be getting to be a problem, gradually.  But 9<br>
>> years is a long time - if you have been running it that full for<br>
>> years, and have not noticed any performance issues, then it is<br>
>> unlikely to be getting worse and will likely have stabilised at the<br>
>> current fragmentation level.<br>
>><br>
>> Also, 9 years is a pretty old drive.  I have older, but I am<br>
>> progressively replacing my older drives - I really do not want one to<br>
>> fail and lose all the data.  A new drive would be much faster and<br>
>> could be a lot bigger.<br>
>><br>
><br>
>The drive has about 200 gigabytes free out of 3 terabytes.<br>
<br>
200 gigs is a decent amount of free space.  It should be possible to<br>
defrag reasonably quickly with that much free space available.  And<br>
there should not be much fragmentation anyway.<br>
<br>
>I was actually basing the idea of defragmenting off of the wiki (<br>
><a href="https://www.mythtv.org/wiki/Optimizing_Performance#XFS-Specific_Tips" rel="noreferrer noreferrer" target="_blank">https://www.mythtv.org/wiki/Optimizing_Performance#XFS-Specific_Tips</a>) where<br>
>one suggestion was to run xfs_fsr for 8 hours overnight via cron. So I'm<br>
>that's an outdated recommendation?<br>
<br>
Not having ever used XFS, I am not the best person to give advice<br>
about it.  Looking at that page, it seems that you can tell xfs_fsr<br>
how long to run for when it is defragging.  So if you want to run it,<br>
I would recommend only doing it when MythTV is not busy.  You can use<br>
my gaps program:<br>
<br>
<a href="http://www.jsw.gen.nz/mythtv/gaps" rel="noreferrer noreferrer" target="_blank">http://www.jsw.gen.nz/mythtv/gaps</a><br>
<br>
to tell you when you have a gap in your recordings and then run<br>
xfs_fsr for a bit less than the length of that gap.  You would also<br>
want to make sure no-one was going to be playing any recordings while<br>
xfs_fsr was running.  But I would think, based on your existing<br>
fragmentation, that you would only want to run it very occasionally,<br>
rather than as a regular cron job.  Defragging puts a lot of use on<br>
your drive as it can result in a large proportion of the entire<br>
contents of the drive being moved around on it.  So it is best to only<br>
do it when it is really needed, otherwise you risk wearing out the<br>
drive.  A better option than a regular defrag cron job is a cron job<br>
that will report when the fragmentation level goes too high and let<br>
you decide how to deal with that.  I have systemd and cron jobs that<br>
do that sort of reporting via email.  For example, I have a systemd<br>
job that runs every hour to check if the system drive is getting too<br>
full.  Setting it up is not too difficult, but it does require a way<br>
of sending email to be installed.<br>
<br>
When I want to run something in an upcoming gap, I use a "sleepuntil"<br>
script I found on the net:<br>
<br>
root@mypvr:/usr/local/bin# cat sleepuntil<br>
#!/bin/bash<br>
set -o nounset<br>
<br>
### // Sleep until some date/time.<br>
# // Example: sleepuntil 15:57; kdialog --msgbox "Backup needs to be<br>
done."<br>
<br>
<br>
error() {<br>
  echo "$@" >&2<br>
  exit 1;<br>
}<br>
<br>
NAME_PROGRAM=$(basename "$0")<br>
<br>
if [[ $# != 1 ]]; then<br>
     error "ERROR: program \"$NAME_PROGRAM\" needs 1 parameter and it<br>
has received: $#."<br>
fi<br>
<br>
<br>
CURRENT=$(date +%s)<br>
TARGET=$(date -d "$1" +%s)<br>
<br>
SECONDS=$(($TARGET - $CURRENT))<br>
<br>
if [[ $SECONDS < 0 ]]; then<br>
     error "You need to specify in a different way the moment in which<br>
this program has to finish, probably indicating the day and the hour<br>
like in this example: $NAME_PROGRAM \"2009/12/30 10:57\"."<br>
fi<br>
<br>
echo "SECONDS=$SECONDS"<br>
sleep "$SECONDS"<br>
<br>
# // End of file<br>
<br>
So if I want to run a job that will take two hours, first I would run<br>
gaps asking it for gaps of minimum length 2 hours:<br>
<br>
root@mypvr:~# gaps 2 | head -n 2<br>
Searching for a minimum duration of 2:00:00<br>
Gap:  start=Mon 2020-05-04 01:48:00+12:00  end=2020-05-04<br>
07:10:00+12:00  duration=5:22:00<br>
<br>
and then I would run the job using sleepuntil:<br>
<br>
sleepuntil "2020-05-03 01:49"; myjob<br>
<br>
I have put sleepuntil on my web server also:<br>
<br>
<a href="http://www.jsw.gen.nz/mythtv/sleepuntil" rel="noreferrer noreferrer" target="_blank">http://www.jsw.gen.nz/mythtv/sleepuntil</a><br>
<br>
To download and install gaps and sleepuntil on Ubuntu or Debian:<br>
<br>
sudo su<br>
cd /usr/local/bin<br>
wget <a href="http://www.jsw.gen.nz/mythtv/gaps" rel="noreferrer noreferrer" target="_blank">http://www.jsw.gen.nz/mythtv/gaps</a><br>
chown root:root gaps<br>
chmod u=rwx,g=rx,o=rx gaps<br>
wget <a href="http://www.jsw.gen.nz/mythtv/sleepuntil" rel="noreferrer noreferrer" target="_blank">http://www.jsw.gen.nz/mythtv/sleepuntil</a><br>
chown root:root sleepunti<br>
chmod w=rwx,g=rx,o=rx sleepuntil<br>
exit<br>
<br>
Gaps requires that you have the MythTV Python bindings installed, and<br>
also a couple of other Python libraries.  Run it manually and it will<br>
tell you if you need to install anything.  Gaps is only available in<br>
Python 2 so does not work with MythTV v31 yet - as soon as I have<br>
upgraded a system to v31 I will be doing a Python 3 version.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Stephen, </div><div dir="auto"><br></div><div dir="auto">Thanks for the suggestions. I'll have to really look at it. </div><div dir="auto"><br></div><div dir="auto">Just a quick note:</div><div dir="auto"><br></div><div dir="auto">When I tried to wget the files from your server I got a 404.</div><div dir="auto"><br></div><div dir="auto">I then clicked on the links in the browser and pasted them into files with nano. After the chown and chmod, I tried running your example gaps command and got this:</div><div dir="auto"><br></div><div dir="auto"><div dir="auto">ian@buster:~$ gaps 2 | head -n 2             File "/usr/local/bin/gaps", line 9</div><div dir="auto">    from __future__ import</div><div dir="auto">                                            ^</div><div dir="auto">SyntaxError: invalid syntax</div><div dir="auto">ian@buster:~$</div></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
</blockquote></div></div></div>