MySQL backup script, one-day full-time backup, three incremental backups

Source: Internet
Author: User
Tags mysql backup

Online MySQL backup of a small business

Full-scale backup

#!/bin/Bash#crete by HEXM at .-Ten- Geneva#scripte name:full_backup.SH#descriptioni: MySQL full backup. Oneday at a Time.# Time InfoDate=`Date+%y%m%d ' #time_now1=`Date+%y%m%d-%h:%m:%S ' #dir InfoBackup_dir="/app/dbbackup/full_backup/"Today_dir="/app/dbbackup/full_backup/${date}"LOG=/app/dbbackup/logs/dumpfull_${Date}.txtif[!-D"${backup_dir}"]; Then  mkdir-P"${backup_dir}"fiif[!-D"${today_dir}"]; Then  mkdir-P"${today_dir}"fiEcho`Date+%y%m%d%h%m%s ' > ${today_dir}/ Time. txt# Loop Databases Array Time_now1=`Date+%y%m%d-%h:%m:%S 'Echo "${time_now1} start to full backup">>${log} forDbinch'/usr/local/mysql/bin/mysql-uroot-pwoyoudabaitu-e'Show Databases'|grep-ev"mysql|test|performance_schema|information_schema| Database"` Do# BACKUP database generates SQL file #/bin/ Nice-N +/usr/local/mysql/bin/mysqldump-uroot-pwoyoudabaitu--database $db > ${today_dir}${db}-$ (Date+%y%m%d). SQL/bin/ Nice-N + //Usr/local/mysql/bin/mysqldump-uroot-pwoyoudabaitu--database--flush-privileges--master-data-- Single-transaction--opt $db > ${today_dir}/${db}-${date}.sql DoneTime_now2=`Date+%y%m%d-%h:%m:%S 'Echo "${time_now2} full backup successfull">>$LOG #get PositionSleep 2if[-F"${today_dir}/db_179_act-${date}.sql"]; Then  sed-N'22p'${today_dir}/db_179_act-${Date}.sql |awk-F"[! ]" '{print $4,$10}'> $today _dir/positionEcho "${time_now2} get position ok!">>$LOGElsetime_now3=`Date+%y%m%d-%h:%m:%S 'Echo "${time_now3} get position faild">>$LOG # $SEND _msgfi#remove1Days ago Backup.Find$BACKUP _dir-mtime +7-delete#Echo "remove 1 days ago Full backup!">> $LOG

Incremental backup

#!/bin/Bash#crete by HEXM at .-Ten-Geneva#scripte name:increment_backup.SH#descriptioni: MySQL increment backup.6Hours at a Time.# Time InfoDate=`Date+%y%m%d ' Time_hour=`Date+%y%m%d%H ' #time_now1=`Date+%y%m%d-%h:%m:%S ' #dir InfoBackup_dir=/app/dbbackup/increment_backup/LOG=/app/dbbackup/logs/dumpincr_${Date}.txt#time_dir=/app/dbbackup/full_backup/${time_hour}if[!-D"${backup_dir}"]; Then  mkdir-P"${backup_dir}"fiTime_now1=`Date+%y%m%d-%h:%m:%S 'Echo "${time_now1} start to increment backup">>${LOG}CD/app/Mysql.binTarCF ${time_hour}_mysql_bin.Tar. GZ *waitMV/app/mysql.bin/*. tar.gz ${backup_dir}cdls ${backup_dir}/${time_hour}_mysql_bin.tar.gz &>/dev/nullif [$?-eq 0];then Time_n ow2= ' Date +%y%m%d-%h:%m:%s ' echo ' ${time_now2} increment backup successfull ' >> $LOGelse echo ' ${time_now2} increm  ENT backup Faild ">> $LOG #SEND_MSGfi #remove 1 days ago backup. #find $BACKUP _dir-mtime +7-deletefind $BACKUP _dir -type f-name "*.tar.gz"-mtime +7-delete#echo "Remove 1 days ago Increment backup!" >> $LOG

Scheduled Tasks

xx  * * * * */bin/bash/app/bin/full_backup. sh & &>/dev/null * * * */bin/bash/app/bin/increment_backup. sh & &>/dev/null * * * */bin/bash/app/bin/increment_backup. sh & &>/dev/nullxx * * */bin/bash/app/bin/increment_backup . sh & &>/dev/null

MySQL backup script to perform a full backup, three incremental backups, one day at a time

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.