免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 959 | 回复: 0
打印 上一主题 下一主题

mysql 全备脚本 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-23 02:29 |只看该作者 |倒序浏览

 

  1. #!/bin/sh

  2. BakDir=/data/dbbak/121.14.23.207/full

  3. LogFile=/data/dbbak/121.14.23.207/full/db_backup.log

  4. DATE=`date +'%Y%m%d_%H_%M'`

  5. LOGDATE=`date +'#%Y-%m-%d %H:%M:%S'`

  6. #DumpFile=dbbackup_$HOSTNAME_$DATE.sql

  7. #GZDumpFile=dbbackup_$HOSTNAME_$DATE.sql.tar.gz

  8. conffile=/data/dbbak/scripts/bak.ini

  9. #DB define

  10. DBUSER=$(awk -F "=" -v var=DBUSER '$1==var"" {print $2}' $conffile)

  11. DBPWD=$(awk -F "=" -v var=DBPWD '$1==var"" {print $2}' $conffile)

  12. MYSQLDIR=$(awk -F "=" -v var=MYSQLDIR '$1==var"" {print $2}' $conffile)

  13. DBNAME=$(awk -F "=" -v var=DBNAME '$1==var"" {print $2}' $conffile)

  14. #DumpFile=bak_$DBNAME_$DATE.sql

  15. #ftp

  16. ftpuser=$(awk -F "=" -v var=FTPUSER '$1==var"" {print $2}' $conffile)

  17. ftppwd=$(awk -F "=" -v var=FTPPWD '$1==var"" {print $2}' $conffile)

  18. ftpserver=$(awk -F "=" -v var=FTPSERVER '$1==var"" {print $2}' $conffile)

  19. FTP_DIR=$(awk -F "=" -v var=FTPDIR '$1==var"" {print $2}' $conffile)

  20. #ssh

  21. sshuser=$(awk -F "=" -v var=SSHUSER '$1==var"" {print $2}' $conffile)

  22. sship=$(awk -F "=" -v var=SSHIP '$1==var"" {print $2}' $conffile)

  23. cd $BakDir

  24. for i in $DBNAME

  25. do

  26. echo `date +'#%Y-%m-%d %H:%M:%S'` begin backup $i ....>>$LogFile

  27. $MYSQLDIR/mysqldump -u$DBUSER -p$DBPWD --skip-opt --create-option --add-drop-table --single-transaction -E -e -q --set-charset --master-data=2 -

  28. -hex-blob $i >bak_${i}_$DATE.sql

  29. #$MYSQLDIR/mysqldump -u$DBUSER -p$DBPWD --skip-opt --add-drop-table --add-locks --create-options --disable-keys --quick --hex-blob $i>bak_${i

  30. }_$DATE.sql

  31. resultbak=$?

  32. echo result: $resultbak>>$LogFile

  33. if [ $resultbak -eq 0 ];then

  34. echo `date +'#%Y-%m-%d %H:%M:%S'` end backup $i ....>>$LogFile

  35. else

  36. curl "http://219.239.93.43/submitalarmstate.php?game=dba_rdb&type=RDB&state=ALARM&description=bakfail"

  37. exit;

  38. fi

  39. done

  40. ######## gzip

  41. for i in $DBNAME

  42. do

  43. echo `date +'#%Y-%m-%d %H:%M:%S'` begin tar $i ....>>$LogFile

  44. gzip bak_${i}_$DATE.sql

  45. resulttar=$?

  46. echo tarresult:$resulttar>>$LogFile

  47. if [ $resulttar -eq 0 ];then

  48. echo `date +'#%Y-%m-%d %H:%M:%S'` end tar $i ....>>$LogFile

  49. else

  50. curl "http://219.239.93.43/submitalarmstate.php?game=dba_rdb&type=RDB&state=ALARM&description=tarfail"

  51. exit;

  52. fi

  53. done

  54. ############# ftp

  55. for i in $DBNAME

  56. do

  57. md5sum bak_${i}_$DATE.sql.gz > bak_${i}_$DATE.sql.gz.md5

  58. #

  59. #curl -T bak_${i}_$DATE.sql.gz -u $ftpuser:$ftppwd $ftpserver/$FTP_DIR/

  60. #curl -T bak_${i}_$DATE.sql.gz.md5 -u $ftpuser:$ftppwd $ftpserver/$FTP_DIR/

  61. #

  62. ##md5

  63. #

  64. #ssh $sshuser@$sship md5sum /mysqlbackup/database/$FTP_DIR/bak_${i}_$DATE.sql.gz > $BakDir/bak_${i}_$DATE.sql.gz_ftp.md5

  65. #localmd5=$(cat $BakDir/bak_${i}_$DATE.sql.gz.md5 |awk '{print $1}')

  66. #remotemd5=$(cat $BakDir/bak_${i}_$DATE.sql.gz_ftp.md5 |awk '{print $1}')

  67. # if [ $localmd5 = $remotemd5 ] ;then

  68. # echo `date +'%Y%m%d %H:%M:%S'` ftpsucess $?>>$LogFile

  69. # else

  70. # echo `date +'%Y%m%d %H:%M:%S'` ftpfail $?>>$LogFile

  71. # curl "http://219.239.93.43/submitalarmstate.php?game=dba_rdb&type=RDB&state=ALARM&description=ftp_fail"

  72. # fi

  73. #

  74. #

  75. done

  76. ##rm -f $DumpFile
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP