shell 代码如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
[root@localhost /]
# cat back.sh
#!/bin/bash
/etc/init
.d
/mysqld
status &>
/dev/null
[ $? -
ne
0 ] &&
echo
"请开启 mysqld 服务"
&&
exit
0
user=root
pass=
"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
$backdb
do
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"
done
done
echo
-e
"\033[32m========================backup stop==========================\033[0m"
|
执行结果如下
本文转自 大雪儿 51CTO博客,原文链接:http://blog.51cto.com/dingxue/1974745,如需转载请自行联系原作者