The shell code is as follows
[[email protected] /]# cat back.sh #!/bin/bash/etc/init.d/mysqld status &> /dev/null[ $? -ne 0 ] && echo "Please open mysqld Service " && exit 0user=rootpass=" 123.com "backdb= ' Mysql -u$user -p" $pass " -e "show databases;" | sed ' 1d ' |grep -v ' schema ' |grep -v ' home ' | grep -v ' MySQL ' | grep -v ' Test ' ' echo -e ' \033[32m ======================= backup start ==== ================= \033[0m "for i in $backdbdotables = ' Mysql -u$user -p" $pass " -e" use $i;show tables; " | sed ' 1d ' for j in $tablesdomysqldump -u$user -p "$pass" -b --database $i --tables $j > /tmp/${i}-${j}-' Date +%f.sql ' [ $? -eq 0 ] && echo -e "$i $j \033[32m ok \033[0m" | | echo "$i $j \033[31m filed \033[0m" donedoneecho -e "\033[32m========= ===============backup stop==========================\033[0m "
Execution results are as follows
650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/20/8813f5feea13ab5fb96d68d966bf26cd.png "title=" capture. PNG "alt=" 8813f5feea13ab5fb96d68d966bf26cd.png "/>
650) this.width=650; "src=" Https://s2.51cto.com/oss/201710/20/b7ddcb96697adca1bcbaeffb9372a9ec.png "title=" capture. PNG "alt=" B7ddcb96697adca1bcbaeffb9372a9ec.png "/>
This article is from the "It Life" blog, so be sure to keep this source http://dingxue.blog.51cto.com/12290895/1974745
Shell finishing (====mysql) sub-database sub-table backup