summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/LinHES-system/bin/mythbackup
blob: 3b4edd4fc68cbdb4d8f92bbc99d49f7073966338 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash

#----------------------------------------------------------------------------
. /usr/LH/bin/backupcommon || {
    echo 1>&2 "Can not load common settings!"
    exit 1
}

. /etc/osd_cat.cfg || {
	color=yellow
	outline=2
	outlinecolour=black
	shadow=0
	shadowcolour=black
	font="-adobe-helvetica-bold-*-*-*-34-*-*-*-*-*-*-*"
}
#----------------------------------------------------------------------------

# Function to display status onscreen
osd()
# Arg_1 = display text Arg_2 = delay time Arg_3 = line num
{
    TEXT=$1
    killall -9 osd_cat
    if [ $3 -gt 1 ]; then
        for ((i=2; i <= $3 ; i++))
        do
            TEXT="\n"$TEXT
        done
    fi
    printf "$TEXT" | osd_cat --lines=6 --pos=middle --align=center --delay=$2 --color=$color --outline=$outline --outlinecolour=$outlinecolour --shadow=$shadow --shadowcolour=$shadowcolour --font=$font &
}

# Prevent mythshutdown from shutting down the system in the middle...
lock_myth

# Play a sound to let you know I'm starting.
play_sound init.wav

# Keep a chain of recent backups,
export DISPLAY=:0.0
osd "Rolling over old backups..." 0 1
echo "Starting rollover of old backups, this may take a while..."
[ -f "$BACKUP_SQL" ] && shrink $BACKUP_SQL
[ -f "$BACKUP_TAR" ] && shrink $BACKUP_TAR
backup_roller .19 .18 .17 .16 .15 .14 .13 .12 .11 .10 .9 .8 .7 .6 .5 .4 .3 .2 .1 ''
echo "Rollover completed."

osd "Checking the database..." 0 2
# Start with the database backup, first we make sure it's healthy, and
# then we can dump it.
# Doing this while the backend is active would be BAD.
stop_mythbackend

# Stop, check, and fix $DATABASE db to ensure clean copy, then restart it.
stop_mysqld
cd $DATABASE_DIR
$MYISAMCHK -f *.MYI
start_mysqld

osd "Backing up database..." 0 3
# Dumps the $DATABASE database
$MYSQLDUMP -v -c -u root $DATABASE > $BACKUP_SQL
shrink $BACKUP_SQL

osd "Backing up files..." 0 4
# Now to backup the other files, no fooling around, grab everything in the
# list because you never know what you'll want, and we can always get clever
# about what to restore later...

# gather all the things in the list into a nice tidy bundle
cd /
$TAR cvf $BACKUP_TAR $BACKUP_LIST 2>&1 |
    $SED -e '/Error exit delayed from previous errors/d'
shrink $BACKUP_TAR

# If you can't read this you've got no business restoring from it anyway.
$CHOWN root:root $BACKUP_TAR* $BACKUP_SQL*
$CHMOD go-rwx $BACKUP_TAR* $BACKUP_SQL*

osd "Testing backup..." 0 5
echo "Sanity checking your backup..."
play_sound testing.wav
# Play a sound to let you know the outcome.
if check_files_and_tables $BACKUP_LIST ; then
    osd "Backup completed successfully." 5 6
    echo "Backup passes all checks."
    COMPLETE_MSG="Last backup completed on `date '+%D @ %-I:%M %p'`"
    play_sound complete.wav
    STATUS=0
else
    osd "Backup FAILED." 5 6
    echo "The backup is bad or already out of date!"
    COMPLETE_MSG="Last backup FAILED on `date '+%D @ %-I:%M %p'`"
    play_sound fail.wav
    STATUS=1
fi

# Add Last backup status to menu item
if grep "<description>" /usr/share/mythtv/themes/defaultmenu/mythbackup.xml >/dev/null 2>&1
then
    sed -i "s_\<description\>.*\<description\>_description\>$COMPLETE_MSG\<\/description_" /usr/share/mythtv/themes/defaultmenu/mythbackup.xml
else
    sed -i.orig " /NONE/ i\     \<description\>$COMPLETE_MSG\<\/description\>" /usr/share/mythtv/themes/defaultmenu/mythbackup.xml
fi

# Now we can restart the backend.
start_mythbackend

# Unlock the system again...
unlock_myth

exit $STATUS