summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/LinHES-system/bin/mythbackup
blob: dfba6116fa3f71b394939655ea5f4f5993f971cb (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
#!/bin/bash

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

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

# Prevent mythshutdown from shutting down the system in the middle...
/usr/bin/mythshutdown --lock

# Keep a chain of recent backups,
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."

# 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.
/etc/init.d/mythtv-backend stop

# Stop, check, and fix $DATABASE db to ensure clean copy, then restart it.
/etc/init.d/mysql stop
cd $DATABASE_DIR
/usr/bin/myisamchk -f *.MYI
/etc/init.d/mysql stop ; /etc/init.d/mysql start

# Dumps the $DATABASE database
/usr/bin/mysqldump -c -u root $DATABASE > $BACKUP_SQL
shrink $BACKUP_SQL

# 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 /
/bin/tar cvf $BACKUP_TAR $BACKUP_LIST 2>&1 |
    /bin/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.
/bin/chown root:root $BACKUP_TAR* $BACKUP_SQL*
/bin/chmod go-rwx $BACKUP_TAR* $BACKUP_SQL*

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
    echo "Backup passes all checks."
    play_sound complete.wav
    STATUS=0
else
    echo "The backup is bad or already out of date!"
    play_sound fail.wav
    STATUS=1
fi

# Now we can restart the backend.
/etc/init.d/mythtv-backend stop ; /etc/init.d/mythtv-backend start

# Unlock the system again...
/usr/bin/mythshutdown --unlock

exit $STATUS