[mythtv] How do you delete the database except for recorded videos

Chris mythtv-dev@snowman.net
Wed Jan 1 23:09:32 EST 2003


Will this allow me to rebuild the recorded video  database from the
video files stored on the hard disk if I decide to just delete the whole
database and start over?  

On Wed, 2003-01-01 at 17:49, Brent Borghese wrote:
> > I have multiple entries of the same show listed in Fix Recording
> > conflicts( a show conflicting with itself).  Is there a way to delete
> > this section of the database?  I want to keep the listing of the current
> > videos recorded in the hard drive of course.  Thanks
> 
> Here is a shell script that will check the database and your video store 
> to make sure they are in sync.
> 
> It has only been tested on the current CVS!   
> 
> What the script does so far:
> - Makes sure all DB entries have a video file on disk
> - Makes sure all video files have DB entries
> - If there are missing DB entries or missing files, it will display the 
>   mysql command that will fix it.
> 
> You will need to run it as root or what ever user has access to the myth 
> database.
> 
> For now it does not check for duplicate DB entries.
> 
> Brent 
> 
> ----
> 

> #!/bin/bash
> store=$(mysql -D mythconverg --batch -s -e "select * from settings ;"|grep RecordFilePrefix|awk '{ print $2 }')
> mysql -D mythconverg --batch -s -e "select * from recorded ;"|awk '{ print $1 "_" $2 "_" $3 ".nuv" }'|sort>/tmp/flist.txt
> cd $store
> find . -name "*.nuv"|awk -F/ '{print $2}'|sort|grep -v ringbuf >/tmp/flist2.txt
> diff /tmp/flist.txt /tmp/flist2.txt|egrep "[<>]">/tmp/flist3.txt
> cat /tmp/flist3.txt|sed -e 's/</No File found for DB entery:/'|sed -e 's/>/No DB entery for file:/'>/tmp/flist4.txt
> 
> # Get the number of video files in the store
> fileCount=$(cat /tmp/flist2.txt|wc -l)
> 
> # Get the number of video files in the DB
> fileDBCount=$(cat /tmp/flist.txt|wc -l)
> echo Total number of files found     : $fileCount
> echo Total number of DB entries found: $fileDBCount
> echo Checking to make sure things match.
> if [ $(cat /tmp/flist4.txt|wc -l) != "0" ] ; then
>    echo "Here is a list of problems found"
>    cat /tmp/flist4.txt
> fi
> # get the number of missing DB entries
> touch /tmp/NoDB.txt
> for line in $(cat /tmp/flist3.txt|grep ">"|awk '{ print $2 }') ;
>    do echo $line >/tmp/line.txt ;
>       cat /tmp/line.txt |awk -v qq="'" -F "[_.]" '{ print "mysql -D mythconverg --batch -s -e \"insert into recorded values (" qq $1 qq "," qq $2 qq "," qq $3 qq "," qq "???" qq "," qq "???" qq "," qq "???" qq ") ;\""  }'>/tmp/NoDB.txt
> done 
> NoDBCount=$(cat /tmp/NoDB.txt|wc -l)
> if [ $NoDBCount != "0" ]; then
>    echo
>    echo "Commands to fix: No DB entery"
>    echo "----------------------------"
>    cat /tmp/NoDB.txt
>    echo Or to free up disk space you can do:
>    for line in $(cat /tmp/flist3.txt|grep ">"|awk '{ print $2 }') ;
>       do echo $line >/tmp/line.txt ;
>         cat /tmp/line.txt |awk -v store=$store -F "[_.]" '{ print "rm -f " store "/" $1 "_" $2 "_" $3 ".nuv" }'
>    done 
> else 
>    echo All Files have DB entries
> fi
> 
> # Get the number of missing files
> touch /tmp/NoFile.txt
> for line in $(cat /tmp/flist3.txt|grep "<"|awk '{ print $2 }') ;
>    do echo $line >/tmp/line.txt ;
>       cat /tmp/line.txt |awk -F "[_.]" '{ print "mysql -D mythconverg --batch -s -e \"delete from recorded where chanid=" $1 " and starttime=" $2 " and endtime=" $3 " ;\""  }'>/tmp/NoFile.txt
> done 
> NoFileCount=$(cat /tmp/NoFile.txt|wc -l)
> if [ $NoFileCount != "0" ]; then
>    echo
>    echo "Commands to fix: No File found for DB entery"
>    echo "--------------------------------------------"
>    cat /tmp/NoFile.txt
> else
>    echo All DB entries have a file in the store.
> fi
> 
> rm -f /tmp/flist.txt /tmp/flist2.txt /tmp/flist3.txt /tmp/flist4.txt /tmp/NoDB.txt /tmp/NoFile.txt
> 
> 





More information about the mythtv-dev mailing list