database MySQL Automatic library sub-table backup script
When we are in the company of database backup, the project is more, often do database and table additions, then we
You want the system script to automatically query the library and table structure in the database, and then perform regular periodic copies of the database and tables automatically,
So how do we do this, and we look at the following script:
VI mysql_backup.sh
#!/bin/sh
#backup Tiandao BBS edoing
#coding Tonye.li
Myuser=root
Mypass=meidi
Socket=/data/3306/mysql.sock
mycmd= "Mysql-u$myuser-p$mypass-s $SOCKET"
mydump= "Mysqldump-u$myuser-p$mypass-s $SOCKET"
For database in ' $MYDUMP-e ' show databases; "| Sed ' 1,2d ' |egrep-v "Mysql|schema"
Do
Mkdir-p/server/backup/${database}
For table in ' $MYCMD-e ' show tables from $databases; "| Sed ' 1d '
Do
$MYDUMP $database $table |gzip >/server/backup/${database}_${table}$ (date + $F). sql.gz
Done
Done
This script filters out two databases (Mysql,schema) from the system, and the script may need to be changed depending on the environment.
Change, hope everyone learn from each other, thank you!
This article is from "Lao Li _tony" blog, please be sure to keep this source http://tonyping.blog.51cto.com/7725720/1682991
Database MySQL Automatic library sub-table backup script