Readers may be interested in an approach to automating database backups of a mythtv system.

Readers may be interested in an approach to automating database backups of a mythtv system.

−

This mechanism can be used with dedicated Mythbuntu frontend/backend with mythwelcome and ACPI wakeup.

+

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:

It was thought that database backups should be taken:

Line 22:

Line 24:

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

*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 is placed in /usr/bin/autobackup.sh and which calls [[mythconverg_backup.pl]] as appropriate. It is called itself from the recording start system event and from within [[setwakeup.sh]]

+

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''

+

+

See [[Database Backup and Restore]] for full details of mythconverg_backup.pl.

−

The script can be placed in /usr/bin/autobackup.sh

+

The script can be placed in ''/usr/bin/autobackup.sh''

−

{{bash|autobackup.pl|

<pre>

<pre>

#!/bin/bash

#!/bin/bash

Line 66:

Line 69:

echo " need parameter">>$MYLOG

echo " need parameter">>$MYLOG

echo "Needs parameter: try $0 --help"

echo "Needs parameter: try $0 --help"

+

exit

elif [ $1 == "--recording" ]; then

elif [ $1 == "--recording" ]; then

Line 99:

Line 103:

fi

fi

−

RECDAY=$(($(date --reference=${MYRECFILE} +%s)- 14400))

−

RECDAY=$((RECDAY/86400))

WAKEDAY=$((${2}-14400))

WAKEDAY=$((${2}-14400))

WAKEDAY=$((WAKEDAY/86400))

WAKEDAY=$((WAKEDAY/86400))

+

+

if [ $WAKEDAY -eq $TODAY ]; then

+

echo " Another recording expected today">>$MYLOG

+

exit

+

fi

+

+

RECDAY=$(($(date --reference=${MYRECFILE} +%s)- 14400))

+

RECDAY=$((RECDAY/86400))

if [ $((WAKEDAY-RECDAY)) -ge 1 ];then # 1 is interval in days - change if necessary

if [ $((WAKEDAY-RECDAY)) -ge 1 ];then # 1 is interval in days - change if necessary

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

+

See [[MythTV System Events]]

−

The setwakeup script is:

+

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:

+

<pre>

+

#!/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

+

+

+

</pre>

+

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

+

'''Recording backups'''

−

[[Category:Bash_Scripts]]

+

If the file ''/usr/bin/autobackup.pl'' is present, then the script will also trigger a selective backup of recordings.

+

See [[autobackup.pl]] for details.

+

[[Category:Management Scripts]]

[[Category:Management Scripts]]

Revision as of 17:41, 8 January 2013

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: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

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.

Recording backups

If the file /usr/bin/autobackup.pl is present, then the script will also trigger a selective backup of recordings.
See autobackup.pl for details.