#!/bin/bash
Dpath= "/mysql_backup" mydays= "7" username= "root" mysql_pwd= "Redhat" xmysql= "/application/mysql/bin/mysql-u$ USERNAME-P${MYSQL_PWD} "xmysqldump="/application/mysql/bin/mysqldump-u$username-p${mysql_pwd} "today= ' Date +%Y%m% d ' old_backup_dir= ' date-d "-${mydays} Day" +%y%m%d '
If [-D $old _backup_dir];then rm-rf $old _backup_dirfi
if [!-D $today]; Then mkdir-p $dpath/$today cp/etc/my.cnf $dpath/$todayfi
$xmysql-E "show databases;" | Grep-ve "(Database|_schema)" > $dpath/db_list$xmysql-e "flush tables with read lock;"
While Read Dbnamedo
if [!-D $dpath/$today/$dbname];then mkdir-p $dpath/$today/$dbname fi
####################### #echo $dbname $xmysql-E "use $dbname; Show tables; "| Grep-ve "(tables_in|general_log|slow_log)" > $dpath/table_list
While read tablename do #echo "Echo $tablename" $xmysqldump $dbname $tablename-R--events--triggers > $dpath/$ today/$dbname/$tablename. SQL Done < $dpath/table_list###################### #done < $dpath/db_list
RM-RF $dpath/DB_LISTRM-RF $dpath/table_list
ls-al/application/mysql/data/mysql-bin* | Grep-v Mysql-bin.index | Tail-1 | awk ' {print $5,$9} ' | Awk-f '/' {print $1,$5} ' >/mysql_backup/$today/position.txt
$xmysql-E "unlock tables;"
From for notes (Wiz)
MySQL master-slave cluster scheduled backup script