MySQL master-slave cluster scheduled backup script

Source: Internet
Author: User

#!/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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.