Copy Code code as follows:
#!/bin/bash
#Mysql autobackup Shell
#
#
#----------------Set the MySQL login parameters
Dbuser=root
Dbpasswd=
Dbserver=localhost
dbname=fwserver2008
Dbopt=--opt
backupdir=/dbbackup/
#-----------------Set the FTP paramters, 0 No send to an FTP server,1 send to a FTP server
Copytoftp=1
ftpserver=172.16.25.2
Ftpuser=linux
ftppasswd=123456
#----------------Set the Backpfile paramters
Fileprefix=fwserver
Dumpfilename= $backupdir $fileprefix ' Date +%f_%h%m%s '. sql
newfile= $fileprefix-' date +%f_%h%m%s '. tar.gz
keepdays=10
#------------------Write the operater command to log file
Logfile=/var/log/_mysqlbackup.log
Logtmp=/var/log/_mybackup.tmp
#===============================================
if [!-D $backupdir]
Then
echo "$backupdir isn't exist, then make ..." >> $logfile
Mkdir-p $backupdir
Fi
echo "start====================================>" >> $logfile
echo "Beginning backup ' date +%f%T '" >> $logfile
echo "Delete $keepdays days ago Files ..." >> $logfile
Find $backupdir-name $fileprefix *-mtime + $keepdays-fls $logtmp-exec rm {};
echo "Deleted Backup file is:" >> $logfile
Cat $logtmp >> $logfile
echo "Delete old file success!" >> $logfile
If [f $backupdir $newfile]
Then
echo "$newfile backup exist, backup stop ..." >> $logfile
Else
If [-Z $dbpasswd]
Then
Mysqldump-u$dbuser-h$dbserver $dbopt $dbname > $dumpfilename
Else
Mysqldump-u$dbuser-p$dbpasswd-h$dbserver $dbopt $dbname > $dumpfilename
Fi
Tar czvf $backupdir $newfile $dumpfilename >> $logfile 2>&1
echo "$backupdir $newfile Backup success!" >> $logfile
RM-FR $dumpfilename
if [$copytoftp = 1]; Then
If [-Z $ftpserver];then
echo "ftp Server not set,copy to ftp Failed ..." >> $logfile
Exit 1
elif [-Z $ftpuser];then
echo "FTP user not set, Copy to Ftp Failed ..." >> $logfile
Exit 2
Elif [Z $ftppasswd]; Then
echo "ftp password not set, Copy to FTP Failed ..." >> $logfile
Exit 3
Else
echo "Start copy to FTP server ..." >> $logfile
Ftp-i-N <<end_ftp
Open $ftpserver
User $ftpuser $ftppasswd
LCD $backupdir
Hash
Prompt
Put $newfile
Close
Bye
End_ftp
Fi
Fi
echo "end=======================================" >> $logfile
Fi
# The end of the auto backup script