##########MYSQL分库备份#######################################
#!/bin/bashmycmd= "mysql-uroot-pjinyan123" #定义了mysql命令MYDUMP = "mysqldump-uroot-pjinyan123" #定义了mysqldump命令DATABASE = ' $MYCMD-e ' show databases; "| Sed ' 1d ' |egrep-v "Mysql|performance_schema|information_schema" ' #获取到数据库名for database in $DATABASEdo $mydump-b $ Database|gzip >/server/backup/${database}_$ (Date +%f). Sql.gzdone
############MYSQL分表备份##########################################
#!/bin/bashmycmd= "mysql-uroot-pjinyan123" mydump= "mysqldump-uroot-pjinyan123" database= ' $MYCMD-e "Show Databases" | Sed ' 1d ' |egrep-v "Mysql|performance_schema|information_schema" ' for database in $DATABASEdo [!-d/server/backup/$ Database] && mkdir-p/server/backup/$database #创建以数据库名命名的目录TABLE = ' $MYCMD-e ' show tables from $database; "| Sed ' 1d ' #获取表名 for table in $TABLE do $MYDUMP $database $table |gzip >/server/backup/$database/${database}_${table} _$ (date +%f). sql.gz #for循环分表备份 Donedone
This article from "Yun-dimensional Life" blog, declined reproduced!
MySQL Sub-database sub-table backup