MySQL logical backup 2 kinds of scenarios

Source: Internet
Author: User

MySQL logical backup scheme:

  1. Logical backup for DB (in production environment due to small amount of data).


    mysql_backup.sh

    #!/bin/bash

    Date= ' Date +%f-%h-%m '

    Mkdir/opt/backup/${date}-P

    Usesize= ' du-s/opt/mysql |cut-f 1 '

    biaozhun= ' df/opt/|awk ' end{print ("' $usesize '" +$3)/$2*100+0.5} ' |cut-d.-f1 '

    ip= ' grep ipaddr/etc/sysconfig/network-scripts/ifcfg-eth1 |cut-d =-f2 '

    If [$biaozhun-ge 85]

    Then

    Mysqldump--user=root--flush-privileges--single-transaction--master-data=1--flush-logs--triggers--routines-- Events--hex-blob-b HBB Meta_dm_config >/opt/backup/${date}/mysqlall${date}.sql


    echo "$ip disk is big,plase check" |sendmail-t "DF" [email protected]

    Echo 1

    Else


    Mysqldump--user=root--flush-privileges--single-transaction--master-data=1-flush-logs--triggers--routines-- Events--hex-blob-b HBB Meta_dm_config >/opt/backup/${date}/mysqlall${date}.sql

    Echo 2

    Fi

  2. A logical backup of a single table.


    mysql_backup_per_table.sh

    #!/bin/bash

    Date= ' Date +%f '

    Mkdir/opt/backup/${date}/hbb-p

    MYSQL-E "Flush table with read lock;"

    #mysql-E "use hbb;show tables;" |grep-v Table >tables_list.txt

    For table_name in ' MYSQL-E ' use hbb;show tables; "|grep-v table"

    Do

    Mysqldump--user=root--flush-privileges--single-transaction--master-data=1--flush-logs--triggers--routines-- Events--hex-blob MySQL >/opt/backup/${date}/mysql.sql

    Mysqldump--user=root--flush-privileges--single-transaction--master-data=1--flush-logs--triggers--routines-- Events--hex-blob HBB $table _name >/opt/backup/${date}/hbb/${table_name}.sql

    Done

    MYSQL-E "Unlock tables;"

MySQL logical backup 2 kinds of scenarios

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.