![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
# #!/bin/bash
![None.gif](p_w_picpaths/editer/None.gif)
# ######################################################################
![None.gif](p_w_picpaths/editer/None.gif)
# # ScriptName : AMBT.sh--Auto Mysql Backup Tool #
![None.gif](p_w_picpaths/editer/None.gif)
# # Date : 2007 - 10 - 04 Thu #
![None.gif](p_w_picpaths/editer/None.gif)
# # Author : Drinkey [SYC] http:
//drinkey.syclover.cn #
![None.gif](p_w_picpaths/editer/None.gif)
# # Version : 0.1 'Not finished yet... #
![None.gif](p_w_picpaths/editer/None.gif)
# # #
![None.gif](p_w_picpaths/editer/None.gif)
# # Descrition : You can use
this script to backup your database, #
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
Discuz! ,it can read the database #
![None.gif](p_w_picpaths/editer/None.gif)
# # and backup your database automaticly.If you're
using #
![None.gif](p_w_picpaths/editer/None.gif)
# # others,you can enter the infomation on your keyboard. #
![None.gif](p_w_picpaths/editer/None.gif)
# # #
![None.gif](p_w_picpaths/editer/None.gif)
# # Useage : $PWD/ambt path_of_the_CONFIG.INC.PHP #
![None.gif](p_w_picpaths/editer/None.gif)
# # $PWD/ambt <CR>, then enter your Infomation of your DB #
![None.gif](p_w_picpaths/editer/None.gif)
# # #
![None.gif](p_w_picpaths/editer/None.gif)
# # Note : The user and password you entered or the user of Discu#
![None.gif](p_w_picpaths/editer/None.gif)
# # z!,they're supposed to has permission to backup your #
![None.gif](p_w_picpaths/editer/None.gif)
# # database. #
![None.gif](p_w_picpaths/editer/None.gif)
# ######################################################################
![None.gif](p_w_picpaths/editer/None.gif)
# CONF='config.inc.php'
![None.gif](p_w_picpaths/editer/None.gif)
# ROOT_UID=0
![None.gif](p_w_picpaths/editer/None.gif)
# E_NOTEXIST=65
![None.gif](p_w_picpaths/editer/None.gif)
# PREFIX='mysql_backup'
![None.gif](p_w_picpaths/editer/None.gif)
# DUMPFILE=$PWD/$PREFIX$(date +%y%m%d).sql
![None.gif](p_w_picpaths/editer/None.gif)
#
![None.gif](p_w_picpaths/editer/None.gif)
# #------IF the user
is NOT root,asking
for some infomation --------#
![None.gif](p_w_picpaths/editer/None.gif)
#
if [
"$UID" -ne
"$ROOT_UID" ]; then
![None.gif](p_w_picpaths/editer/None.gif)
# echo -e
"You're NOT ROOT.\n"
![None.gif](p_w_picpaths/editer/None.gif)
# echo -e
"Please Enter the info of database which you want backup.\n"
![None.gif](p_w_picpaths/editer/None.gif)
# echo
"Database Name:"
![None.gif](p_w_picpaths/editer/None.gif)
# read N_DBName
![None.gif](p_w_picpaths/editer/None.gif)
# echo
"Database User:"
![None.gif](p_w_picpaths/editer/None.gif)
# read N_DBUser
![None.gif](p_w_picpaths/editer/None.gif)
# echo
"Database Password:"
![None.gif](p_w_picpaths/editer/None.gif)
# read N_DBPassword
![None.gif](p_w_picpaths/editer/None.gif)
#
![None.gif](p_w_picpaths/editer/None.gif)
# #------IF there's a file with same name,means he has backuped today ----#
![None.gif](p_w_picpaths/editer/None.gif)
#
if [ -x
"$DUMPFILE" ]; then
![None.gif](p_w_picpaths/editer/None.gif)
# echo
"You've backuped your database today."
![None.gif](p_w_picpaths/editer/None.gif)
# echo
"If you want backup anyway,please delete $DUMPFILE"
![None.gif](p_w_picpaths/editer/None.gif)
#
else
![None.gif](p_w_picpaths/editer/None.gif)
# mysqldump -u$N_DBUser -p$N_DBPassword --opt $N_DBName > $DUMPFILE
![None.gif](p_w_picpaths/editer/None.gif)
# sleep 1
![None.gif](p_w_picpaths/editer/None.gif)
# echo
"Backup complet!"
![None.gif](p_w_picpaths/editer/None.gif)
# fi
![None.gif](p_w_picpaths/editer/None.gif)
#
![None.gif](p_w_picpaths/editer/None.gif)
#
else
![None.gif](p_w_picpaths/editer/None.gif)
# #------The path the user entered
is correct??-------#
![None.gif](p_w_picpaths/editer/None.gif)
#
if [ -x
"$1$CONF" ]; then
![None.gif](p_w_picpaths/editer/None.gif)
# COFILE=
"$1$CONF"
![None.gif](p_w_picpaths/editer/None.gif)
# echo
"File exists,read info from $COFILE."
![None.gif](p_w_picpaths/editer/None.gif)
# awk -F\' '/\$dbuser/ { print
"User: "$2}' $COFILE > $PWD/tmp
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
# awk -F\' '/\$dbpw/ { print
"Passwd: "$2}' $COFILE >> $PWD/tmp
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
# awk -F\' '/\$dbname/ { print
"DBName: "$2}' $COFILE >> $PWD/tmp
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
# sleep 1
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
# DBUser=
"`awk '/User/{print $2}' tmp`"
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
# DBName=
"`awk '/DBName/{print $2}' tmp`"
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
# DBPassword=
"`awk '/Passwd/{print $2}' tmp`"
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
# sleep 1
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
# mysqldump -u$DBUser -p$DBPassword $DBName > $DUMPFILE
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
# echo
"Backup complet!"
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
# rm -f tmp
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
#
else
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
# echo
"File not exists,Please check the path."
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
# exit $E_NOTEXIST
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
# fi
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
#
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
# fi