[mythtv] Purging video files
Brent Borghese
mythtv-dev@snowman.net
Fri Jan 10 06:11:10 EST 2003
--=-RuWjZyJ5IFGu1v6oUHpW
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
I wrote a Purge shell script for Mythtv.
What it will do is read from the database where is video store is and
delete the oldest video file and remove the database entry for that
file. It will do this till there is at least 15G(The default) free.
The default of 15G can be changed by passing a argument to the script
with the new size, in K.
It can be run from cron, I run it every hour on the half hour.
30 * * * * /usr/local/bin/mythPurge.sh
This will purge at 5G
30 * * * * /usr/local/bin/mythPurge.sh 5000000
I did see some database changes in the CVS a day or so and do not know
if this will still work, I think it should.
To install the script copy it to /usr/local/bin
If some one can put a "Save Until I delete field" in the database, I can
then check for that so programs can be saved.
Brent
--=-RuWjZyJ5IFGu1v6oUHpW
Content-Disposition: attachment; filename=mythPurge.sh
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-sh; name=mythPurge.sh; charset=ISO-8859-1
#!/bin/bash
# This script is licensed under the GNU GENERAL PUBLIC LICENSE=20
# Writen by: Brent Borghese
#
# Change the next line to the purge size in K, so 15G will be 15000000
PurgeAt=3D15000000
if [ $# -gt 0 ]; then
PurgeAt=3D$1
fi
store=3D$(mysql -D mythconverg --batch -s -e "select * from settings ;"|gre=
p RecordFilePrefix|awk '{ print $2 }')
mysql -D mythconverg --batch -s -e "select * from recorded group by startti=
me asc;"|awk '{ print $2 " " $1 "_" $2 "_" $3 ".nuv" }'|head -n 1 >/tmp/my=
thpurge.txt
freespace=3D$(df -k $store |grep -v "Filesystem"|awk '{ print $4 }')
OldestFile=3D$(cat /tmp/mythpurge.txt|awk '{ print $2 }')
OldestName=3D$(mysql -D mythconverg --batch -s -vvv -e "select * from recor=
ded group by starttime asc ;"|awk -F "|" '{ print $5 " - " $6 }'|head -n 8|=
tail -n 1)
channel=3D$(echo $OldestFile|awk -F _ '{ print $1 }')
starttime=3D$(echo $OldestFile|awk -F _ '{ print $2 }')
echo "PurgeAt: " $PurgeAt
#echo "freespace:" $freespace
#echo "channel: " $channel
#echo "starttime: " $starttime
if [ $PurgeAt -gt $freespace ]; then
echo We need to purge a file
echo Deleting the oldest show from DB: $OldestName
mysql -D mythconverg --batch -s -e "delete from recorded where chanid=
=3D$channel and starttime=3D $starttime ;"
echo Deleting the oldest file Video: $OldestFile
rm -f $store/$OldestFile
sleep 1
$0 $PurgeAt
else
echo No need to purge
fi
--=-RuWjZyJ5IFGu1v6oUHpW--
More information about the mythtv-dev
mailing list