MySQL database sub-Library backup script
version 1
For dbname in ' mysql-uroot-poldboy123-e ' show databases; "|grep-evi" database|informa|perfor "'
Do
mysqldump-uroot-poldboy123--events-b $dbname |gzip >/opt/bak/${dbname}_bak.sql.gz
Done
version 2
#!/bin/bash
Myuser=root
Mypass=oldboy123
mycmd= "Mysql-u$myuser-p$mypass--default-character-set=utf8"
mydump= "Mysqldump-u$myuser-p$mypass--default-character-set=utf8--events-b"
Dblist= ' $MYCMD-e "show databases; | Grep-evi "Database|informa|perfor"
[!-d/opt/bak] && mkdir-p/opt/bak
For dbname in $DBLIST
Do
$MYDUMP $dbname |gzip >/opt/bak/${dbname}_bak.sql.gz
Done
Multi-instance sub-library backup
#!/bin/bash
Myuser=root
Mypass=oldboy123
Socket=/data/3306/mysql.sock
mycmd= "Mysql-u$myuser-p$mypass--default-character-set=utf8-s $SOCKET"
mydump= "Mysqldump-u$myuser-p$mypass--default-character-set=utf8-s $SOCKET--events-b"
Dblist= ' $MYCMD-e "show databases; | Grep-evi "Database|informa|perfor"
[!-d/opt/bak] && mkdir-p/opt/bak
For dbname in $DBLIST
Do
$MYDUMP $dbname |gzip >/opt/bak/${dbname}_bak.sql.gz
Done
Sample script:
#!/bin/bash
Bakpath=/server/backup
Myuser=root
Mypass=oldboy123
Socket=/data/3306/mysql.sock
mycmd= "Mysql-u$myuser-p$mypass-s $SOCKET"
mydump= "Mysqldump-u$myuser-p$mypass-s $SOCKET-X-b-f-R"
[!-D $BAKPATH] && mkdir-p $BAKPATH
Dblist= ' $MYCMD-e "show databases; | Sed 1d | Egrep-v "_schema|mysql"
For dbname in $DBLIST
Do
$MYDUMP $dbname |gzip >/server/backup/${dbname}_$ (date +%f). sql.gz
Done
MySQL Database sub-Library backup script