[mythtv-users] Question on how to purge old recordings
Kirk Fitzpatrick
kfitzpatrick at cbltech.com.au
Thu Feb 19 04:20:13 UTC 2009
*malcolm* wrote:
> That is a long winded way of asking:
> "Does anyone know a method of purging a recordings directory for files /
> recordings that are no longer referenced in the database.?"
I use this script for 0.21. Basically it takes a list of the mpg's in
the recording directory and checks if there's an entry in the DB for it.
If not, it deletes 'em (the files). Adapt as necessary for your
situation.
--
#!/bin/bash
# remove files in the tv storage directory that are not in the database
RECORDINGDIR="/myth/tv"
MYSQLUSER="mythtv"
MYSQLPASS="mythtv"
SQLSCRIPT="/tmp/remove_recordings_without_db_entry.sql"
# Create empty file or remove one that already exists
cp /dev/null $SQLSCRIPT
# Search for files ending in ".mpg"
for filename in `ls -1 $RECORDINGDIR | grep -i "mpg$"`
do
echo "SELECT count(basename) FROM recorded WHERE basename =
'$filename';" > $SQLSCRIPT
ROWS=$(mysql -u $MYSQLUSER -p$MYSQLPASS --batch mythconverg <
$SQLSCRIPT |tail -1)
if [ $ROWS -eq 0 ]
then
rm -f $RECORDINGDIR/$filename
echo "Removing $RECORDINGDIR/$filename"
fi
done
# Clean up the tmp file
rm -f $SQLSCRIPT
--
- Kirk.
P.S. Not sure where I got this idea/script from - my regards to the
original author.
More information about the mythtv-users
mailing list