脚本学习之一---菜鸟级别入门---mysql简单分库备份【二】

在“脚本学习之一---菜鸟级别入门---mysql简单分库备份【一】”的是有一个弊端的,就是数据库的库名都是咱们手动写的。那么咱们有没有办法从数据库里面把库名取出来呢?答案是确定的以下
mysql

由于performance_schema和information_schema数据库5.5.32安装默认就有的,咱们备份的时候不要备份,所以咱们哟啊过滤掉。sql

[root@demo scripts]# mysql -uroot -poldboy123 -S /data/3306/mysql.sock -e"show databases;"数据库

+--------------------+vim

| Database           |ide

+--------------------+学习

| information_schema |spa

| binlog             |orm

| liu                |server

| mysql              |ip

| oldboy             |

| performance_schema |

| qq                 |

| riziwenjian        |

| shaopeng           |

| shujuku            |

| test               |

| uu                 |

| wodeshujk          |

| xindata            |

| zonglizhu          |

+--------------------+

[root@demo scripts]# mysql -uroot -poldboy123 -S /data/3306/mysql.sock -e"show databases"

+--------------------+

| Database           |

+--------------------+

| information_schema |

| binlog             |

| liu                |

| mysql              |

| oldboy             |

| performance_schema |

| qq                 |

| riziwenjian        |

| shaopeng           |

| shujuku            |

| test               |

| uu                 |

| wodeshujk          |

| xindata            |

| zonglizhu          |

+--------------------+

[root@demo scripts]# mysql -uroot -poldboy123 -S /data/3306/mysql.sock -e"show databases"|sed '1,2d'

binlog

liu

mysql

oldboy

performance_schema

qq

riziwenjian

shaopeng

shujuku

test

uu

wodeshujk

xindata

zonglizhu

[root@demo scripts]# mysql -uroot -poldboy123 -S /data/3306/mysql.sock -e"show databases"|sed '1,2d'|egrep -v "schema"

binlog

liu

mysql

oldboy

qq

riziwenjian

shaopeng

shujuku

test

uu

wodeshujk

xindata

zonglizhu

[root@demo scripts]# vim fenku_bak_auto.sh

#!/bin/sh

for dbname in `mysql -uroot -poldboy123 -S /data/3306/mysql.sock -e"show databases"|sed '1,2d'|egrep -v "schema"`

do

       mysqldump -uroot -poldboy123 --skip-lock-tables -S /data/3306/mysql.sock -F -B ${dbname}|gzip >/server/backup/${dbname}_$(da

te +%F).sql.gz

done

[root@demo scripts]# sh fenku_bak_auto.sh

-- Warning: Skipping the data of table mysql.event. Specify the --events option explicitly.

[root@demo scripts]# ll /server/backup/  

总用量 192

-rw-r--r-- 1 root root    511 1月  17 20:00 binlog_2014-01-17.sql.gz

-rw-r--r-- 1 root root    508 1月  17 20:00 liu_2014-01-17.sql.gz

-rw-r--r-- 1 root root 144320 1月  17 20:00 mysql_2014-01-17.sql.gz

-rw-r--r-- 1 root root    938 1月  17 20:00 oldboy_2014-01-17.sql.gz

-rw-r--r-- 1 root root    509 1月  17 20:00 qq_2014-01-17.sql.gz

-rw-r--r-- 1 root root    517 1月  17 20:00 riziwenjian_2014-01-17.sql.gz

-rw-r--r-- 1 root root    513 1月  17 20:00 shaopeng_2014-01-17.sql.gz

-rw-r--r-- 1 root root    513 1月  17 20:00 shujuku_2014-01-17.sql.gz

-rw-r--r-- 1 root root    511 1月  17 20:00 test_2014-01-17.sql.gz

-rw-r--r-- 1 root root    509 1月  17 20:00 uu_2014-01-17.sql.gz

-rw-r--r-- 1 root root    515 1月  17 20:00 wodeshujk_2014-01-17.sql.gz

-rw-r--r-- 1 root root    511 1月  17 20:00 xindata_2014-01-17.sql.gz

-rw-r--r-- 1 root root    515 1月  17 20:00 zonglizhu_2014-01-17.sql.gz

-- Warning: Skipping the data of table mysql.event. Specify the --events option explicitly.备份mysql库,就会有这个。解决方法:

[root@demo scripts]# mysql -uroot -poldboy123 -S /data/3306/mysql.sock -e"show databases"|sed '1,2d'|egrep -v "mysql|schema"

binlog

liu

oldboy

qq

riziwenjian

shaopeng

shujuku

test

uu

wodeshujk

xindata

zonglizhu

相关文章
相关标签/搜索