View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 5 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Sat Nov 07, 2009 4:52 am 
Offline
Joined: Mon Sep 28, 2009 5:42 am
Posts: 50
The issue with a cron job for database backup is that it won't run if the machine isn't on at the right time. If (like me) you have your system automatically shutdown and startup to save power, then you may have run into this problem.

My solution is to run a cron job once every hour, instead of once every day. But rather than backup every hour I run a script that checks to see how long its been since the last backup. If its been longer than 24hrs then the backup is done, otherwise nothing happens.

As suggested on the mythtv wiki I use the mythconverg_backup.pl script from here. Note that it needs to be setup before you can use it. Use the wiki as a reference for how to do that.

My script looks like this
Code:
#!/bin/bash

# Backup directory
backupdir=/home/mythtv/backup

# Has it been more than 24hrs since last backup?
date
needbackup=$(find $backupdir -type f -mmin -1439)
if [ "$needbackup" = "" ]; then
  echo 'need backup'
  /home/mythtv/bin/mythconverg_backup.pl
else
  echo 'no backup needed'
fi
and my crontab entry looks like this
Code:
15 * * * * /home/mythtv/bin/mythbackup >> /home/mythtv/backuplog 2>&1
i.e. the script gets called at 15min after every hour.

The guts of the script is the definition of the "needbackup" variable. If a file younger than 24hrs exists in the backup directory (I use the timestamp option of find) then no backup is needed, otherwise a backup is done.

Thankfully I've never had to use the database backups that I've made, but its reassuring that they're there.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 07, 2009 10:51 am 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
KnoppMyth/LinHES does come with a set of backup utilities, and there's a lot of coverage here in the forums about how to set up various automated schemes using them. For example, your scheme might benefit from the use of the idle.sh script to make sure that the backup doesn't interfere with recordings or the like. Searching for idle.sh in the forums should provide a number of examples.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 08, 2009 5:59 pm 
Offline
Joined: Mon Sep 28, 2009 5:42 am
Posts: 50
tjc wrote:
For example, your scheme might benefit from the use of the idle.sh script to make sure that the backup doesn't interfere with recordings or the like.


Thanks for your suggestion, but testing for the system being idle defeats the purpose somewhat. I really need to assume that the machine is only on for recording (which will happen when we're on holidays, for instance).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 09, 2009 7:43 pm 
Offline
Joined: Tue May 05, 2009 10:39 am
Posts: 3
Thanks for your suggestion.I am lucky to read to this forum this is a big help to me..cause this past few days dont know what to do with my backup..Thanks a lot.Image


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 13, 2009 7:09 pm 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
If you're doing a backup with the system active you're creating two potential problems. First, having the backup interfere with the recording and corrupting it, second, recording an inconsistent DB state and producing a bad backup.

The usual solution is to schedule a "maintenance" wake up event at particular times or intervals. I know it's been discussed here along with the "how to" details.


Top
 Profile  
 

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


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 15 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