#!/bin/bash
#This is a ShellScript For Auto DB Backup
#Setting
DBName=mysqlqqq
DBUser=root
DBPasswd=mima
BackupPath=/home/backup
LogFile=/home/backup/log/bk_bugtracker.log
NewFile="$BackupPath/$DBName"_db_$(date +%Y_%m_%d).tgz
DumpFile="$BackupPath/$DBName"_db_$(date +%Y_%m_%d).sql
OldFile="$BackupPath/$DBName"_db_$(date +%Y_%m_%d --date='3 days ago').tgz
#Delete Old File
if [ -f $OldFile ]
then
rm -f $OldFile>> $LogFile 2>&1
echo "[$OldFile] Delete Old File Success!">> $LogFile
else
echo "[$OldFile] No Old Backup File!">> $LogFile
fi
#Create new backupfile
if [ -f $NewFile ]
then
echo "[$NewFile] The Backup File is exists,Can't Backup!">> $LogFile
else
mysqldump -u $DBUser -p$DBPasswd $DBName> $DumpFile
tar czvf $NewFile $DumpFile>> $LogFile 2>&1
echo "[$NewFile] Backup Success!">> $LogFile
rm -rf $DumpFile
fi
echo "-------------------------------------------">> $LogFile
echo>> $LogFile
echo>> $LogFile作者: pcuer 时间: 2011-06-01 16:29 回复 1#狼毫吴钩