溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Club數(shù)據(jù)庫基于時(shí)間點(diǎn)單表恢復(fù)案例

發(fā)布時(shí)間:2020-07-12 12:39:03 來源:網(wǎng)絡(luò) 閱讀:431 作者:524683249 欄目:數(shù)據(jù)庫

Club數(shù)據(jù)庫基于時(shí)間點(diǎn)單表恢復(fù)案例

發(fā)現(xiàn)問題:

DBA于2016-05-20發(fā)現(xiàn)club數(shù)據(jù)庫出現(xiàn)sql注入現(xiàn)象,如下圖

Club數(shù)據(jù)庫基于時(shí)間點(diǎn)單表恢復(fù)案例

此時(shí)數(shù)據(jù)庫中數(shù)據(jù)已經(jīng)被全部替換了,具體數(shù)據(jù)如下

Club數(shù)據(jù)庫基于時(shí)間點(diǎn)單表恢復(fù)案例

Club數(shù)據(jù)庫基于時(shí)間點(diǎn)單表恢復(fù)案例

可以看到nickname,realname都已經(jīng)被修改,這是業(yè)務(wù)已經(jīng)收到影響需要對(duì)數(shù)據(jù)進(jìn)行恢復(fù)。

解決方案:

1、找到當(dāng)天備份,并將備份文件直接啟動(dòng)。

啟動(dòng)時(shí)注意調(diào)一下配置文件中的server-id,避免與線上從庫沖突

2、通過mysqlbinlog工具解析備份時(shí)間到當(dāng)前時(shí)間的所有binlog日志并追加到一個(gè)臨時(shí)文件中

mysqlbinlog -d club --start-datetime '2016-05-20 00:00:00' mysql-bin.000161 > /tmp/liuyaxin.sql

mysqlbinlog -d club --start-datetime '2016-05-20 00:00:00' mysql-bin.000162 >> /tmp/liuyaxin.sql

3、過濾臨時(shí)文件中對(duì)該表的操作,找到導(dǎo)致問題的sql語句,并記錄當(dāng)時(shí)問題sql前一條sqllog_pos點(diǎn),binlog_file信息沒有記錄,需要根據(jù)sql執(zhí)行時(shí)間點(diǎn)去確認(rèn)。

grep -B 2 user_doctor_new liuyaxin.sql | grep -A 5 -B 6  qwqrnore | more

導(dǎo)致問題sql及時(shí)間點(diǎn):

Club數(shù)據(jù)庫基于時(shí)間點(diǎn)單表恢復(fù)案例

sql沒有條件限制導(dǎo)致全表數(shù)據(jù)被惡意修改。

導(dǎo)致問題前一條sql及時(shí)間點(diǎn):

Club數(shù)據(jù)庫基于時(shí)間點(diǎn)單表恢復(fù)案例

4.在利用備份啟動(dòng)的實(shí)例上通過指定binlog_pos點(diǎn)結(jié)束位置的方式開啟中從同步

start slave until MASTER_LOG_FILE='mysql-bin.000162',MASTER_LOG_POS=101655506;

等待數(shù)據(jù)同步,同步到指定pos點(diǎn)時(shí) sql線程會(huì)自動(dòng)斷掉 

localhost.club>show slave status\G;

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: ****

Master_User: *****

Master_Port: ****

Connect_Retry: 60

Master_Log_File: mysql-bin.000164

Read_Master_Log_Pos: 107671841

Relay_Log_File: relay-bin.000004

Relay_Log_Pos: 101704628

Relay_Master_Log_File: mysql-bin.000162

Slave_IO_Running: Yes

Slave_SQL_Running: No

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 101655506

Relay_Log_Space: 2255157326

Until_Condition: Master

Until_Log_File: mysql-bin.000162

Until_Log_Pos: 101655506

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: NULL

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 0

Last_SQL_Error:

1 row in set (0.00 sec)

根據(jù)標(biāo)紅字段可以看出數(shù)據(jù)已經(jīng)同步到我們指定的位置了。

5.將同步完成后的要恢復(fù)的表dump出來,并恢復(fù)到線上庫

Club數(shù)據(jù)庫基于時(shí)間點(diǎn)單表恢復(fù)案例

6.校驗(yàn)數(shù)據(jù)

Club數(shù)據(jù)庫基于時(shí)間點(diǎn)單表恢復(fù)案例

Club數(shù)據(jù)庫基于時(shí)間點(diǎn)單表恢復(fù)案例

名字已經(jīng)變回來了

9.恢復(fù)完畢

 

 

 


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI