#!/bin/bash 
BakDir=/backup/mysql/full 
LogFile=/var/log/mysql-dbispconfig-backup.log 
DATE=`date +%Y-%m-%d` 
DumpFile=$DATE.sql 
GZDumpFile=$DATE.sql.tar.gz 
backup_error=/backup/mysql/backup_error 
compress_error=/backup/mysql/compress_error 
email1="daigh@qian-gao.com" 
email2="qubq@qian-gao.com" 
echo -e "\n" >>$LogFile 
echo "===========&gt;  $DATE   <=============     " >&gt;$LogFile 
echo "$(date +"%H:%M:%S") begin back  DNS database "&gt;&gt;$LogFile 
cd $BakDir 
mysqldump -u root  -pqian-gao.com dabispconfig --default-character-set=utf8 &gt;$DumpFile 2&gt;/backup/mysql/backup_error 
if [ $? == 0 ] 
then 
      echo "at $(date +"%H:%M:%S")  the backup Done,now begin compress the sql file" &gt;&gt;$LogFile 
      tar czvf $GZDumpFile $DumpFile 2&gt;/backup/mysql/compress_error 
        if  [ $? == 0 ] 
        then 
                 echo "at $(date +"%H:%M:%S") the $GZDumpFile Backup Success!" &gt;&gt;$LogFile 
                 echo "finish!" &gt;&gt;$LogFile 
                 rm -f $DumpFile 
        else 
                 mail -s "compress_error" $email1 &lt;$compress_error 
                 mail -s "compress_error" $email2 &lt;$compress_error
        fi
else 
      mail -s "backup_error" $email1 &lt;$backup_error 
      mail -s "backup_error" $email2 &lt;$backup_error 
fi