LINUX mysql数据库备份
log_file=”/usr1/tools/job/log/mysqlbak.log”
echo $(date) >>$log_file
db_user=”root” #用户名
db_passwd=”123456″ #密码
db_host=”localhost” #IP
backup_dir=”/usr1/tools/mysql5130/mysql_bak” #备份文件路径
time=”$(date +”%Y%m%d%H%M%S”)” #时间戳
MYSQL=”/usr1/tools/mysql5130/bin/mysql” #mysql安装路径
MYSQLDUMP=”/usr1/tools/mysql5130/bin/mysqldump” #mysql执行备份(mysqldump)的路径
#本功能会备份所有数据库 #如果要备份一个数据库, 在 do … done 里面添加if判断 例如: if [ $db = “ybd” ] … fi
all_db=”$($MYSQL -u $db_user -h $db_host -p$db_passwd -Bse ‘show databases’)”
for db in $all_db
do
#if [ $db = “ybd” ]
then
$MYSQLDUMP -u $db_user -h $db_host -p$db_passwd $db | gzip > “$backup_dir/$time.$db.sql.gz”
#fi
done
exit 0;