Oracle/백업&복구

recover database using backup controlfile until cancel; 명령어관련

에몽이ㅋ 2012. 2. 5. 02:01

보통 recover database;로 복구시에는 control파일이 최신이므로,
controlfile의 checkpoint SCN이 마지막이 되게끔, datafile에 자료들을 복구해 넣는데 반해서, 

backup된 controlfile로 복구시에는 마지막 checkpoint SCN이 언제가 되는지 모릅니다.
그래서 datafile의 SCN을 보고 그 이후의 복구자료들(archive file, logfile)을 모두 복구하게 되는데, 
(using backup controlfile 옵션)

언제까지 복구할 줄 알 수가 없으므로, 사용자가 CANCEL을 입력할 때의 시점의 파일전까지 복구를 한다는 의미입니다.(until cancel 옵션)

CANCEL입력에 관해서는 media recovery하실때 다들 auto입력하셨잖아요.
제 추측인데 auto로 입력하게 되면, 쭉 읽어오다가 복구할 파일(archive file, logfile)을 더이상 찾지 못하게 되면 자동으로 CANCEL입력이 되는 것 같습니다.

auto로 입력하지 않게 되면, 직접 파일을 일일히 써주면서 복구하게 되는데, 쭉 복구하다가 CANCEL을 입력하게 되면 CANCEL입력된 파일 전까지의 자료들은 복구가 되는 것입니다.

결국, CANCEL 입력한 파일 전까지의 불완전복구가 되는 셈입니다.
* using backup controlfile을 사용하는 때 : 
백업본의 control file을 사용할 때, control file을 재생성했을 때
 

결론은, 어떠한 이유든, control file에 최근 SCN이 없는 상태에서, recover(복구)하고 싶을 땐 using backup controlfile 옵션을 사용해야합니다.



 
관련 데모시나리오
1. backup 실행

2. 테이블생성, 자료입력 등등 후 log switch로 archivelog file생성

3. datafile모두 삭제됨, control파일 삭제됨  --> 2번에서 생성한 자료들 모두 삭제됨

4. shutdown후 백업된 datafile, control파일 restore

5. startup mount까지 올림

6. recover database using backup controlfile until cancel; 로 복구

7. alter database open resetlogs; 로 open함

8. 2번에서 입력한 자료들 복구 확인


 
SQL> select status from v$instance;

STATUS
------------
OPEN

SQL> !sh ~/main_backup.sh

set begin backup mode~~

real    0m1.487s
user    0m0.061s
sys     0m0.076s

end begin backup mode--

start file copy.…

real    0m44.491s
user    0m0.110s
sys     0m3.328s
end file copy~

set end backup mode~~

real    0m0.918s
user    0m0.026s
sys     0m0.040s
complete hot backup~!!

--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------

SQL> create table scott.t01 (no number) tablespace users;

Table created.

SQL> insert into scott.t01 values(1);

1 row created.

SQL> select * from scott.t01;

        NO
----------
         1

SQL> commit;

Commit complete.

SQL> alter system switch logfile;

System altered.

SQL> /

System altered.

SQL> /

System altered.

SQL> /

System altered.

SQL> /

System altered.

SQL> /

System altered.

SQL> /

System altered.

SQL> alter system checkpoint;

System altered.

SQL> !rm ~/oradata/testdb/*.ctl

SQL> !rm ~/oradata/testdb/*.dbf

SQL> !ls ~/oradata/testdb/
redo01.log  redo02.log  redo03.log  <--- 자료들이 모두 유실

--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------
SQL> !ls /backup/open
2012-02-05-01-23-44  2012-02-05-01-51-12

SQL> !cp -av /backup/open/2012-02-05-01-51-12/*.dbf ~/oradata/testdb/
`/backup/open/2012-02-05-01-51-12/example01.dbf' -> `/home/oracle/oradata/testdb/example01.dbf'
`/backup/open/2012-02-05-01-51-12/sysaux01.dbf' -> `/home/oracle/oradata/testdb/sysaux01.dbf'
`/backup/open/2012-02-05-01-51-12/system01.dbf' -> `/home/oracle/oradata/testdb/system01.dbf'
`/backup/open/2012-02-05-01-51-12/undotbs01.dbf' -> `/home/oracle/oradata/testdb/undotbs01.dbf'
`/backup/open/2012-02-05-01-51-12/users01.dbf' -> `/home/oracle/oradata/testdb/users01.dbf'

SQL> !cp -av /backup/open/2012-02-05-01-51-12/*.ctl ~/oradata/testdb/control01.ctl
`/backup/open/2012-02-05-01-51-12/2012-02-05-01-51-12.ctl' -> `/home/oracle/oradata/testdb/control01.ctl'

--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------
SQL> startup
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  1272600 bytes
Variable Size              96470248 bytes
Database Buffers           67108864 bytes
Redo Buffers                2920448 bytes
Database mounted.
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------
SQL> recover database using backup controlfile until cancel;   <---- 복구시도
ORA-00279: change 733371 generated at 02/05/2012 01:51:11 needed for thread 1
ORA-00289: suggestion : /backup/arc/1_1_774409410.dbf
ORA-00280: change 733371 for thread 1 is in sequence #1


Specify log: {=suggested | filename | AUTO | CANCEL}
auto
ORA-00279: change 733494 generated at 02/05/2012 01:53:31 needed for thread 1
ORA-00289: suggestion : /backup/arc/1_2_774409410.dbf
ORA-00280: change 733494 for thread 1 is in sequence #2
ORA-00278: log file '/backup/arc/1_1_774409410.dbf' no longer needed for this
recovery


ORA-00279: change 733496 generated at 02/05/2012 01:53:32 needed for thread 1
ORA-00289: suggestion : /backup/arc/1_3_774409410.dbf
ORA-00280: change 733496 for thread 1 is in sequence #3
ORA-00278: log file '/backup/arc/1_2_774409410.dbf' no longer needed for this
recovery

--------------------------------------------------------------
생략
--------------------------------------------------------------

ORA-00279: change 733507 generated at 02/05/2012 01:53:40 needed for thread 1
ORA-00289: suggestion : /backup/arc/1_8_774409410.dbf
ORA-00280: change 733507 for thread 1 is in sequence #8
ORA-00278: log file '/backup/arc/1_7_774409410.dbf' no longer needed for this
recovery
  ------------ 여기까지 복구완료 -------------

ORA-00308: cannot open archived log '/backup/arc/1_8_774409410.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3


--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------

SQL> alter database open resetlogs;

Database altered.

SQL> select * from scott.t01;

        NO
----------
         1
복구확인