数据库备份脚本
简单的数据库备份脚本,通过传递参数选择需要备份的库;
#!/bin/bash # Descripts: mysql backup # /scripts/mysqlbackup.sh {db1|db2} Item=$1 C_DATE=`date '+%F_%T'` BakDir=/home/backup/mysql_backup/ LogFile=/home/backup/mysql_backup/bak.log [ ! -d ${BakDir} ] && mkdir -pv /home/backup/mysql_backup/ if [ $# != 1 ] ;then echo "USAGE: $0 {db1|db2}" exit fi if [ ${Item} != db1 ] && [ ${Item} != db2 ];then echo "USAGE: $0 {db1|db2}" exit fi Begin=`date +"%Y年%m月%d日 %H:%M:%S"` cd ${BakDir} /usr/bin/mysqldump -uroot -p'123456' --master-data=2 -F -B ${Item} > /${BakDir}/${Item}.${C_DATE}.sql Last=`date +"%Y年%m月%d日 %H:%M:%S"` echo 开始:$Begin 结束:$Last ${Item}.${C_DATE}.sql succ >> $LogFile Begin=`date +"%Y年%m月%d日 %H:%M:%S"` cd ${BakDir} /usr/bin/mysqldump -uroot -p'123456' --master-data=2 -F -B ${Item} > /${BakDir}/${Item}.${C_DATE}.sql Last=`date +"%Y年%m月%d日 %H:%M:%S"` echo 开始:$Begin 结束:$Last ${Item}.${C_DATE}.sql succ >> $LogFile</SPAN></PRE></DIV>