dump备份mysql库
Auth: Jin
Date: 20140403
Content:
1 #!/bin/bash - 2 ### auth: Jin 3 ### date: 20140402 4 ### Desc: 根据配置文件里的ip,端口(dblist文件格式为192.168.201.245:3303:sso:root:passwd),数据库名dump备份mysql数据,清理指定天前的备份文件,通过ssh隧道追加同步到其他IDC服务器上 5 ### Usage: ./dump_mysqldatabase.sh 6 7 BACKDIR=/data/BackupPC/database 8 LIST=${BACKDIR}/dblist 9 BACKUPLOG=${BACKDIR}/dump_mysqldatabase.log 10 TODAY=`date +%F` 11 DELDAY=`date -d "7 day ago" +%F` 12 NUM=$(cat $LIST | wc -l) 13 DUMPBIN=/usr/local/mysql/bin/mysqldump 14 RSYNCBIN=/usr/bin/rsync 15 16 function log () 17 { 18 echo " " >> $BACKUPLOG 19 echo "###########################" >> $BACKUPLOG 20 echo "`date +%F/%T` $1" >> $BACKUPLOG 21 echo "###########################" >> $BACKUPLOG 22 } 23 24 log START 25 26 ### dump 27 for (( i=1; i<=$NUM; i=i+1 ));do 28 IP=$(sed -n "$i"p $LIST | awk -F : ‘{print $1}‘) 29 PORT=$(sed -n "$i"p $LIST | awk -F : ‘{print $2}‘) 30 DB=$(sed -n "$i"p $LIST | awk -F : ‘{print $3}‘) 31 USER=$(sed -n "$i"p $LIST | awk -F : ‘{print $4}‘) 32 PASSWD=$(sed -n "$i"p $LIST | awk -F : ‘{print $5}‘) 33 ${DUMPBIN} -h${IP} -P${PORT} -u${USER} -p${PASSWD} ${DB} --opt | gzip -9 > ${BACKDIR}/db-${TODAY}.${DB}.sql.gz 34 if [ $? -eq 0 ];then 35 echo "${IP} ${PORT} ${DB} backup Sucessful" >> $BACKUPLOG 36 else 37 echo "${IP} ${PORT} ${DB} backup Fail" >> $BACKUPLOG 38 fi 39 done 40 41 ### delete 42 for (( i=1; i<=$NUM; i=i+1 ));do 43 DB=$(sed -n "$i"p $LIST | awk -F : ‘{print $3}‘) 44 rm -f ${BACKDIR}/db-${DELDAY}.${DB}.sql.gz 45 if [ -f "${BACKDIR}/db-${DELDAY}.${DB}.sql.gz" ]; then 46 echo "${BACKDIR}/db-${DELDAY}.${DB}.sql.gz delete Fail" >> $BACKUPLOG 47 else 48 echo "${BACKDIR}/db-${DELDAY}.${DB}.sql.gz delete OK" >> $BACKUPLOG 49 fi 50 done 51 52 ### rsync to other IDC 53 ${RSYNCBIN} -av -e"ssh" ${BACKDIR}/ root@10.1.0.22:${BACKDDIR}/ 54 if [ $? -eq 0 ];then 55 echo "JQ IDC rsync to ZJ IDC OK" >> $BACKUPLOG 56 else 57 echo "JQ IDC rsync to ZJ IDC Fail" >> $BACKUPLOG 58 fi 59 60 log END
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。