shell 代码如下
[root@localhost/]#catback.sh #!/bin/bash /etc/init.d/MysqLdstatus&>/dev/null [$?-ne0]&&echo"请开启MysqLd服务"&&exit0 user=root pass="123.com" backdb=`MysqL-u$user-p"$pass"-e"showdatabases;"|sed'1d'|grep-v'schema'|grep-v'home'|grep-v'MysqL'|grep-v'test'` echo-e"\033[32m=======================backupstart=====================\033[0m" foriin$backdb do tables=`MysqL-u$user-p"$pass"-e"use$i;showtables;"|sed'1d'` forjin$tables do MysqLdump-u$user-p"$pass"-B--database$i--tables$j>/tmp/${i}-${j}-`date+%F.sql` [$?-eq0]&&echo-e"$i$j\033[32mok\033[0m"||echo"$i$j\033[31mfiled\033[0m" done done echo-e"\033[32m========================backupstop==========================\033[0m"
执行结果如下