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