summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/lh_system_restore_job
blob: 9c66e2a15711f8400f777cf4f4d34e7221417e13 (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
#!/bin/bash
#  This script is used to perform a quick restore of a database that was backed up via the nightly system backup
#  The restore only does the database it does NOT restore system files (even if they are in the backup file)
#
BACKUPDIR=/myth/system_backups
backupfile=$1

function usage(){
    echo "------------------------------------------------------"
    echo "This program will restore the database from a system backup."

    echo "Files are expected to be in the $BACKUPDIR"
    echo "usage:"
    echo ""
    echo "lh_system_restore_job \$filename  [yes]"
    echo ""
    echo "example: lh_system_restore_job backup.2011-12-22_15-34.tgz "
    echo ""
    echo ""

    echo "If the script is passed a second argument, it will not cleanup the the restore dir."
    echo "------------------------------------------------------"

    exit 1
    }



if [ x$backupfile = x ]
then
    usage
fi

. /etc/profile

RESTOREDIR=$BACKUPDIR/restore
DIR=`echo $backupfile |cut -d. -f2`
CSQL="create database mythconverg;"
DSQL="drop database mythconverg; "
MYSQL="mysql  -u mythtv -pmythtv"



mkdir -p $RESTOREDIR
cp $BACKUPDIR/$backupfile $RESTOREDIR
cd $RESTOREDIR && tar -xf  $backupfile && cd $DIR

if [ -f mythconverg ]
then
    #drop the db
    $MYSQL -e "$DSQL"
    #create the db
    $MYSQL  -e "$CSQL"
    #restore the database_backup
    echo "Restoring the database  $DIR"
    $MYSQL  mythconverg < mythconverg
    if [ $? = 0 ]
    then
        echo "Done"
    else
        echo "An error occured"
    fi
 else
    echo "Couldn't file a file to restore"
fi


#cleanup
if [ x$2 = x ]
then
    echo "Cleaning up the restore dir"
    rm -rf $RESTOREDIR/$DIR
    rm -f $RESTOREDIR/$backupfile
else
    echo "Not doing a cleanup of $RESTOREDIR"
fi