LinHES Forums
http://forums.linhes.org/

Database backup for a machine that is NOT always on
http://forums.linhes.org/viewtopic.php?f=24&t=20486
Page 1 of 1

Author:  bigtoedsloth [ Sat Nov 07, 2009 4:52 am ]
Post subject:  Database backup for a machine that is NOT always on

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.

Author:  tjc [ Sat Nov 07, 2009 10:51 am ]
Post subject: 

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.

Author:  bigtoedsloth [ Sun Nov 08, 2009 5:59 pm ]
Post subject: 

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).

Author:  Juliannepei [ Mon Nov 09, 2009 7:43 pm ]
Post subject: 

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

Author:  tjc [ Fri Nov 13, 2009 7:09 pm ]
Post subject: 

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.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/