View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 3 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
 Post subject: Auto mythbackup script
PostPosted: Fri Jul 13, 2007 9:57 pm 
Offline
Joined: Mon Feb 16, 2004 7:06 pm
Posts: 309
Location: Toronto
This is a little diddy I threw together that needs testing. It's an automatic mythbackup script that checks to see if the backend is busy before running, and if it is, it reschedules itself to run an hour later again and again until it succeeds, then resets itself to run again at the original time (every monday at 2AM)

WARNING!!! THIS IS BETA CODE!!

Prerequisites: Add the following line to your /etc/crontab
Code:
0 2 * * 1       root    /myth/data/backup/scripts/autobackup.sh


Things to Note:
The script fails to detect whether or not the upcoming recordings are actually going to be recorded.
If your system is busy all day and you run out of Monday it won't run because there are not 25 hours in the day. You will manually have to fix your cron entry
It is also very rudimentary, if you have other things scheduled at that time it will change those entries also.

Code:
#!/bin/sh
# initalize variables
db='mythconverg'
user='root'
password=''
SCRIPTDIR=/myth/data/backup/scripts

data0=`mysql $db -u $user -e "select count(*) from inuseprograms where recusage like 'player'" -sN`
data1=`mysql $db -u $user -e "select count(*) from inuseprograms where recusage like 'recorder'" -sN`
data2=`mysql $db -u $user -e "select count(*) from record
                                inner join recordmatch on record.recordid=recordmatch.recordid
                                where timediff(recordmatch.starttime,sysdate())<'00:10:00' and
                                recordmatch.starttime > sysdate() and
                                inactive=0 and (type!=0 or type!=8);" -sN`

CRONENTRY=$(grep autobackup /etc/crontab|gawk -F'[ ]' '{print $1,$2,"\\"$3,"\\"$4,$5}')
HOUR=$(grep autobackup /etc/crontab|gawk -F'[ ]' '{print $2}')
NEWCRON="0 $(expr $HOUR + 1) \* \* 1"

if [ $data0 -ge 1 -o $data1 -ge 1 -o $data2 -ge 1 ]; then
        cat /etc/crontab | sed "s/$CRONENTRY/$NEWCRON/g" > /etc/crontab
else
        cat /etc/crontab | sed "s/$CRONENTRY/0 2 \* \* 1/g" > /etc/crontab
        mythbackup
fi

exit 0


If you find any flaws or ways to augment it, please post. Comments are appreciated.

_________________
KnoppMyth Folding@home
How to setup F@H
F@H Stats Page


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 10:45 pm 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
Rather than rescheduling it'd probably be simpler to just hang around and wait... It avoids the problem of stepping on other crontab entries or leaving a bunch of extra ones around... Make sure there's only one copy of the job running and loop until you get a break, sleeping for a half an hour at a pop takes up no CPU to speak of...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 2:27 pm 
Offline
Joined: Mon Feb 16, 2004 7:06 pm
Posts: 309
Location: Toronto
Another version for those who don't like modifying their crontab

Also needs testing

Code:
#!/bin/sh
# initalize variables
db='mythconverg'
user='root'
password=''
SCRIPTDIR=/myth/data/backup/scripts
BACKEDUP="false"

while [ $BACKEDUP = "false" ]
do
   data0=`mysql $db -u $user -e "select count(*) from inuseprograms where recusage like 'player'" -sN`
   data1=`mysql $db -u $user -e "select count(*) from inuseprograms where recusage like 'recorder'" -sN`
   data2=`mysql $db -u $user -e "select count(*) from record
                                inner join recordmatch on record.recordid=recordmatch.recordid
                                where timediff(recordmatch.starttime,sysdate())<'00:10:00' and
                                recordmatch.starttime > sysdate() and
                                inactive=0 and (type!=0 or type!=8);" -sN`

   if [ $data0 -ge 1 -o $data1 -ge 1 -o $data2 -ge 1 ]; then
        BACKEDUP="false"
        sleep 1800
   else
        BACKEDUP="true"
        mythbackup
   fi
done

exit 0

_________________
KnoppMyth Folding@home
How to setup F@H
F@H Stats Page


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 82 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu