#! 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