Autobackup.sh

Note:The correct title of this article is autobackup.sh. It appears incorrectly here due to technical restrictions.

name=unnamed
author=Phil Brady
webpage=none
short=Daily database backup at end of day
long=Daily database backup at end of day
file=autobackup.sh
category=Maintenance
supports=S21:unset,S22:unset,S23:unset,S231:unset,S24:unset,S241:unset,S25:yes,S251:unset,S252:unset,S26:unset,S27:yes,S28:unset,S29:unset

Author

Phil Brady

Description

Daily database backup at end of day

Supports

Readers may be interested in an approach to automating database backups of a mythtv system.
This mechanism is used with a dedicated mythtv frontend/backend system with Mythwelcome and ACPI Wakeup.
It has been validated with version 0.25 of Mythtv and Mythbuntu 12.04.

AIMS

It was thought that database backups should be taken:

daily

on days when recording had been made

at a time when the system was otherwise idle

preferably at the end of the day

if a recording should straddle midnight, the backup should be after that had finished, so 'end of day' needs defining as 4am.

This is achieved by a bash script which calls mythconverg_backup.pl as appropriate. It is called itself from the recording start system event and from within /usr/bin/setwakeup.sh

The user mythtv will be performing the backups. If the file (or link) /home/mythtv/.mythtv/config.xml does not exist then it will need creating so the backup system can access the database. However, if the file or link already exists then omit this step.

sudo cp ~/.mythtv/config.xml /home/mythtv/.mythtv/config.xml

The system needs to be triggered by the ‘Recording Start’ system event (frontend, setup, system events) which needs to be set to

It is also triggered in the /usr/bin/setwakeup.sh script which passes next wakeup time to the script and allows it to detect whether it is the last closedown of the 4am to 4am day and perform the database backup.

The standard setwakeup script is modified as follows:

#!/bin/sh
#$1 is the first argument to the script. It is the time in seconds since 1970
#this is defined in mythtv-setup with the time_t argument
echo 0 > /sys/class/rtc/rtc0/wakealarm #this clears your alarm.
echo $1 > /sys/class/rtc/rtc0/wakealarm #this writes your alarm
#do database backup if appropriate
if [ -x /usr/bin/autobackup.sh ]; then
/usr/bin/autobackup.sh --setwake $1
fi

Logging

The script placed logging information in /var/log/mythtv/autobackup.log and rotates it as necessary to /var/log/mythtv/autobackup.log.1 If logging is not required, simply remove these log files.

Backing up Recordings

If the file /usr/bin/autobackup.pl is present, then the script will also trigger a selective backup of recordings. The 'best set' which fits within the available space will be chosen and transferred.
See autobackup.pl for details.