[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