自动备份数据库的Shell
时间:2009-03-23 来源:sjhf
# #!/bin/bash # ###################################################################### # # ScriptName : AMBT.sh--Auto Mysql Backup Tool # # # Date : 2007 - 10 - 04 Thu # # # Author : Drinkey [SYC] http://drinkey.syclover.cn # # # Version : 0.1 'Not finished yet... # # # # # # Descrition : You can use this script to backup your database, # Discuz! ,it can read the database # # # and backup your database automaticly.If you're using # # # others,you can enter the infomation on your keyboard. # # # # # # Useage : $PWD/ambt path_of_the_CONFIG.INC.PHP # # # $PWD/ambt <CR>, then enter your Infomation of your DB # # # # # # Note : The user and password you entered or the user of Discu# # # z!,they're supposed to has permission to backup your # # # database. # # ###################################################################### # CONF='config.inc.php' # ROOT_UID=0 # E_NOTEXIST=65 # PREFIX='mysql_backup' # DUMPFILE=$PWD/$PREFIX$(date +%y%m%d).sql # # #------IF the user is NOT root,asking for some infomation --------# # if [ "$UID" -ne "$ROOT_UID" ]; then # echo -e "You're NOT ROOT.\n" # echo -e "Please Enter the info of database which you want backup.\n" # echo "Database Name:" # read N_DBName # echo "Database User:" # read N_DBUser # echo "Database Password:" # read N_DBPassword # # #------IF there's a file with same name,means he has backuped today ----# # if [ -x "$DUMPFILE" ]; then # echo "You've backuped your database today." # echo "If you want backup anyway,please delete $DUMPFILE" # else # mysqldump -u$N_DBUser -p$N_DBPassword --opt $N_DBName > $DUMPFILE # sleep 1 # echo "Backup complet!" # fi # # else # #------The path the user entered is correct??-------# # if [ -x "$1$CONF" ]; then # COFILE="$1$CONF" # echo "File exists,read info from $COFILE." # awk -F\' '/\$dbuser/ { print "User: "$2}' $COFILE > $PWD/tmp # awk -F\' '/\$dbpw/ { print "Passwd: "$2}' $COFILE >> $PWD/tmp # awk -F\' '/\$dbname/ { print "DBName: "$2}' $COFILE >> $PWD/tmp # sleep 1 # DBUser="`awk '/User/{print $2}' tmp`" # DBName="`awk '/DBName/{print $2}' tmp`" # DBPassword="`awk '/Passwd/{print $2}' tmp`" # sleep 1 # mysqldump -u$DBUser -p$DBPassword $DBName > $DUMPFILE # echo "Backup complet!" # rm -f tmp # else # echo "File not exists,Please check the path." # exit $E_NOTEXIST # fi # # fi 一个备份数据库用的工具,可以加在计划任务里,每天备份,专门为Discuz!优化,如果你是root,直接运行该工具就可以完成备份,生成一个sql文件,以便恢复用。 我的第一个shell,纪念一下,呵呵~难免有错,欢迎指正 |
相关阅读 更多 +