This article from http://www.xuliangwei.com/xubusi/252.html
Free video commentary See http://edu.51cto.com/course/course_id-5064.html
Enterprise Shell actual Combat-mysql sub-database sub-table backup
Today is the last day of the 2015, everyone is happy across the year, and I still in the bitter force of hehe--omitted
Here the content from the old boy education Oldboy and the old boy 26 Wang continued wonderful sharing organized and to express thanks, special finishing this blog share to everyone!
Project Contact author Qq:572891887 can also join the architect Exchange Group: 471443208 for communication
[Email protected] scripts]# cat/server/scripts/store_backup.sh #脚本详细内容
#!/bin/sh
Myuser=root
Mypass=xuliangwei
Socket=/data/3306/mysql.sock
mylogin= "Mysql-u$myuser-p$mypass-s $SOCKET"
mydump= "Mysqldump-u$myuser-p$mypass-s$socket-b"
Database= "$ ($MYLOGIN-E" show databases; "| Egrep-vi "Data|_schema|mysql") "
For dbname in $DATABASE
Do
mydir=/server/backup/$dbname
[!-D $MYDIR] && mkdir-p $MYDIR
$MYDUMP $dbname |gzip > $MYDIR/${dbname}_$ (Date +%f). sql.gz
Done
[Email protected]/]# tree/server/backup/#执行后的结果
/server/backup/
├──oldboy26
│├──oldboy26_2015-12-29.sql.gz
│├──oldboy26_2015-12-30.sql.gz
│└──oldboy26_2015-12-31.sql.gz
├──oldboy_xuliangwei26
│├──oldboy_xuliangwei26_2015-12-29.sql.gz
│├──oldboy_xuliangwei26_2015-12-30.sql.gz
│└──oldboy_xuliangwei26_2015-12-31.sql.gz
└──xuliangwei26
├──xuliangwei26_2015-12-29.sql.gz
├──xuliangwei26_2015-12-30.sql.gz
└──
Xuliangwei26_2015-12-31.sql.gz
3 Directories, 9 files
Shell-mysql Library Sub-table backup script
[email protected] scripts]# cat mysql_table.sh #脚本详细内容
#!/bin/sh
User=root
Passwd=xuliangwei
Socket=/data/3306/mysql.sock
Mylogin= "Mysql-u$user-p$passwd-s$socket"
mydump= "Mysqldump-u$user-p$passwd-s$socket"
Datebase= "$ ($MYLOGIN-E" show databases; "| Egrep-vi "Data|_schema|mysql") "
For dbname in $DATEBASE
Do
Table= "$ ($MYLOGIN-E" use $dbname; show tables; "| Sed ' 1d ') "
For Tname in $TABLE
Do
mydir=/server/backup/$dbname/${dbname}_$ (date +%f)
[!-D $MYDIR] && mkdir-p $MYDIR
$MYDUMP $dbname $tname |gzip > $MYDIR/${dbname}_${tname}_$ (Date +%f). sql.gz
Done
Done
[Email protected] scripts]# tree/server/backup/#查看执行后的结果
/server/backup/
├──oldboy26
│├──oldboy26_2015-12-30
││├──oldboy26_oldboy_test_2015-12-30.sql.gz
││└──oldboy26_oldboy_test2_2015-12-30.sql.gz
│└──oldboy26_2015-12-31
│├──oldboy26_oldboy_test_2015-12-31.sql.gz
│└──oldboy26_oldboy_test2_2015-12-31.sql.gz
├──oldboy_xuliangwei26
│├──oldboy_xuliangwei26_2015-12-30
││├──oldboy_xuliangwei26_cloudstack_2015-12-30.sql.gz
││├──oldboy_xuliangwei26_dashborad_2015-12-30.sql.gz
││└──oldboy_xuliangwei26_student_2015-12-30.sql.gz
│└──oldboy_xuliangwei26_2015-12-31
│├──oldboy_xuliangwei26_cloudstack_2015-12-31.sql.gz
│├──oldboy_xuliangwei26_dashborad_2015-12-31.sql.gz
│└──oldboy_xuliangwei26_student_2015-12-31.sql.gz
└──xuliangwei26
├──xuliangwei26_2015-12-30
│├──xuliangwei26_openstack_2015-12-30.sql.gz
│├──xuliangwei26_saltstack_2015-12-30.sql.gz
│├──xuliangwei26_server_2015-12-30.sql.gz
│└──xuliangwei26_zabbix_2015-12-30.sql.gz
└──xuliangwei26_2015-12-31
├──xuliangwei26_openstack_2015-12-31.sql.gz
├──xuliangwei26_saltstack_2015-12-31.sql.gz
├──xuliangwei26_server_2015-12-31.sql.gz
└──xuliangwei26_zabbix_2015-12-31.sql.gz
9 Directories, files
Project Contact author Qq:572891887 can also join the architect Exchange Group: 471443208 for communication
This article is from the "Old Boys Linux Training" blog, make sure to keep this source http://oldboy.blog.51cto.com/2561410/1731109
(turn) Enterprise Shell actual combat-mysql sub-database table backup script