MySQL backup script

Source: Internet
Author: User
Tags mysql backup

On the Internet to read a few scripts based on the Internet slightly modified under, slightly more prepared point, is missing something

#!/bin/bash# Large Backup number backup_max_files=20# database backup directory working_dir=$ (dirname "$") Export working_dir=$ (cd-p "$WORKING _dir"/ >/dev/null; PWD) #数据库IP地址, account number, password db_host= "XXXXXXX" db_user= "XXXXXX" db_password= "XXXXXXX" #需要备份的数据库Databases = ("MySQL" "Zabbix ") #==========echo" ########## #Bash Shell MySql Databases Backup tools! " #定义变量 = Current date date_time=$ (date +%f) #定义备份文件前缀BackData_File =zhang "_${date_time}" CD $WORKING _dirmkdir $BackData _file# Statistics need to back up the number of databases Count=0while ["X${databases[count]}"! = "x"]do count=$ ((count + 1)) echo "Databases= $count" Doneech o "[+] ${count} The database is on to being backed up ' for Databases in ${databases[@]}do echo ' [+] mysql-backing up: ${ Databases} "Echo-n" MySql Backup Start: "Echo $ (date +"%y-%m-%d%h:%m:%s ") #使用Mysqdump工具进行逻辑备份 (fully prepared) and send successfully using mail script failed Reminder if $ (mysqldump-h${db_host}-u${db_user}-p${db_password}--single-transaction--flush-logs mysql > ${BackData_ FILE}/${DATABASES}.SQL) then echo "Success ok!: Mysql database backup Success!"       # python/root/jiaoben/mail.py "[email protected]" "${databases} Database Backup succeeded" "${databases}> database backup succeeded" else        echo "Error no!: Failure of MySQL database backup!" #python/root/jiaoben/mail.py "[email protected]" "${databases} Database Backup Failed" "${databases}> database backup failed see fi echo- N "Backup success:" Echo $ (date + "%y-%m-%d%h:%m:%s") Doneechoecho "[+] packaging and compressing folders with Tar .... "#使用tar命令打包并压缩生成的数据库文件cd $WORKING _DIRTAR-CV ${backdata_file} | bzip2 > ${backdata_file}.tar.bz2 && rm-rf ${backdata_file}

MySQL 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.