-1. 배경
-. 특정 Table 쿼리실수로 데이터 유실 발생
-. 해당 DBMS는 10.0.28 버전으로 10.2.x 부터 제공되는 flash back 기능 사용불가
-. 다운타임 확보가 안되어 풀백업본 + binary log (start position / stop position 옵션) 을 사용하여 해당 쿼리부분만 빼고 적용불가능한 상태
-2. 복구 방법
Full 백업본에서 해당 테이블 ibd 파일을 db의 data 영역의 동일 테이블 ibd 파일과 교체 후
해당 테이블과 관련된 쿼리를 binlog 에서 추출하여 수행
1) Full 백업본에서 해당 테이블 ibd 파일 확인
[TESTPROD01:test_user]/bkup001/TESTDB/FULL_BACKUP/2018-07-02/test] ls -ltr test_tb.ibd -rw-r----- 1 test_user mysql 62914560 Jul 2 02:01 test_tb.ibd
2) DB 접속하여 해당 테이블 ibd 파일 discard (drop)
MariaDB [(none)]> alter table test.test_tb discard tablespace; MariaDB [(none)]> select count(*) from test.test_tb; ERROR 1146 (42S02): Table 'test.test_tb' doesn't exist [TESTPROD01:test_user]/data001/TESTDB/test] ls -ltr test_tb.ibd ls: cannot access test_tb.ibd: No such file or directory
=> DB에서 discard 수행 시 해당 테이블 ibd 파일 삭제됨
3) 백업본 ibd 파일과 교체하여 ibd 파일 import
[TESTPROD01:test_user]/bkup001/TESTDB/FULL_BACKUP/2018-07-02/test] cp test_tb.ibd /data001/TESTDB/test [TESTPROD01:test_user]/data001/TESTDB/test] ls -ltr test_tb.ibd -rw-r----- 1 test_user mysql 62914560 Jul 2 02:01 test_tb.ibd
=> 백업본 test_tb.ibd 파일을 DB의 data 영역에 복사
MariaDB [(none)]> alter table test.test_tb import tablespace; MariaDB [(none)]> select count(*) from test.test_tb; +----------+ | count(*) | +----------+ | 134377 | +----------+ 1 row in set (0.02 sec)
=> import 커맨드로 백업본의 ibd 파일 인식시킴
4) binlog 에서 해당 테이블 관련 내용만 추출하여 적용
-3. 주의 사항
M-S replication 되어 있는 구성이면 백업본 ibd 파일을 data 영역으로 복사할 때 M / S 양쪽 노드에 모두 수행해야함
* discar / import 커맨드는 양쪽 노드에서 모두 수행됨
Master 에서만 수행 시 아래와 같이 replication 이 깨지게 됨
MariaDB [(none)]> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: TESTPROD01
Master_User: repliUser
Master_Port: 3310
Connect_Retry: 60
Master_Log_File: mysql-bin.000061
Read_Master_Log_Pos: 332448184
Relay_Log_File: relay-항log.000128
Relay_Log_Pos: 331366068
Relay_Master_Log_File: mysql-bin.000061
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: 1932
Last_Error: Error 'Table 'test.test_tb' doesn't exist in engine' on query. Default database: ''. Query: 'alter table test.test_tb import tablespace'
Skip_Counter: 0
MariaDB [(none)]> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: TESTPROD01
Master_User: repliUser
Master_Port: 3310
Connect_Retry: 60
Master_Log_File: mysql-bin.000061
Read_Master_Log_Pos: 332508552
Relay_Log_File: relay-log.000128
Relay_Log_Pos: 331366068
Relay_Master_Log_File: mysql-bin.000061
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: 1813
Last_Error: Error 'Tablespace for table 'test_tb' exists. Please DISCARD the tablespace before IMPORT.' on query. De ''. Query: 'alter table test.test_tbimport tablespace'
Skip_Counter: 0
Exec_Master_Log_Pos: 331365781
Relay_Log_Space: 332509173
Until_Condition: None