Mysql数据备份

 1 #!/bin/bash
 2 #2014-11-4
 3 #author pdd
 4 #backup mysql
 5 
 6 backup_target_dir="/data/mysql_backup"
 7 backup_logs_dir="/data/mysql_backup/logs"
 8 
 9 Date=$(date "+%Y.%m.%d")
10 LDate=$(date "-d -4 day" "+%Y.%m.%d") # keep 5 backup files
11 
12 echo "----------$(date "+%F %T")----------" >>$backup_logs_dir/mysql.log
13 echo "backup start" >> $backup_logs_dir/mysql.log
14 
15 mysqldump -uroot -pkobe5824 --all-databases >$backup_target_dir/mysql_$Date.sql 2>/dev/null
16 
17 if [ 0 -eq $? ];then
18     echo "mysql backup success !" >>$backup_logs_dir/mysql.log
19 else
20     echo "mysql backup fail " | tee -a $backup_logs_dir/mysql.log | mail -s mysql 254995740@qq.com
21 fi
22 
23 if [ -e $backup_target_dir/mysql$LDate.sql ];then
24     echo "rm success !" >> $backup_logs_dir/mysql.log
25 else
26     echo -e "rm fail\n" | tee -a $backup_logs_dir/mysql.log | mail -s rm 254995740@qq.com
27 fi

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。