Collect and test and organize online
#!/bin/bash #This is a ShellScript For Auto DB Backup #Powered by aspbiz Changed by Jeen#2004-09 Changed 2014-12#Setting #设置数据库名, Database login name, password, backup path, log path, data file location dbname= "test" dbuser= "root" dbpasswd= "root" backuppath=/root/backup/mysqllogfile=/root/ backup/mysql/bak_$dbname.log#setting end newfile= $BackupPath/"$DBName" _$ (date +%y%m%d). tar.gz dumpfile= "$DBName" _$ (date +%y%m%d). sqloldfile= $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 fiecho ------- ------------------------------------" >> $LogFile
This article is from the "micro-desire for-micro-life" blog, please be sure to keep this source http://vsfor.blog.51cto.com/4165449/1586531
mysqldump implementing a MySQL Backup small script