Oracle/RMAN

RMAN사용도중 control file을 재생성하게되면!? ; RMAN환경설정다시하기, RMAN backuppiece정보 재등록하기

에몽이ㅋ 2012. 2. 27. 00:18

기본적으로는 저장되어있던 backup정보들이 다 날라갑니다.
  --> 하지만 백업된 파일만 남아있다면 다시 RMAN에서 등록이 가능합니다.



control file 재생성 후 

RMAN 환경설정 재설정하기

alter database backup control file to trace as 'control.sql';
명령어로 재생성 스크립트 생성 후 생성된 스크립트 안의 내용을 살펴보면
-- Configure RMAN configuration record 1
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CHANNEL','DEVICE TYPE DISK FORMAT   ''/app/rman/%U_%T.rman''');
-- Configure RMAN configuration record 2
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('DEVICE TYPE','DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET');
위와같이 RMAN에서 설정했던 환경들이 적혀져 있는 것을 볼 수 있습니다.
위 명령어들을 open 상태에서 실행해주면, control file재생성 이전의 RMAN환경과 동일하게 다시 설정이 되게 됩니다.


RMAN으로 백업한 파일 재등록하기

예전 백업파일을 카탈로그에 다시 등록하는 명령어

RMAN> catalog backuppiece '/app/rman/02n4abi7_1_1_20120226.rman';  입니다. (파일 하나만 등록)
RMAN> catalog start with '/directory'; (디렉토리 한꺼번에 등록)



아래 예시를 보시죠.
RMAN> list backupset;

using target database control file instead of recovery catalog

List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
1       Full    283.91M    DISK        00:00:59     2012-02-26:18:56:00
        BP Key: 1   Status: AVAILABLE  Compressed: YES  Tag: TAG20120226T185501
        Piece Name: /app/rman/01n4abg5_1_1_20120226.rman
  List of Datafiles in backup set 1
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  1       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/system01.dbf
  2       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/sysaux01.dbf
  3       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/undotbs01.dbf
  4       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/users01.dbf
  5       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/example01.dbf
  6       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/koo01.dbf
  7       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/test01.dbf
  8       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/fbda01.dbf
  9       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/koo02.dbf

-----------------------------------------------------------------------------------------
컨트롤파일 재생성
-----------------------------------------------------------------------------------------
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> @ctl
ORACLE instance started.

Total System Global Area  535662592 bytes
Fixed Size                  1345376 bytes
Variable Size             209717408 bytes
Database Buffers          318767104 bytes
Redo Buffers                5832704 bytes

Control file created.

SQL> alter database open;

Database altered.

이후 RMAN에서 list backupset;를 보고, 없으면(없는게 당연하죠) 재등록시켜주겠습니다.!
-----------------------------------------------------------------------------------------
이후 RMAN에서 backupset살펴보기
-----------------------------------------------------------------------------------------
RMAN> list backupset;

using target database control file instead of recovery catalog
specification does not match any backup in the repository      << 등록을 하지 않으면 없습니다.

RMAN> catalog backuppiece '/app/rman/01n4abg5_1_1_20120226.rman';  << 예전 백업파일을 직접 등록시켜줍니다.

cataloged backup piece
backup piece handle=/app/rman/01n4abg5_1_1_20120226.rman RECID=1 STAMP=776303723

RMAN> catalog backuppiece '/app/rman/02n4abi7_1_1_20120226.rman';  << 예전 백업파일을 직접 등록시켜줍니다.

cataloged backup piece
backup piece handle=/app/rman/02n4abi7_1_1_20120226.rman RECID=2 STAMP=776303734

RMAN> list backupset;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
1       Full    283.91M    DISK        00:00:00     2012-02-26:18:55:01
        BP Key: 1   Status: AVAILABLE  Compressed: YES  Tag: TAG20120226T185501
        Piece Name: /app/rman/01n4abg5_1_1_20120226.rman
  List of Datafiles in backup set 1
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  1       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/system01.dbf
  2       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/sysaux01.dbf
  3       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/undotbs01.dbf
  4       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/users01.dbf
  5       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/example01.dbf
  6       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/koo01.dbf
  7       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/test01.dbf
  8       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/fbda01.dbf
  9       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/koo02.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
2       Full    1.03M      DISK        00:00:00     2012-02-26:18:56:07
        BP Key: 2   Status: AVAILABLE  Compressed: YES  Tag: TAG20120226T185501
        Piece Name: /app/rman/02n4abi7_1_1_20120226.rman
  Control File Included: Ckp SCN: 938690       Ckp time: 2012-02-26:18:56:07


여기서 의문 : 해당 백업파일로 복구가 가능할까?
한번 해봅시다.
SQL> !rm /app/oracle/oradata/testdb/test01.dbf  << 장애발생

SQL> alter tablespace test offline;
alter tablespace test offline
*
ERROR at line 1:
ORA-01116: error in opening database file 7
ORA-01110: data file 7: '/app/oracle/oradata/testdb/test01.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3

-------------------------------------------------------------------------------
RMAN에서 복구시도
-------------------------------------------------------------------------------
RMAN> run {
2> sql "alter database datafile ''/app/oracle/oradata/testdb/test01.dbf'' offline";
3> restore datafile 7;
4> recover datafile 7;
5> sql "alter database datafile ''/app/oracle/oradata/testdb/test01.dbf'' online";
6> }

using target database control file instead of recovery catalog
sql statement: alter database datafile ''/app/oracle/oradata/testdb/test01.dbf'' offline

Starting restore at 2012-02-27:00:02:43
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=134 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00007 to /app/oracle/oradata/testdb/test01.dbf
channel ORA_DISK_1: reading from backup piece /app/rman/01n4abg5_1_1_20120226.rman
channel ORA_DISK_1: piece handle=/app/rman/01n4abg5_1_1_20120226.rman tag=TAG20120226T185501
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 2012-02-27:00:02:44

Starting recover at 2012-02-27:00:02:44
using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 1 is already on disk as file /app/arc/1_1_776291823.arc
archived log file name=/app/arc/1_1_776285053.arc thread=1 sequence=1
media recovery complete, elapsed time: 00:00:01
Finished recover at 2012-02-27:00:02:45

sql statement: alter database datafile ''/app/oracle/oradata/testdb/test01.dbf'' online

-------------------------------------------------------------------------------
복구 후 확인
-------------------------------------------------------------------------------
SQL> !ls /app/oracle/oradata/testdb/test01.dbf
/app/oracle/oradata/testdb/test01.dbf  << 파일이 복구되어 생성되었습니다.
SQL> l
  1  select name, status from v$datafile
  2* where name like '%test01%'
SQL> /

NAME                                          STATUS
--------------------------------------------- -------
/app/oracle/oradata/testdb/test01.dbf         ONLINE  << 무사합니다.

catalog backuppiece로 등록된 백업파일로도 얼마든지 복구가 가능합니다.!!




백업된 파일들을 다시 등록하는 다른 방법(파일이 여러개일때)

RMAN> catalog start with '/directory';
(위 catalog backuppiece와 동일하지만, 이 명령어는 폴더단위로 파일들을 등록할때 사용합니다.) 


[oracle@server16 ~]$ rman target /

Recovery Manager: Release 11.2.0.2.0 - Production on Mon Feb 27 00:12:59 2012

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: TESTDB (DBID=2559315509)

RMAN> list backupset;  << 재생성으로 인해 백업된 파일이 없다고 나옵니다.

using target database control file instead of recovery catalog
specification does not match any backup in the repository

RMAN>

RMAN> catalog start with '/app/rman';  << 폴더단위로 백업파일을 등록합니다.

searching for all files that match the pattern /app/rman

List of Files Unknown to the Database
=====================================
File Name: /app/rman/01n4abg5_1_1_20120226.rman
File Name: /app/rman/02n4abi7_1_1_20120226.rman

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /app/rman/01n4abg5_1_1_20120226.rman
File Name: /app/rman/02n4abi7_1_1_20120226.rman

------------------------------------------------------------------------------------
등록이후
------------------------------------------------------------------------------------
RMAN> list backupset;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
1       Full    283.91M    DISK        00:00:00     2012-02-26:18:55:01
        BP Key: 1   Status: AVAILABLE  Compressed: YES  Tag: TAG20120226T185501
        Piece Name: /app/rman/01n4abg5_1_1_20120226.rman
  List of Datafiles in backup set 1
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  1       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/system01.dbf
  2       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/sysaux01.dbf
  3       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/undotbs01.dbf
  4       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/users01.dbf
  5       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/example01.dbf
  6       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/koo01.dbf
  7       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/test01.dbf
  8       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/fbda01.dbf
  9       Full 938666     2012-02-26:18:55:01 /app/oracle/oradata/testdb/koo02.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
2       Full    1.03M      DISK        00:00:00     2012-02-26:18:56:07
        BP Key: 2   Status: AVAILABLE  Compressed: YES  Tag: TAG20120226T185501
        Piece Name: /app/rman/02n4abi7_1_1_20120226.rman
  Control File Included: Ckp SCN: 938690       Ckp time: 2012-02-26:18:56:07

명령어 참조사이트 : http://emrebaransel.blogspot.com/2008/11/how-to-register-older-backups-to-rman.html