#!/bin/bash
BackupPath=/data/backup/testbk #备份路径
Mysql_bk_dir=$BackupPath/mysql_bk_dir
LogFile=$BackupPath/backuplog
Passwd=admin #mysql密码
######################################
# define mysql variables
######################################
NewFile="$Mysql_bk_dir"/test$(date +%Y%m%d).tar.gz
DumpFile="$Mysql_bk_dir"/test$(date +%Y%m%d).sql
OldFile="$Mysql_bk_dir"/test$(date +%Y%m%d --date=‘5 days ago‘).tar.gz
######################################
#mysql backup proccess
######################################
echo "------------------------------------" >> $LogFile
echo $(date +"%Y-%m-%d %H:%M:%S") >> $LogFile
echo "------------------------------------" >> $LogFile
#Dlete Old File
if [ -f $OldFile ]
then
rm -f $OldFile >> $LogFile 2>&1
echo "[$OldFile] Delete Old File Success " >> $LogFile
else
echo "[$OldFile] Delete Old Backup File " >> $LogFile
fi
if [ -f $NewFile ]
then
echo "[$NewFile] The Backup File is exists,Can‘t Backup " >> $LogFile
else
cd $Mysql_bk_dir
/usr/local/mysql/bin/mysqldump -uroot -p$Passwd --opt --database test > $DumpFile
tar czf $NewFile ccv$(date +%Y%m%d).sql >> $LogFile 2>&1
echo "[$NewFile] Backup success ">> $LogFile
/bin/rm -rf $DumpFile
fi
本文出自 “目标:印度” 博客,请务必保留此出处http://shunzi115.blog.51cto.com/5184443/1826164
原文地址:http://shunzi115.blog.51cto.com/5184443/1826164