您好,登錄后才能下訂單哦!
下文主要給大家帶來使用二進制日志shell腳本該如何增量備份mysql,希望這些內容能夠帶給大家實際用處,這也是我編輯使用二進制日志shell腳本該如何增量備份mysql這篇文章的主要目的。好了,廢話不多說,大家直接看下文吧。
#!/bin/bash # Date:2017-10 # Description:backup mysql binary logs # Version:0.1 db_user="root" myisam_db="mysql" db_passwd="123456" host="localhost" export PATH="/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin" backup_dir="/opt/backup/mysql/bin" log_file="/opt/backup/mysql/bin/bin_log_file.log" bin_index="/mydata/data/mysql-bin.index" data_dir="/mydata/data" mysql="$(which mysql)" $mysql -u$db_user -h$host -p$db_passwd -e "flush logs" num=$(awk 'END{print NR}' $bin_index) counter=0 start_time=$(date +"%F %H:%M:%S") [ ! -d $backup_dir ] && mkdir -p $backup_dir [ ! -f $log_file ] && touch $log_file echo "Starting backup mysql binary logs at $start_time" >>$log_file for file in `cat $bin_index` do base=`basename $file` counter=$(expr $counter + 1) if [ $counter -eq $num ];then echo "Skip $base" >>$log_file else if [ ! -f $backup_dir/$base ];then cp -a $data_dir/$base $backup_dir 2>>$log_file if [ $? -eq 0 ];then echo "Backup $base successfully" >>$log_file else echo "Backup $base failed" >>$log_file echo "Backup $base to $backup_dir failed"|mail -s "MySQL binary logs backup failed" root@localhost fi fi fi done stop_time=$(date +"%F %H:%M:%S") echo "End backup mysql binary logs at $stop_time" >>$log_file echo " " >>$log_file exit 0
對于以上關于使用二進制日志shell腳本該如何增量備份mysql,大家是不是覺得非常有幫助。如果需要了解更多內容,請繼續關注我們的行業資訊,相信你會喜歡上這些內容的。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。