首页 > 代码库 > mysqldump实现mysql备份小脚本
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
mysqldump实现mysql备份小脚本
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。