#!/bin/bash
#1.數(shù)據(jù)庫信息定義
echo "Enter mysql password:"
read PWD
mysql_host="localhost"
mysql_user="root"
mysql_passwd=$PWD
#sql備份目錄
back_dir="/home/bakdb"
if [ ! -d $back_dir ]; then
mkdir -p $back_dir
fi
#備份的數(shù)據(jù)庫數(shù)組
db_arr=$(echo "show databases;" | mysql -u$mysql_user -p$mysql_passwd -h$mysql_host)
#當(dāng)前日期
nowdate=`date +%Y-%m-%d`;
#2.進(jìn)入到備份目錄
cd $back_dir
mkdir $nowdate
cd $nowdate
#3.循環(huán)備份
for dbname in ${db_arr}
do
if [ "$dbname" = "information_schema" ] || [ "$dbname" = "Database" ] || [ "$dbname" = "test" ] || [ "$dbname" = "performance_schema" ] || [ "$dbname" = "mysql" ]; then
echo "no"
else
sqlfile=$dbname".sql"
a=`mysqldump -u$mysql_user -p$mysql_passwd -h$mysql_host $dbname >$sqlfile`
echo $dbname
fi
done
發(fā)表評(píng)論