Write automated, fully-prepared shell scripts based on mysqldump

Source: Internet
Author: User

Write automated, fully-prepared shell scripts based on mysqldump

On-line MySQL database backup is divided into full standby and add-on, while Xtrabackup backup already supports incremental backup, but mysqldump does not support incremental backup, so we need to write a shell script for mysqldump from the full standby and Add.

The script asks us to make a fully-prepared strategy, then how to do incremental backups, automate the daily incremental backups, and execute the full-time every Sunday. Reduce disk pressure by removing the binaries after backup.

[[email protected] ~]# cat mysqlback.sh#!/bin/bash# #date =2017-11-7# #name =cml# #email =****** * * @qq. com# #title =mysqldump backup email= "******* @qq. com" Mysqlbak_dir=/usr/local/mysql/mydatamysqlbak _log=/usr/local/mysql/mydata/mysqlbak.logdate= ' date +%y%m%d ' time= ' date + "%y-%m %H:%M:%S" ' dumpbak= $DATE. sqlgzdumpbak= $DATE. sql.gzweek= ' date +%w ' cd  $mysqlbak _diruser=rootpasswd=redhatbin_log= ' Ls -tr mysql-bin.0*| head -1 ' bin_log_dir=/usr/local/mysql/mydata/bin_log if [  ! -f  $bin _log_dir ];then       mkdir$bin_log_dirfi  echo  "--------------------------$TIME-----------------------------" >>  $mysqlbak _log   if [  $WEEK  == 0 ];then     # #日期是星期天的时候执行 # #week =0 ~6       cd$mysqlbak_dir       /usr/ Local/mysql/bin/mysqldump-u$user -p$passwd --single-transaction -r --triggers -e --master-data -- flush-logs--all-databases >  $DUMPBAK  2>&1        echo "mysqldump backup success!!"  >>  $mysqlbak _log       tar-czvf  $GZDUMPBAK  $ dumpbak >>  $mysqlbak _log 2>&1       echo "$ gzdumpbak backup success!! "  >>  $mysqlbak _log#     if[ -f  $GZDUMPBAK  ];then#             echo "$GZDUMPBAK  backup success!!"  |mail -s  "Mysqldump backup" $EMAIL #     fi        rm-rf  $DUMPBAK        rm-rf  $bin _log## The above step is the full standby process else       cd$mysqlbak_dir&Nbsp;      /usr/local/mysql/bin/mysqladmin-u$user -p$passwd flush-logs        cp-p  $bin _log  $bin _log_dir        echo "copy  $bin _log to  $bin _log_dir"  >>  $mysqlbak _log        rm-rf  $bin _log       echo "backup  bin_log success!! "  >>  $mysqlbak _log#     echo "backup bin_log  $bin _log  Success! "  | mail -s  "Backupbin_log"   $EMAIL # #下面是增备过程fi

# #给脚本权限:

[[email protected] ~]# cd/usr/local/src/script/[[email protected] script]# Lsmysqlback.sh[[email protected] script]# chmod a+x mysqlback.sh


# #把它加入到crontab几乎任务里面:

[[email protected] script]# CRONTAB-E1 0 * * */usr/local/src/script/mysqlback.sh


This article is from the "First Legehappy51cto blog" blog, be sure to keep this source http://legehappy.blog.51cto.com/13251607/1980183

Write automated, fully-prepared shell scripts based on mysqldump

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.