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

一个备份数据库用的工具,可以加在计划任务里,每天备份,专门为Discuz!优化,如果你是root,直接运行该工具就可以完成备份,生成一个sql文件,以便恢复用。
我的第一个shell,纪念一下,呵呵~难免有错,欢迎指正