shell 代码如下
[root@localhost /]# cat back.sh #!/bin/bash/etc/init.d/mysqld status &> /dev/null[ $? -ne 0 ] && echo "请开启 mysqld 服务" && 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 $backdbdo tables=`mysql -u$user -p"$pass" -e"use $i;show tables;" | sed '1d'` for j in $tables do mysqldump -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" donedone echo -e "\033[32m========================backup stop==========================\033[0m"
执行结果如下