脚本
#!/bash/bin
user=root #用户名
password=123456 #密码
back_path=/backup/db
databases_file=/backup/databases.list
[ -f $databases_file ] || touch /backup/databases.list
if [[ ! -s ${databases_file} ]]
then
while read line
do[ -d ${back_path}/$line ] || mkdir -p ${back_path}/$linemysqldump -u${user} -p${password} -B $line 2>/dev/null | gzip 1> ${back_path}/${line}/${line}.sql.gzmysql -u$user -p$password -N -e "show tables from $line" 1> /backup/tbname 2>/dev/nullwhile read tbdomysqldump -u${user} -p${password} $line $tb 2>/dev/null | gzip 1>${back_path}/$line/${line}_${tb}.sql.gzdone < /backup/tbname
done < $databases_file
if [ $? -eq 0 ]
thenecho "备份成功!!备份目录是$back_path"
elseecho "备份失败!!!请检查"
fi
rm -rf /backup/tbname
true > $databases_file
执行脚本
备份成功!