본문 바로가기

Note

[관리] Offline DB 백업의 복원

Offline Backup은 Database가 메모리에서 내려간 상태에서 받아진 것을 의미한다. 다른 관점에서는 Database에 접속이 이뤄지지 않는, 업무 서비스가 되지 않는 상황에서의 백업을 의미한다.

특정 DBMS에서는 이런 offline backup 개념이 없을 수도 있겠지만, DB2에서 백업은 트랜잭션을 기록하는 로그 관리 방식과 밀접한 관련을 갖는다.

순환로깅 방식을 사용하는 경우 백업은 offline 상태에서 진행되고, 아카이브 로깅 방식(사용한 트랜잭션 로그를 버리지 않고 보관)을 사용하는 경우는 offline, online 백업이 가능해 진다.

대부분의 고객사에서는 서비스가 중지되는 시간을 줄이기 위해 Archive 로깅 모드로 DB를 운영한다. 이런 상황에 offline backup을 못하는 것은 아니지만, 받아 놓은 offline backup을 restore 하다보면 약간 당황스러운 상황이 발생한다.

DB2 걸음마 시절, 고객사에서 갑작스럽게 restore 작업을 하다가 탐탁치않게 보던 시선을 느꼈던 순간이 기억난다..

1. 로깅 방식 확인

   V8 버전 이하의 경우, 혹은 전문 백업 솔루션을 사용하는 경우 좀 더 상세히 살펴봐야 하지만 보통은 아래 변수의 설정값을 통하여 Circular 모드인지 아닌지를 확인할 수 있다.

$ db2 get db cfg for sample | grep -i logarchmeth1

First log archive method                 (LOGARCHMETH1) = OFF
Options for logarchmeth1                  (LOGARCHOPT1) =

LOGARCHMETH1 값이 설정되지 않은 경우 Circular 모드로 운영 중임을 의미한다.

이런 경우는 offline backup 을 restore 하면 바로 db 접속이 가능해 진다.

$ db2 backup db sample to /instance/inst97 compress
Backup successful. The timestamp for this backup image is : 20120423104058

$ db2 drop db sample
DB20000I  The DROP DATABASE command completed successfully.

$ db2 restore db sample from /instance/inst97
DB20000I  The RESTORE DATABASE command completed successfully.

$ db2 connect to sample

  Database Connection Information

Database server        = DB2/LINUXX8664 9.7.4
SQL authorization ID   = INST97
Local database alias   = SAMPLE

그러나 아카이빙 로그 모드로 운영되는 경우 offline backup 이미지를 복원하는 경우 바로 접속되지 않는다.

$ db2 get db cfg for sample | grep -i logarchmeth1

First log archive method                 (LOGARCHMETH1) = DISK:/instance/inst97/archive/
Options for logarchmeth1                  (LOGARCHOPT1) =

$ db2 backup db sample to ~/archive compress

Backup successful. The timestamp for this backup image is : 20120423104901

$ db2 drop db sample

DB20000I  The DROP DATABASE command completed successfully.

$ db2 restore db sample from ~/archive

DB20000I  The RESTORE DATABASE command completed successfully.

$ db2 connect to sample

SQL1117N  A connection to or activation of database "SAMPLE" cannot be made
because of ROLL-FORWARD PENDING.  SQLSTATE=57019

위와 같이 SQL1117N 코드를 반환한다. 보통은 online backup을 복원 후, rollforward 작업을 하지 않는 경우에 발생하는 메시지이다.

위의 문제 해결을 2가지 방법이 존재한다.

$ db2 restore db sample from ~/archive

$ db2 rollforward db sample query status

                                Rollforward Status

Input database alias                   = sample
Number of nodes have returned status   = 1

Node number                            = 0
Rollforward status                     = DB  pending
Next log file to be read               = S0000001.LOG
Log files processed                    =  -
Last committed transaction             = 2012-04-23-02.09.42.000000 UTC



$ db2 rollforward db sample stop

                                 Rollforward Status

Input database alias                   = sample
Number of nodes have returned status   = 1

Node number                            = 0
Rollforward status                     = not pending
Next log file to be read               =
Log files processed                    =  -
Last committed transaction             = 2012-04-23-02.09.42.000000 UTC

DB20000I  The ROLLFORWARD command completed successfully.

혹은 다음과 같이 할 수도 있겠다.

$ db2 restore db sample from ~/archive without rolling forward
DB20000I  The RESTORE DATABASE command completed successfully.

$ db2 rollforward db sample query status


                                Rollforward Status

Input database alias                   = sample
Number of nodes have returned status   = 1

Node number                            = 0
Rollforward status                     = not pending
Next log file to be read               =
Log files processed                    =  -
Last committed transaction             = 2012-04-23-02.09.42.000000 UTC

 

만일 online backup 을 restore 하고 위와 같이 rollforward를 중지하도록 하는 경우, rollforward pending은 풀리지 않는다.

$ db2 rollforward db sample stop

SQL1276N  Database "SAMPLE" cannot be brought out of rollforward pending state
until roll-forward has passed a point in time greater than or equal to
"2012-04-23-02.20.40.000000 UTC", because node "0" contains information later
than the specified time

$ db2 rollforward db sample query status


                                Rollforward Status

Input database alias                   = sample
Number of nodes have returned status   = 1

Node number                            = 0
Rollforward status                     = DB  working
Next log file to be read               = S0000000.LOG
Log files processed                    =  -
Last committed transaction             = 2012-04-23-02.20.40.000000 UTC

$ db2 connect to sample

SQL1117N  A connection to or activation of database "SAMPLE" cannot be made
because of ROLL-FORWARD PENDING.  SQLSTATE=57019

온라인 백업은 백업 이미지에 포함된 archive log 를 추출하여 최소한의 시점 복구(rollforward)를 해 주어야 한다.