mysql linux 备份脚本

时间:2014-05-19 10:58:24   收藏:0   阅读:360
  1. #!/bin/sh
  2. # mysql data backup script
  3. #
  4. # use mysqldump --help,get more detail.
  5. #
  6. BakDir=/root/back/mysql
  7. LogFile=/root/back/mysql/mysqlbak.log
  8. DATE=`date +%Y%m%d%H%M%S`
  9. echo " " >> $LogFile
  10. echo " " >> $LogFile
  11. echo "-------------------------------------------" >> $LogFile
  12. echo $(date +"%y-%m-%d %H:%M:%S") >> $LogFile
  13. echo "--------------------------" >> $LogFile
  14. cd $BakDir
  15. DumpFile=$DATE.sql
  16. GZDumpFile=$DATE.sql.tar.gz
  17. /usr/local/bin/mysqldump -u user -pname  --database -h 127.0.0.1 db> $DumpFile
  18. echo "Dump Done" >> $LogFile
  19. tar czvf $GZDumpFile $DumpFile >> $LogFile 2>&1
  20. echo "[$GZDumpFile]Backup Success!" >> $LogFile
  21. rm -f $DumpFile
  22. #cd $BakDir/daily
  23. cd $BakDir   
  24. echo "Backup Done!"
  25. echo "please Check $BakDir Directory!"
  26. echo "copy it to your local disk or ftp to somewhere !!!"
  27. find $BakDir -ctime +30 -exec rm {} \;
  28. echo "delete file over 30 days"

其中user,name和db请根据自己的情况修改

mysql linux 备份脚本,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!