summaryrefslogtreecommitdiffstats
path: root/abs/mv-core/MythVantage-system/restore_job.sh
blob: 0d0bec7d7b5fcea3fa896b94233e962a7e92421f (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
#!/bin/bash
backupfile=$1
. /etc/profile
BACKUPDIR=/data/database_backup
RESTOREDIR=$BACKUPDIR/restore
DIR=`echo $backupfile |cut -d. -f2`
CSQL="create database mythconverg;"
DSQL="drop database mythconverg; "
MYSQL="mysql  -u mythtv -pmythtv"



mkdir $RESTOREDIR
cp $BACKUPDIR/$backupfile $RESTOREDIR
cd $RESTOREDIR && tar -xvf  $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
rm -rf $RESTOREDIR/$DIR
rm -f $RESTOREDIR/$backupfile