View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 6 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
 Post subject: mythbackup via cron
PostPosted: Wed Mar 05, 2008 9:09 pm 
Offline
Joined: Wed Jan 18, 2006 8:36 pm
Posts: 199
I am not the best about backing-up my myth box and it could have saved me a few times. I've created script that can be called from a cron job to automatically backup my system. The script attempts to make sure your backend is not recording before performing the backup.
Code:
#/bin/sh

file=/tmp/status.html

wget -q -O $file http://localhost:6544
# Make sure backend is not already recording
grep -q 'is recording' $file
if test $? -eq 0 ; then
  # Some encoder is recording
  exit 0
fi

mythbackup
if $? -ne 0 ; then
  echo "Warning: mythbackup failed!"
fi
rm -f $file


I store this as run-mythbackup and have it execute from /etc/crontab once a week on Sunday:
Code:
15 4 * * 0      root    /usr/local/bin/run-mythbackup


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 05, 2008 11:41 pm 
Offline
Joined: Sun Jun 12, 2005 10:55 pm
Posts: 3161
Location: Warwick, RI
Hi,

I also modified the menu halt button so my box does a backup before shutdown. That way if I forget to do a backup before going for an upgrade I don't hose myself :)
As always, watch for line wrapping.

halt-control.sh
Code:
#<code>
#!/bin/bash
# Shutdown mesage
lsmod |grep "ivtvfb "|cut -b1-6 >/tmp/tv
if [ $(cat /tmp/tv) = "ivtvfb" ]; then
fontsize="26"
fontcolor="lightyellow"
else
fontsize="34"
fontcolor="yellow"
fi
killall xterm
sudo killall mythfrontend&
echo "Starting Backup, followed with Shutdown" > /tmp/ver
echo "This may take a few minutes...." >> /tmp/ver
export DISPLAY=:0
export FONT="-adobe-helvetica-bold-*-*-*-$fontsize-*-*-*-*-*-*-*"
cat /tmp/ver | osd_cat --delay=180 --font=$FONT --color=$fontcolor --shadow=2 --pos=middle --align=centre&
festival --tts /tmp/ver >/dev/null
(play /usr/share/sounds/beg.wav) > /dev/null
sleep 1
sudo /usr/local/bin/mythbackup
killall osd_cat
(play /usr/share/sounds/end.wav)& > /dev/null
sleep 3
#(play /myth/saytime/gas.wav)& > /dev/null
sudo halt
#<end code>


Mike


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 6:45 pm 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
Also see the discussion in this thread for a more robust script. http://knoppmyth.net/phpBB2/viewtopic.php?t=17988


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 9:17 pm 
Offline
Joined: Wed Jan 18, 2006 8:36 pm
Posts: 199
Thanks for the suggestion. This is much better:
Code:
#/bin/sh

# Make sure backend is not busy
mythshutdown -s
if test $? -ne 0 ; then
  # 1 = transcoding, 2 = comm flag, 4 = grabbing data, 16 = locked
  exit 0
fi

mythbackup
if $? -ne 0 ; then
  echo "Warning: mythbackup failed!"
fi


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 9:36 pm 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
Well, the intent was actually to have you try the idle.sh script posted in that thread which is substantially smarter about current and upcoming system activity... ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 08, 2008 3:55 pm 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
I've published a link to the full blown idle.sh script in the thread mjl refers to above.

- Download it from there and put it in /usr/local/bin

- Make sure it's owned by root and has execute permissions:
Code:
chown root:root /usr/local/bin/idle.sh
chmod u=rwx,go=rx /usr/local/bin/idle.sh


- Change your cron command to be something like:
Code:
/usr/local/bin/idle.sh -s && /usr/local/bin/mythbackup >/var/log/backup.log 2>&1

Another possibility is to do something like this
Code:
(/usr/local/bin/idle.sh && /usr/local/bin/mythbackup) >/var/log/backup.log 2>&1

Which will include the verbose output from idle.sh in the log file. Note that both of these should be run as root to allow writing the logs in /var/log

- If you want to get really fancy configure the logfile rolling to keep a recent history of the logs.


Top
 Profile  
 

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


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 12 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:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu