MYSQL 鑷姩澶囦唤鑴氭湰

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MYSQL 鑷姩澶囦唤鑴氭湰相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/%e8%b7%9d%e7%a6%bb' title='璺濈'>璺濈   澶囦唤   鑷姩   tab   mysq   mod   閿欒   鍒嗘暟   mysql   

1.缂栬緫mysql澶囦唤鑴氭湰

vim test.sh
1 #!/bin/bash
  2 USER=ws
  3 PASSWORD=********
  4 DATABASE=ws-test1
  5 BACKUP_DIR=/root/backup           #鏁版嵁搴撳浠絪ql鏂囦欢鐨勭粷瀵硅矾寰?/span>
  6 LOGFILE=/root/backup/data_backup.log     #澶囦唤鏁版嵁搴撶殑鑴氭湰鐨勬棩蹇楁枃浠?/span>
  7 DATE=`date +%Y%m%d-%H%M`    #鑾峰彇褰撳墠绯荤粺鏃堕棿
  8 DUMPFILE=$DATE-ws-test1.sql      #澶囦唤鏁版嵁搴撶殑sql鏂囦欢鍚?/span>
  9 ARCHIVE=$DUMPFILE-tar.gz           #澶囦唤鐨勬暟鎹簱鍘嬬缉鍚庣殑鏂囦欢鍚?/span>
 10 MYHOST=118.190.184.140            #澶囦唤鐨勬暟鎹簱鎵€鍦ㄤ富鏈哄湴鍧€
 11
 12 if [ ! -d $BACKUP_DIR ];                   #鍒ゆ柇璺緞鏄惁瀛樺湪锛屼笉瀛樺湪鐨勮瘽鍒涘缓姝よ矾寰?br /> 13 then
 14 mkdir -p "$BACKUP_DIR"
 15 fi

 16 echo -e " " >> $LOGFILE
 17 echo "------------------------------------" >> $LOGFILE
 18 echo "BACKUP DATE:$DATE">> $LOGFILE
 19 echo "------------------------------------" >> $LOGFILE
 20

 21 cd $BACKUP_DIR      #杩涘叆澶囦唤璺緞
 22 /usr/bin/mysqldump -h$MYHOST -u$USER -p$PASSWORD $DATABASE > $DUMPFILE          #浣跨敤mysqldump鍛戒护澶囦唤鏁版嵁搴?/span>
 23
 24 if [[ $? == 0 ]]; then
 25 tar czvf $ARCHIVE $DUMPFILE >> $LOGFILE 2>&1                             #鍒ゆ柇鏄惁澶囦唤鎴愬姛锛岃嫢澶囦唤鎴愬姛锛屽垯鍘嬬缉澶囦唤鏁版嵁搴擄紝鍚﹀垯灏嗛敊璇棩蹇楀啓鍏ユ棩蹇楁枃浠朵腑鍘汇€?/span>
 26 echo "$ARCHIVE BACKUP SUCCESSFUL!" >> $LOGFILE
 27 rm -f $DUMPFILE
 28 else
 29 echo "$ARCHIVE Backup Fail!" >> $LOGFILE
 30 fi
~                                                              

2.瀹氭湡鍒犻櫎瓒呰繃涓€娈垫椂闂寸殑澶囦唤
vim test2.sh
#!/bin/bash
BACKUPDIR="/root/backup"       #澶囦唤鏁版嵁搴搒ql鏂囦欢鐨勭粷瀵硅矾寰?br />KEEPTIME=1       #瀹氫箟闇€瑕佸垹闄ょ殑鏂囦欢璺濈鐜板湪鏃堕棿鐨勫ぉ鏁?/span> 
DELFILE=`find $BACKUPDIR -type f -mtime +$KEEPTIME -exec ls {} ;`
for delfile in ${DELFILE} 
do
rm -f $delfile
done
3.缂栬緫瀹氭椂浠诲姟
crontab -e
#鍒?鏃?nbsp;鏃ワ紙姣忎釜鏈堢殑閭d竴澶?-31锛?nbsp;鏈堬紙涓€骞翠腑鐨勯偅涓湀浠? -12锛夊懆锛堜竴鍛ㄤ腑鐨勯偅涓€澶?-6锛?浠h〃鍛ㄦ棩锛?br />00 00 * * *  sh test.sh #姣忓ぉ12鐐规湰鍒嗘暟鎹簱
00 00 * * 1 sh test2.sh #姣忎釜鍛ㄦ棩12鎵ц鍒犻櫎鏁版嵁搴撶殑鑴氭湰

以上是关于MYSQL 鑷姩澶囦唤鑴氭湰的主要内容,如果未能解决你的问题,请参考以下文章

瀛楀吀鑴氭湰鍜孧D5鐖嗙牬鑴氭湰

Winclone 8 Mac澧炲己姹夊寲鐗? Windows鍒嗗尯澶囦唤杩佺Щ宸ュ叿 8.0.1

Oracle 11g RAC to RAC ADG鎼缓锛堜竴锛夐噰鐢╮man澶囦唤鎭㈠鏂瑰紡

瀹夎apache鑴氭湰

jenkins鎵ц鑴氭湰npm: command not found瑙e喅

Oracle寤鸿〃鑴氭湰璁板綍