MySQl Backup recovery policy (full + Incremental backup policy)

Source: Internet
Author: User
Tags mysql backup
#! Binsh # Name: mysqlFullBackup. sh # PS: MySQLDataBaseFullBackup. # Writeby: I. stone # LastModify: 2007-11-17 # Usemysqldump -- helpgetmoredetail. # define variables. Modify the variables as needed # define the script directory scriptsDir 'pwd' # define the database directory my

#! /Bin/sh # Name: mysqlFullBackup. sh # PS: MySQL DataBase Full Backup. # Write by: I. stone # Last Modify: 2007-11-17 # Use mysqldump -- help get more detail. # define variables. Modify the variables as needed # define the script directory scriptsDir = 'pwd' # define the database directory my

#! /Bin/sh


# Name: mysqlFullBackup. sh


# PS: MySQL DataBase Full Backup.


# Write by: I. Stone


# Last Modify: 2007-11-17


#


# Use mysqldump -- help get more detail.


#


# Define variables. Modify the variables as needed


# Define the script directory


ScriptsDir = 'pwd'


# Define the database directory


MysqlDir =/usr/local/mysql


# Define the username and password used to back up the database


User = root


User Pwd = 111111


# Define the Backup Directory


DataBackupDir =/tmp/mysqlbackup


# Define the mail body File


EMailFile = $ dataBackupDir/email.txt


# Define email addresses


EMail = alter@somode.com


# Define backup log files


LogFile = $ dataBackupDir/mysqlbackup. log


DATE = 'date-I'



Echo ""> $ eMailFile


Echo $ (date + "% y-% m-% d % H: % M: % S" >>$ eMailFile


Cd $ dataBackupDir


# Define the backup file name


DumpFile = mysql _ $ DATE. SQL


Gzdumpfile1_mysql_1_date. SQL .tar.gz



# Use mysqldump to back up the database. set parameters as needed


$ MysqlDir/bin/mysqldump-u $ user-p $ userPWD \


-- Opt -- default-character-set = utf8 -- extended-insert = false \


-- Triggers-R -- hex-blob -- all-databases \


-- Flush-logs -- delete-master-logs \


-- Delete-master-logs \


-X> $ dumpFile



# Compressing backup files


If [[$? = 0]; then



Tar czf $ GZDumpFile $ dumpFile >>$ eMailFile 2> & 1



Echo "BackupFileNameGZDumpFile"> $ eMailFile



Echo "DataBase Backup Success! ">>$ EMailFile



Rm-f $ dumpFile



# Delete daily backup files.



Cd $ dataBackupDir/daily



Rm-f *



# Delete old backup files (mtime> 2 ).



$ ScriptsDir/rmBackup. sh



# If you do not need to transmit the backup to the backup server or the backup server is Windows, comment out the lines marked green


# Move Backup Files To Backup Server.


# Suitable for Linux (MySQL Server) to Linux (Backup Server)



$ ScriptsDir/rsyncBackup. sh



If ((! $? ); Then


Echo "Move Backup Files To Backup Server Success! ">>$ EMailFile


Else


Echo "Move Backup Files To Backup Server Fail! ">>$ EMailFile


Fi



Else



Echo "DataBase Backup Fail! ">>$ EmailFile


Fi


# Write a log file


Echo "--------------------------------------------------------"> $ logFile


Cat $ eMailFile> $ logFile


# Send email notification


Cat $ eMailFile | mail-s "MySQL Backup" $ eMail

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.