#!/bin/bash
path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export path
#數(shù)據(jù)庫(kù)用戶名
dbuser='1111'
#數(shù)據(jù)庫(kù)用密碼
dbpasswd='2222'
#備份數(shù)據(jù)庫(kù)
dbname='3333'
#備份時(shí)間
BACKUP_TIME=`date +"%Y/%m/%d %H:%M.%S"`
backup_time=`date +"%Y%m%d"`
#日志備份路徑
logpath='/var/log/MySQL_backup'
[ ! -e "$logpath" ] && mkdir $logpath
cd $logpath
touch mysql_backup.log
cd
#數(shù)據(jù)備份路徑
datapath='/home/backup/mysql_back'
[ ! -e "$datapath" ] && mkdir $datapath
#日志記錄頭部
echo "備份時(shí)間為${BACKUP_TIME},備份數(shù)據(jù)庫(kù)表 ${dbname} 開(kāi)始" >> ${logpath}/mysql_backup.log
#正式備份數(shù)據(jù)庫(kù)
SQLBakName="${backup_time}.lxhp.tar.gz"
mysqldump --user=$dbuser --password=$dbpasswd --databases $dbname > $datapath/mysql_backup_${backup_time}.sql
find $datapath -type f -mtime +7 -exec rm -rf {} \; > /dev/null 2>&1
當(dāng)前名稱:mysql_backup.sh
轉(zhuǎn)載來(lái)源:
http://weahome.cn/article/gdcdjj.html