[mythtv-users] myth_archive_job.pl and it's Use. (And Side effects of use)
Tony Lill
ajlill at ajlc.waterloo.on.ca
Thu Sep 28 19:05:53 UTC 2006
Since you're always recording to a NAS box, it seems a bit silly to
copy the files from one nfs mount to another. Instead, make your
recording directory a symlink to point to the emptiest mount point,
and change it when it gets too full.
I've been running the following script to switch my recording dir
between 3 filesystems. It's run from cron 5 minutes after the half
hour. The min free space is enough to hold 2 movies, plus a bit (since
I have 2 encoders). When it changes the symlink to the recording dir,
it fixes/creates/deletes symlinks as necessary.
#!/usr/bin/perl -w
#
# By A. J. Lill, with bits from myth_archive_job.pl
#
# Values are: "DIRECTORY:FREESPACE"
#
# Free Space is in Megabytes
#
my( @ArchiveDirEntries ) = (
"/misc/f1/myth:10240",
"/misc/f2/myth:10240",
"/misc/f3:10240"
);
my( $curmount ) = readlink "/u/myth";
my( $bestdir) ;
my $bestfree = 0;
my( $dirEntry);
foreach $dirEntry ( @ArchiveDirEntries ) {
my( $archiveDir, $keepFree ) = split( ':', $dirEntry );
my( $freeSpace ) = GetFreeSpace( $archiveDir );
if( $#ARGV < 0 && $archiveDir eq $curmount && $freeSpace - $keepFree > 0 ) {
# If we're below the freespace threshold, don't bother. Any
# argument forces a switch
exit(0);
}
if( $freeSpace - $keepFree > $bestfree ) {
$bestdir = $archiveDir;
$bestfree = $freeSpace - $keepFree;
}
}
if( $#ARGV > 0 ) {
$bestdir = $ARGV[1];
}
if( ! $bestdir ) {
exit 0;
}
if( $bestdir ne $curmount ) {
unlink "/u/myth";
symlink( $bestdir, "/u/myth");
chdir $curmount;
foreach $i ( glob "*.{nuv,mpg}*" ) {
$link = readlink $i;
if( defined( $link ) ) {
if( ! -f "$bestdir/$i" ) {
symlink( $link, "$bestdir/$i" );
}
unlink $i;
} else {
symlink( "$curmount/$i", "$bestdir/$i" );
}
}
}
exit(0);
# Don't like doing this, but it was easier than requiring Filesys::Statfs
sub GetFreeSpace {
my( $dir ) = shift;
if ( ! -r $dir ) {
return 0;
} else {
my( $freeSpace ) = `df -m $dir | grep -v Available | awk '{print \$4}'`;
return $freeSpace;
}
}
More information about the mythtv-users
mailing list