mysql使用binlog實現增量備份指令碼

2021-10-06 09:11:22 字數 899 閱讀 1862

使用binlong日誌實現mysql的增量備份

[root@mysqltest ~]# cat a.sh

#!/bin/bash

bakdir=/mnt #備份檔案存放的路徑

bindir=/data/mysql/log #binlog日誌的路徑

logfile=/data/mysql/log/bak.log #日誌存放路徑

binfile=/data/mysql/log/mysql-bin.index #binlog日誌索引檔案

mysqladmin -uroot -p****** flush-logs #備份前先重新整理binlog日誌

counter=`wc -l $binfile|awk ''` #統計binlog日誌總數

nextnum=0

for file in `cat $binfile`

do base=`basename $file`

nextnum=`expr $nextnum + 1`

if [ $nextnum -eq $counter ]; then

echo $base skip! >> $logfile

else

dest=$bakdir/$base

if [ -e $dest ]; then

echo $base exist! >> $logfile

else

cp $bindir/$base $bakdir/

echo $base copying >> $logfile

fifi

done

echo `date +"%y年%m月%d日 %h:%m:%s"` $next bakup succ~ >> $logfile

MySQL開啟binlog日誌

mysql開啟binlog日誌很簡單,只需要找到配置檔案,在配置檔案中的 mysqld 配置段新增下面一句話就可以了 log bin mysql bin 這樣就開啟了mysql的binlog日誌。使用下面的sql語句在mysql的客戶端可以檢視binlog日誌是否開啟 show master log...

mysql 匯出binlog日誌

首先你得開啟了mysql的bin log.找到你的mysqlbinlog。執行 find name mysqlbinlog 檢視mysql server上的二進位制日誌 mysql showbinarylogs 將binlog檔案匯出為sql檔案 usr local src mysql 5.7.10...

Mysql開啟binlog 實踐

mysql binlog是mysql資料庫的二進位制日誌,用於記錄使用者對資料庫操作的sql語句 除了資料查詢語句 資訊。binlog的格式也有三種 statement row mixed 我使用的是用docker安裝的mysql,所以需要提前掛載好配置檔案。開啟binlog方法 1 找到 my,c...