shell指令碼邏輯備份資料庫

來源:互聯網
上載者:User


[zxw@host1 ~]$ nl shscp/dump_backup_my.sh 
      1  #!/bin/bash
     2  #dump mysql data once per day, reserve last 7 days data.
     3  #zhao xiaowei
     4  #2014.08.27
       
     5  PATH=/bin:/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin:~/bin
     6  export PATH
       
     7  DIR="/home/zhaoxiaowei/data_db/"
     8  FILENAME_PREFIX="data_1db_"
     9  DATENOW=`date --date= +%Y%m%d`
    10  BACKUPFILE=${DIR}${FILENAME_PREFIX}${DATENOW}".sql"
    11  LOGFILE="/home/zxw/shdir/logfile.log"
       
    12  MAILADDR=" xxx@xxx.com xyz@xxx.com "
       
    13  echo "-----------------------------" >> $LOGFILE
    14  echo $(date --date= +%Y%m%d) >> $LOGFILE
       
    15  mysqldump -h IP -uUSERNAME -p'XXXXXX' --events --ignore-table=mysql.events --single-transaction -A > $BACKUPFILE
    16  find $DIR -mtime +7 -exec rm '{}' \; >> $LOGFILE 2>&1
       
    17  if [ -f $BACKUPFILE ]
    18  then
    19    echo " xxx successfully." >> $LOGFILE
    20    echo " $BACKUPFILE is ok!" >> $LOGFILE
    21  else
    22    echo " Failure when xxx." >> $LOGFILE
    23    echo " $BACKUPFILE dump failure!!!" >> $LOGFILE
    24    echo -e "$DATENOW Failure when xxx " | mail -s  "$DATENOW Failure when xxx " $MAILADDR
    25  fi


轉載請著明出處:
blog.csdn.net/beiigang

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.