Linux back up Mysql database shell

Source: Internet
Author: User


Welcome to shoot bricks. The details are as follows: # MYSQL data File Path MYSQL_DATA_PATH = "/usr/local/mysql/data/" # Backup Directory MYSQL_DUMP_PATH = "***/DB/" # backup username MYSQL_ACCOUNT = "mysql_backup "# backup password MYSQL_PASSWORD = "mysql_backup" MYSQLDUMP_OPTS = "mysqldump-u $ MYSQL_ACCOUNT-p $ MYSQL_PASSWORD -- single-transaction" # The compression command bzip2-k retains the source file TAR_OPTS = "bzip2 "# back up function BackDB () {FULLPATH = "$1" # traverse the directory for dbName in $ (/bin/ls $ FULLPATH) do # check is da Tabase fileType = '/usr/bin/file $ FULLPATH $ dbName |/bin/awk' {FS = ": "} {printf $2}'' # The folder type is directory if ["directory" = $ fileType]; then # start dump if ["$ dbName" = "mysql"] \ | ["$ dbName" = "test"] \ | ["$ dbName" = "information_schema"] \ | ["$ dbName" = "cece_schema"]; then echo "-------------> $ dbName not need dump !! "Else echo $ dbName www.2cto.com dumpName = $ MYSQL_DUMP_PATH/" $ dbName "_" $ DATESTR "$ MYSQLDUMP_OPTS $ dbName>" $ dumpName ". SQL # compressing the backup file $ TAR_OPTS "$ BACKUP_NAME ". SQL fi else printf '% s is not database ######## \ n' $ dbName fi done} # Back up function BackDBTB () for each data table () {FULLPATH = "$1" # traverse the directory for fName in $ (/usr/bin/find $ FULLPATH-name "*. ibd ") do dbPath = 'echo" $ fName "|/bin/awk 'in in {FS =" '$ fullpath' "} {printf $2} ''# get database name dbName = 'echo" $ dbPath "|/bin/awk 'in in {FS ="/"} {printf $1}'' # get table name tbName = 'echo "$ dbPath" |/bin/awk 'in in {FS = "/"} {printf $2} ''# start dump if [" $ dbName" = "mysql"] \ | ["$ dbName" = "test"] \ | ["$ dbName" = "information_schema"] \ | ["$ dbName "=" performance_schema "]; then echo "-------------> $ dbName not need dump !! "Else echo $ dbName $ tbName dumpName = $ MYSQL_DUMP_PATH/" $ dbName "_" $ tbName "_" $ DATESTR "$ MYSQLDUMP_OPTS $ dbName $ tbName>" $ dumpName ". SQL # compressing the backup file $ TAR_OPTS "$ dumpName ". SQL fi done} By babaoqi

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.