restore.sh

#!/bin/sh
if test $1
then

#################### Modify the following before running ##############
backup_file_path='/db_restores'
mysql_passwd='MY_PASSWORD'

###### Extract the sql files from the backup mysql_restore.tar #######
save_current_path = pwd
cd $backup_file_path
rm -f *.sql
tar -xvf $backup_file_path/mysql_restore.tar
bunzip2 *.sql.bz2

####### Create a script to drop, create and load the passed in DB #######
echo which_db=$1 > db_$1.sh
echo mysql_password=$mysql_passwd >> db_$1.sh
echo 'echo starting drop, create, load for $which_db at `date` > db_log' >> db_$1.sh
echo "drop database $1;" > db_$1.sql
echo 'mysql -uroot -p$mysql_password < db_$which_db.sql >> db_log 2>&1' >> db_$1.sh
echo 'mysqladmin -uroot -p$mysql_password create $which_db >> db_log 2>&1' >> db_$1.sh
echo 'mysql -uroot -p$mysql_password $which_db < $which_db.sql >> db_log 2>&1' >> db_$1.sh
echo 'echo finished drop, create, load for $which_db at `date` >> db_log' >> db_$1.sh
chmod 755 db_$1.sh

cd $save_current_path
echo +++ Almost done +++
echo - Now cd $backup_file_path
echo - and run this command ./db_$1.sh
else
echo Missing required parameter database name for example: ./db_restore wikidb
fi