首页 > 代码库 > Mysql数据备份

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 files11 12 echo "----------$(date "+%F %T")----------" >>$backup_logs_dir/mysql.log13 echo "backup start" >> $backup_logs_dir/mysql.log14 15 mysqldump -uroot -pkobe5824 --all-databases >$backup_target_dir/mysql_$Date.sql 2>/dev/null16 17 if [ 0 -eq $? ];then18     echo "mysql backup success !" >>$backup_logs_dir/mysql.log19 else20     echo "mysql backup fail " | tee -a $backup_logs_dir/mysql.log | mail -s mysql 254995740@qq.com21 fi22 23 if [ -e $backup_target_dir/mysql$LDate.sql ];then24     echo "rm success !" >> $backup_logs_dir/mysql.log25 else26     echo -e "rm fail\n" | tee -a $backup_logs_dir/mysql.log | mail -s rm 254995740@qq.com27 fi

 

Mysql数据备份