mysql linux 备份脚本

  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

mysql linux 备份脚本

上一篇:SQL存储过程笔记


下一篇:浅析SQLite数据库开发常用管理工具