.tgz
DBName=mysql
DBUser=root
DBPasswd=
BackupPath=/root/
LogFile=/root/db.log
DBPath=/var/lib/mysql/
#BackupMethod=mysqldump
#BackupMethod=mysqlhotcopy
#BackupMethod=tar
#SettingEnd
NewFile='$BackupPath'db$(date+%y%m%d).tgz
DumpFile='$BackupPath'db$(date+%y%m%d)
OldFile='$BackupPath'db$(date+%y%m%d--date='5daysago').tgz
echo'-------------------------------------------'$LogFile
echo$(date+'%y-%m-%d%H:%M:%S')$LogFile
echo'--------------------------'$LogFile
#DeleteOldFile
if[-f$OldFile]
then
rm-f$OldFile$LogFile21
echo'[$OldFile]DeleteOldFileSuccess!'$LogFile
else
echo'[$OldFile]NoOldBackupFile!'$LogFile
fi
if[-f$NewFile]
then
echo'[$NewFile]TheBackupFileisexists,Can'tBackup!'$LogFile
else
case$BackupMethodin
mysqldump)
if[-z$DBPasswd]
then
mysqldump-u$DBUser--opt$DBName$DumpFile
else
mysqldump-u$DBUser-p$DBPasswd--opt$DBName$DumpFile
fi
tarczvf$NewFile$DumpFile$LogFile21
echo'[$NewFile]BackupSuccess!'$LogFile
rm-rf$DumpFile
;
mysqlhotcopy)
rm-rf$DumpFile
mkdir$DumpFile
if[-z$DBPasswd]
then
mysqlhotcopy-u$DBUser$DBName$DumpFile$LogFile21
else
mysqlhotcopy-u$DBUser-p$DBPasswd$DBName$DumpFile$LogFile21
fi
tarczvf$NewFile$DumpFile$LogFile21
echo'[$NewFile]BackupSuccess!'$LogFile
rm-rf$DumpFile
;
*)
/etc/init.d/mysqldstop/dev/null21
tarczvf$NewFile$DBPath$DBName$LogFile21
/etc/init.d/mysqldstart/dev/null21
echo'[$NewFile]BackupSuccess!'$LogFile
;
esac
fi
echo'-------------------------------------------'$LogFile
MySQL数据库的自动备份在这里为大家介绍。我们会按照上面文章中讲解的步骤和方法来做MySQL数据库的自动备份。相信你能很好的完成MySQL数据库的自动备份。