mysqldump实现mysql备份小脚本
网上搜集并测试整理
#!/bin/bash #This is a ShellScript For Auto DB Backup #Powered by aspbiz Changed by Jeen #2004-09 Changed 2014-12 #Setting #设置数据库名,数据库登录名,密码,备份路径,日志路径,数据文件位置 DBName="test" DBUser="root" DBPasswd="root" BackupPath=/root/backup/mysql LogFile=/root/backup/mysql/bak_$DBName.log #Setting End NewFile=$BackupPath/"$DBName"_$(date +%y%m%d).tar.gz DumpFile="$DBName"_$(date +%y%m%d).sql OldFile=$BackupPath/"$DBName"_$(date +%y%m%d --date=‘7 days ago‘).tar.gz echo "-------------------------------------------" >> $LogFile echo $(date +"%y-%m-%d %H:%M:%S") >> $LogFile echo "--------------------------" >> $LogFile #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 echo "--------------------------" >> $LogFile if [ -f $NewFile ] ; then echo "[$NewFile]The Backup File is exists,Can‘t Backup!" >> $LogFile else cd $BackupPath if [ -z $DBPasswd ] ;then mysqldump -u $DBUser --opt $DBName > $DumpFile else mysqldump -u $DBUser -p$DBPasswd --opt $DBName > $DumpFile fi tar czvf $NewFile $DumpFile >> $LogFile 2>&1 echo "[$NewFile]Backup Success!" >> $LogFile rm -rf $DumpFile fi echo "-------------------------------------------" >> $LogFile
本文出自 “微所欲为——微生活” 博客,请务必保留此出处http://vsfor.blog.51cto.com/4165449/1586531
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。