반응형

오라클 import 과정중에


아래와 같이 에러를 만났다


ora-00257 archiver error. connect internal only until freed


원인은 


아카이브 full로 인해 발생


근데 문제는 ASM 디스크 였다


아래의 쿼리를 통해 조회하면 archive err 상태를 확인 가능하다


SQL> select * from v$archive_dest;



방법은 수동 삭제와 자동 삭제가 있고


개발서버라 고민없이 RMAN으로 접속하여 자동으로 지웠다.


수동삭제


Subject:  How To Delete Archive Log Files Out Of +Asm? 

Doc ID:  Note:300472.1

The information in this document applies to: 

Oracle Server - Enterprise Edition - Version: 10.1.0.3

Information in this document applies to any platform.

Goal

How to delete archive log files out of +ASM? 

Fix

1. Run the following SQL to find the full path for the archivelog files.

SELECT CONCAT('+'||gname, SYS_CONNECT_BY_PATH(aname,'/')) full_path,

dir, sys FROM (SELECT g.name gname, a.parent_index pindex, a.name aname,

a.reference_index rindex, a.ALIAS_DIRECTORY dir, a.SYSTEM_CREATED sys

FROM v$asm_alias a, v$asm_diskgroup g

WHERE a.group_number = g.group_number)

START WITH (MOD(pindex, POWER(2, 24))) = 0

CONNECT BY PRIOR rindex = pindex

ORDER BY dir desc, full_path asc;

The results will look similar to the following.

+DSKGRP1/MAXCP/ARCHIVELOG/2004_11_15/thread_1_seq_970.1236.1

2. When the file is created by Oracle the format in +ASM is:

   DISKGROUP_NAME/db_name/file_type/creation_date/<file_name>.

This SQL will generate the SQL necessary to delete all archivelogs out of +ASM.

Note: Change the <diskgroup> and <dbname> to the actual values from what is returned from previous SQL output.

select 'alter diskgroup DSKGRP1 drop file

''<diskgroup>/<dbname>/ARCHIVELOG/'|| to_char(b.creation_date,'YYYY_MM_DD') ||'/'|| a.name||''';'

from v$asm_alias a, v$asm_file b

where a.group_number = b.group_number

and a.file_number = b.file_number

and b.type='ARCHIVELOG'

order by a.name;

This will generate SQL similar to the following.

alter DISKGROUP DSKGRP1 drop file  '+DSKGRP1/MAXCP/ARCHIVELOG/2004_11_15/thread_1_seq_970.1236.1';


자동삭제


$> rman target /


RMAN> crosscheck archivelog all;


RMAN> delete noprompt archivelog all;


참고 : http://interpiastory.tistory.com/21

http://kooremo.tistory.com/entry/ora00257archiver-error-Connect-internal-only-until-freed

http://database.sarang.net/?inc=read&aid=30826&criteria=oracle&subcrit=&id=&limit=20&keyword=blob&page=3

반응형
반응형

################################################################
1. Backup 하기

################################################################



1.
백업 가능대상
 

 - database (all datafile 과 현재 control file)
 - tablespace
 - datafile (current 또는 image copy)
 - archived redo log
 - control file (current 또는 image copy)
   
* 백업이 되는 않는 대상( init.ora, password file. listener.ora, tnsnames.ora, BFILES)

 

2. 백업 분류 

 - consistent vs Inconsistent 백업

     RMAN을 통한 백업은 대상 DB open 혹은 close된 시점에서 백업이 가능하며, open 상태에서의 백업은 항상 Inconsistent 이며, consistent 백업은 항상 mount상태에서 백업을 받은 것을 말하며 이전에 DB crash되거나 비 정상 종료가 되지 않아야 한다.

     ( NOARCHIVE MODE에서는 INCONSISTENT 백업을 허용하지 않는다)  


3.
백업 방법
3.1 전체 database 백업 

 run {

        allocate channel c1 device type disk;

        backup database

        format ‘/data/backup/rman/%d_%p_%t’;

  }

 
3.2 tablespace 백업

 run {

       allocate channel c1 device type disk;

       allocate channel c2 device type disk;

       allocate channel c3 device type disk;

       backup filesperset=3                                  ## 한 백업set datafile 3개를 넘어서 백업받지 않는 조건

       tablespace example , users,system

       include current controlfile;                          ## 현재 control file도 같이 백업

 }


3.3 datafile
백업

 run {

       allocate channel c1 device type disk;

       backup  datafile 1, 2, 3, 4, 5, 6 ;

 }

 
3.4 datafile copy

 run {

        allocate channel c1 device type disk;   

        backup datafilecopy ‘/home/oracle/oradata/testdb/users01.dbf’

        format ‘/data/backup/rman/users01.bak’;

 }

 
3.5 current control file 백업

 run {

       allocate channel ch1 type disk;

       backup current controlfile

       tag = mondayPMbackup;

  }

 
3.6 다른 object 백업시 control file 백업 추가 방법

 run {

       allocate channel ch1 type disk;

       backup tablespace users

       include current controlfile;                          ## users 라는 tablespace 백업시 currnet control file 포함

 }

 
3.7 Archive redo log 백업

 

 run {

       allocate channel ch1 type disk;

       backup archivelog all                                 ## archive된 모든 redo log 백업

       delete input;                                               ## 백업받은 archive log 삭제

 }

 

 * archived redo log 백업시 time, SCN, log sequence number 조건을 사용해서 백업 받을수 있다.

    예) time 조건

 run {

        allocate channel ch1 type disk;

        backup archivelog

        from time ‘SYSDATE-2’ until time ‘SYSDATE-1’;         ## 2일전부터 1일전까지 발생한 archived redolog

 }                                                                                              

 

4. incremental 백업

 

 run {

       allocate channel ch1 type disk;

       backup incremental level=0                        ## level 0 으로 database incremental backup

       database;

 }

 

 run {

       allocate channel ch1 type disk;

       backup incremental level=1                        ## level 1 system tablespace sale.f datafile 을 백업

       tablespace system                                     ##   하는데 level 0 또는 1이후로 변경된 사항만

       datafile ‘/home/oracle/oradata/testdb/example01.dbf’;   ##                     백업받는다.

 }

 

 run {

       allocate channel ch1 type disk;

       backup incremental level=2 cumulative       ## level 2 tbs_1 tablespace 백업하는데 level 0 또는 1

       tablespace  example;                                 ## 이후로 변경된 사항만 백업(cumulative 옵션사용)

 }

 

 

5. image copies

 

1. datafile

2. archived redo log

3. control file

 
5.1 datafile controlfile image copy

1)

 run {

       allocate channel ch1 type disk;

       copy

       datafile 1 to ‘/data/backup/rman/df_1.bak,

       datafile 2 to ‘/data/backup/rman/df_2.bak’,

       datafile 3 to ‘/data/backup/rman/df_3.bak’,

       datafile 4 to ‘/data/backup/rman/df_4.bak’,

       current controlfile to ‘/data/backup/rman/control.bak;

 }

 

  

################################################################
Restore

################################################################

 

1. Restore Datafile, Controlfile, Archived redo log file

 - restore 명령으로 백업set이나 image copy본에서 restore가능하다.

 (image copy본은 disk에서만 가능)

 

2. restore database

 - database restore시에는 db는 항상 close상태이어야 한다. (db open된 상태라면 아래와 같이 shutdown , startup mount 상태로 한다.)

 

     shutdown immediate

     startup mount

 

ex) 기존의 datafile 위치에 database restore 하는경우

 run {

       allocate channel ch1 type disk;

       allocate channel ch2 type disk;

       allocate channel ch2 type disk;

       restore database;

 }

 

3. tablespace datafile restore
3.1 기존위치에 tablespace restore

 run {

        sql ‘alter tablespace example offline ’;

        allocate channel ch1 type disk;

        restore tablespace  example;

 }

 
3.2 새로운 위치에 tablespace restore

 run {

        allocate channel ch1 type disk;

        sql ‘alter tablespace  example offline’ ;

         ## 새로운 위치에 datafile restore

         set newname for datafile ‘/home/oracle/oradata/testdb/example01.dbf’
          
to ‘/home/oracle/temp/example01.dbf’;

         restore tablespace example;

         ## 변경된 위치로 control file이 인식할 수 있게 함

         switch datafile all;

 }


4. control file restore

 - nomount 단계에서 restore 해야함

 run {

       allocate channel ch1 type disk;

       restore controlfile;

       alter database mount;

 }

 

5. Archived redo log restore

 - mount 단계에서 restore

 run {

       ## init.ora 에 명시되어있는 log_archive_dest 위치가 아니 다른 위치에 restore하고자 할때

       set archivelog destination to ‘/oracle/temp_restore’;

       allocate channel ch1 type disk;

       restore archivelog all;

 }

  

################################################################
Recovery

################################################################

1. Complete Recovery
1.1 recover database

 shutdown immediate;

 startup mount;

 

 run {

       allocate channel ch1 type disk;

       restore database;

       recover database;

 }

 
1.2 recover database (control file 백업본을 restore하고 복구하는 경우)

 startup nomount;

 

 run {

        allocate channel ch1 type ‘sbt_tape’;

        restore controlfile;

        alter database mount;

        restore database;

        recover database;

        alter database open resetlogs;

 }

 * resetlogs database open한 경우 reset database명령수행이 필요하며, 다시 database를 백업받는다.

 
1.3. recover tablespace
1.3.1 database close상태이고 tablespace위치에 접근가능할 때

 run {

        allocate channel ch1 type disk;

        restore tablespace tbs_3;

        recover tablespace tbs_3;

 }

 
1.3.2 database close상태이고 tablespace위치에 접근가능하지 못할 때
(datafile 위치를 바꿀 필요가 있을때)

 run {

        allocate channel ch1 type disk;

        set newname for datafile ‘/disk1/oracle/tbs_1.f’ to ‘/disk2/oracle/tbs_1.f’;

        restore tablespace tbs_1;

        switch datafile all;

        recover tablespace tbs_1;

 }

 
1.3.3 database open된 상태이고 tablespace위치에 접근가능할 때

 run {

        sql ‘alter tablespace user_data offline temporary’;

        allocate channel ch1 type disk;

        set archivelog destination to ‘/oracle/temp/arc1_restore’;

        restore tablespace user_data;

        recover tablespace user_data;

        sql ‘alter tablespace user_data online’;

 }


1.3.4 database
open된 상태이고 tablespace위치에 접근불가능할 때

 run {

        sql ‘alter tablespace tbs_1 offline temporary’;

        allocate channel ch1 type disk;

        set newname for datafile ‘/disk1/oracle/tbs_1.f’ to ‘/disk2/oracle/tbs_2.f’;

        restore tablespace tbs_1;

        switch datafile all;

        recover tablespace tbs_1;

        sql ‘alter tablespace tbs_1 online’;

 }


2. Incomplete Recovery
2.1 time base Incomplete Recovery

   time base Incomplete Recovery를 하고자 할 때는 time format을 확인한 후 작업해야 한다.

  (필요시 time format설정 변경)

 

   ) NLS_LANG=american

   NLS_DATE_FORMAT=’Mon DD YYYY HH24:MI:SS’

 

   database open시는 반드시 shutdown후 작업

     shutdown immediate;

     startup mount;

 

 run {

       set until time ‘Nov 15 1998 09:00:00’;

       allocate channel ch1 type ‘sbt_tape’;

       restore database;

       recover databse;

       alter database open resetlogs;

 }

 

   resetlogs database open후 반드시 recovery catalog database reset database 명령으로 초기화 후 target database를 백업 받도록 한다.

 


2.2
특정 SCN까지 recovery

 database open시는 반드시 shutdown후 작업

   shutdown immediate;

   startup mount;

 

 run {

       set until scn 1000;

       allocate channel ch1 type ‘sbt_tape’;

       restore database;

       recover database;

       alter database open resetlogs;

 }

 

   resetlogs database open후 반드시 recovery catalog database reset database 명령으로 초기화 후 target database를 백업 받도록 한다.

 


2.3
특정 log sequence까지 recovery

  어느시점까지 recovery할것인지는 v$log_history view 조회를 통해서 결정

 

   database open시는 반드시 shutdown후 작업

    shutdown immediate;

    startup mount;

 

 ## thread 1에 대해 log sequence 6 까지 recovery하는 예

 run {

       set until logseq 6 on thread 1;

       allocate channel ch1 type ‘sbt_tape’;

       restore database;

       recover database;

       alter database open resetlogs;

 }

  resetlogs database open후 반드시 recovery catalog database reset database 명령으로 초기화 후 target database를 백업 받도록 한다.


3.  recovery catalog
없이 DBPITR(DataBase Point In Time Recovery)할때

 - recovery catalog 없이 DBPITR 수행을 하고자 할때는 아래와 같은 몇가지 필요한 사항들이 있다

 - control file은 별도로 백업을 받아 두도록 한다.

    database 백업시 control file도 자동으로 백업을 받아지기는 하지만 그때 발생한 database 백업에 대한 정보를 가지고 있지 못하기 때문에 별도로 아래와 같이 백업을 받도록 한다.

 

     backup database;

    backup current controlfile tag = ‘database backup’;

 

    controlfile 백업시 tag 옵션을 사용하여 향후에 특정시점에 백업받은 controlfile을 사용할 수 있도록 한다.

 - tablespace 변경 시나 datafile 추가시 백업을 수행하도록 한다.(control file도 포함)

 

 예)

     catalog없이 rman 시작

     rman target / nocatalog

 

     만일 database open된 상태라면 shutdown mount시킨다.

     startup force mount;

 

     특정 임시위치에 control file restore

 run {

        set until time ‘Jun 18 1998 16:32:36’;

        allocate channel ch1 type disk;

        restore controlfile to ‘/tmp/cf.tmp’ from tag = ‘database backup’;

 }

 

 백업받은 특정 controlfile restore할 수 없을 때는 rman을 통해 restore받은 controlfile아래와 같은 sql 명령으로 백업받은 후 init.ora 관련 파라미터를 조정한후 다음단계를 수행하도록 한다.


 - sql > alter database backup controlfile to ‘/tmp/original_cf’;

 - database shutdown

 - init.ora 에 명시된 CONTROL_FILES 파라미터를 적절히 조정

 - 백업받은 controlfile을 적당한 위치에 copy

 - startup mount

 run {

        set until time ‘Jun 18 1998 16:32:36’;

        allocate channel ch1 type disk;

        restore database;

        recover database noredo;                         ## database Noarchive Mode일때 noredo 옵션사용

        alter database open resetlogs;                  ## Archive Mode일때는 noredo 옵션없이 recover한다.

 }


출처 : cafe.naver.com/prodba
반응형

'Database > ORACLE' 카테고리의 다른 글

오라클 클론 디비로 복구 하기  (0) 2010.07.13
PL/SQL Exception  (0) 2010.07.06
오라클 암호화 기능  (0) 2010.07.02
오라클 pump 관련 자료  (0) 2010.06.30
오라클 기본 유저 정보  (0) 2010.06.30
반응형

복구 관리자 (recovery manager:rman)는 데이터베이스의 백업과 복구에 관련된 정보를 저장하고 필요한 경우 백업과 복구 절차를 수행해 주는 유틸리티이다. 데이터베이스, 테이블스페이스, 데이터파일, 컨트롤 파일, 아카이브 파일별로 백업할 수 있으며, 백업 시 사용되지 않는 블록을 제외하고 백업할 수 도 있다. 또한 백업 시 손상된 블록의 사용 가능 여부를 확인해 주기도 한다.

rman 툴은 자체적인 스크립트 해석 인터프리터를 가진 명령언어 인터프리터(command language interpreter)이므로 입력된 명령을 해석하여 실행하게 된다. 예를 들어, backup, restore, copy, recover와 같은 명령을 rman 툴에서 실행할 수 있는 것이다.

rman의 형식은 다음과 같다.

형식

RMAN  [TARGET connectStringSpec
      ¦ { CATALOG connectStringSpec }
      ¦ LOG ['] filename ['] [APPEND ]
      ......
      ]...
      
connectStringSpec::=
  ['] [userid] [/ [password]] [@net_service_name] ['] 




rman 구성

RMAN 시작과 DB에 연결
다음 예제는 간단하게 rman에 접속하고 접속해지 하는 과정이다.
【예제】 ☜ rman 시각과 끝
$ rman

RMAN> exit

$ 
SQL*Plus로 데이터베이스에 접속하듯이 RMAN으로도 데이터베이스에 접속하는데,
그 차이점은 RMAN은 SYSDBA 권한을 가지고 타킷과 보조 데이터베이스에 접속해야 하는데 AS SYSDBA 키워드는 사용하지 않아도 묵시적으로 가진 것으로 간주하기 때문에 의도적으로 표시하지 않아도 된다는 점만 다르다.

RMAN에 연결되면 CONNECT TARGET을 실행해야 타킷 데이터베이스에 접속이 이루어진다.

【예제】☜ target DB에 관리자로 접속 
$ rman

RMAN> connect target /

connected to target database: ORCL (DBID=1204356616)

RMAN> exit

Recovery Manager complete.
$
다음 예는 RMAN 세션중에 출력되는 텍스트 파일을 로그 파일(/tmp/msglog.log)에 추가하도록 하는 예제이다.
【예제】☜ log 파일을 지정하면서 접속 
$ rman TARGET / LOG /tmp/msglog.log APPEND
RMAN> exit
$
이처럼 rman 툴을 이용하여 rman 클라이언트로 들어간 다음에, rman> 프롬프트에서 입력되는 명령은 그 문장의 끝에 세미콜론(;)을 붙여야 하는데, 다만 예외로 STARTUP, SHUTDOWN, CONNECT 명령은 세미콜론을 붙여도 되고 안 붙여도 된다

【예제】

RMAN> CONNECT TARGET
RMAN> BACKUP DATABASE;

RMAN> BACKUP DATABASE
2>  INCLUDE CURRENT
3>  CONTROLFILE
4>  ;
디폴트 RMAN configuration 보기

RMAN이 백업과 복구를 실행하는 구성을 미리 작성한 디폴트 configure가 준비되어 적용된다.
configure란 백업장치를 지정하고, 백업 장치에 접속(이를 channel이라 부름)의 구성을 설정하는 것이다.
현재 작성된 configure를 다음과 같이 확인할 수 있다.

1) RMAN을 시작하고 타킷 DB에 접속한다.
$ rman TARGET /

2) SHOW ALL 명령을 실행한다.
RMAN> SHOW ALL;


$ rman TARGET /
RMAN> show all;

using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name ORCL are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BZIP2'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/export/home/oracle/app/oracle/product/110.1/dbs/snapcf_orcl.f'; # default

RMAN> 

나열되는 항목은 CONFIGURE 명령으로 재작성할 수 있으며, 다음은 channel를 configure하는 예시이다.

CONFIGURE DEFAULT DEVICE TYPE TO DISK; # backup goes to disk
CONFIGURE DEVICE TYPE sbt PARALLELISM 2; # 2 channels used in in channel
CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT '/disk1/%U' # 1st channel to disk1
CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT '/disk2/%U' # 2nd channel to disk2
BACKUP DATABASE; # backup - 1st channel goes to disk1 and 2nd to disk2

데이터베이스 백업

BACKUP 명령으로 파일을 백업한다. RMAN은 configure로 설정된 장치에 데이터를 백업하는데, 디폴트는 disk이다.
flash recovery가 가능하고 FORMAT 매개변수를 지정하지 않은 경우라면, RMAN은 recovery 영역에 unique한 이름으로 자동적으로 백업을 생성한다.
RMAN은 디폴트로 image copy보다는 백업 셋을 생성하는데, 여기서 image copy란 유닉스의 cp 명령어로 복사하는 것을 image copy 라 한다.
backup set은 하나 이상의 backup piece로 RMAN으로만 억세스할 수 있도록 물리적 파일을 복사하는 것을 뜻한다.

BACKUP AS COPY 명령은 데이터베이스 파일을 디스크에 bit-for-bit로 image copy를 수행하는데 이는 RMAN에서만 이용할 수 있다.

option 예제 설명
FORMAT
BACKUP
 FORMAT 'AL_%d/%t/%s/%p'
 ARCHIVELOG LIKE '%arc_dest%';
백업할 조각의 위치와 이름을 지정함
%U : 유일한 이름
%d : DB_NAME
%t : timestamp를 가짐
%s : number를 가짐
%p : backup piece number
TAG
BACKUP
 TAG 'weekly_full_db-bkup'
 DATABASE MAXSETSIZE 10M;
백업 라벨에 사용자 정의 문자로 지정하지만,
TAG을 지정하지 않으면 date와 time이 디촐트임

【예제】☜ 데이터베이스를 백업

ARCHIVELOG 모드
1) RMAN을 시작하고 타킷 DB에 접속한다.
$ rman TARGET / 2) BACKUP DATABASE 명령을 실행한다.
RMAN> BACKUP DATABASE PLUS ARCHIVELOG;
NOARCHIVELOG 모드
데이터베이스는 반드시 mount 상태이어야 한다.

1) RMAN을 시작하고 타킷 DB에 접속한다.
$ rman TARGET / 2) shutdown하고 mount한다.
RMAN> SHUTDOWN IMMEDIATE
RMAN> STARTUP FORCE DBA;
RMAN> SHUTDOWN IMMEDIATE
RMAN> STARTUP MOUNT; 3) BACKUP DATABASE를 실행한다.(아래 둘 중 하나)
RMAN> BACKUP DATABASE;
RMAN> BACKUP AS COPY DATABASE; 4) 데이터베이스를 open한다.
RMAN> ALTER DATABASE OPEN;

앞 예제에서와 같이 archive mode와 noarchive mode을 예제로 익혔다.

incremental backup

incremental backup은 BACKUP INCREMENTAL 명령을 사용하여 실행하는데, 이는 full database backup보다 더 빠르다.
그러므로 recovery도 redo logs만 사용하는 경우보다 더 신속하게 복구할 수 있다.
incremental backup이나 full backup 모두 level 0의 내용은 동일하지만, full backup과 달리 level 0 backup은 incremental backup에 관한 사항이 담겨있다.
level 1 incremental backup은 이전의 incremental backup 이후의 변경된 내용만 담긴다.
그래서 level 1 백업을 cumulative incremental backup이라하고, level 0 백업을 differential incremental backup이라하는데, differential이 디폴트이다.

【예제】☜ 데이터베이스의 incremental 백업
1) RMAN을 시작하고 타킷 DB에 접속한다.

$ rman TARGET /

2) BACKUP INCREMENTAL 명령을 실행한다.
다음은 level 0 incremental 백업인 경우

RMAN> BACKUP INCREMENTAL LEVEL 0 DATABASE;

다음은 level 1 cumulative incremental 백업인 경우

RMAN> BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;

다음은 level 1 differential incremental 백업인 경우

RMAN> BACKUP INCREMENTAL LEVEL 1 DATABASE;

incrementally updated backup

incrementally updated 백업은 BACKUP FOR RECOVER OF COPY 명령을 사용한다.
FOR RECOVER OF COPY 문의 옵션은 다음과 같다.

option 예제
FOR RECOVER OF COPY WITH TAG 'tag_name' BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG 'incr_update' DATABASE;
FOR RECOVER OF COPY DATAFILECOPY FORMAT 'format' BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY DATAFILECOPY FORMAT 'disk2/df1.cpy' DATABASE;

【예제】☜ 데이터베이스의 incrementally updated 백업
1) RMAN을 시작하고 타킷 DB에 접속한다.

$ rman TARGET /

2) RECOVER COPY와 BACKUP INCREMENTAL 명령을 실행한다.
다음 스크립트를 실행한다.


     RECOVER COPY OF DATABASE
       WITH TAG 'incr_update';
     BACKUP
       INCREMENTAL LEVEL 1
       FOR RECOVER OF COPY WITH TAG 'incr_update'
       DATABASE;

database 파일과 백업의 validating

VALIDATE 명령을 사용하여 모든 데이터베이스 파일이 존재를 확인하고, 바른 위치에 있는지 확인하며, 또한 물리적 오류의 여지를 확인한다.
CHECK LOGICAL옵션을 사용하여 논리적 오류도 확인할 수 있다.

【예제】☜ 데이터베이스 파일의 유효성 확인
1) RMAN을 시작하고 타킷 DB에 접속한다.

$ rman TARGET /

2) VALIDATE 명령을 해당파일에 실행한다.

   BACKUP VALIDATE CHECK LOGICAL
     DATABASE ARCHIVELOG ALL;
만약 각각의 블럭에 대한 유효성 체크는 다음과 같이 할 수 있다.

VALIDATE DATAFILE 4 BLOCK 10 TO 13;

다음은 백업셋에 대한 유효성 체크의 예이며, 백업셋은 LIST BACKUP를 실행하여 확인할 수 있다.

VALIDATE BACKUPSET 3;

RMAN에 동작하는 명령어로 구성된 파일

데이터베이스를 주기적으로 반복하여 백업한다는 것은 실증하기 때문에 이러한 동작을 RMAN 명령으로 작성한 명령 파일을 하나의 스크립트로 작성하여 @아규먼트와 파일이름을 지정하여 실행 시키면 편리하다.

【예제】☜ RMAN에서 동작할 스크립트 생성과 실행
1) vi와 같은 문서편집기로 RMAN 명령문으로 구성된 파일을 작성한다.


    #my_commnad_file.txt
    BACKUP DATABASE PLUS ARCHIVELOG;
    LIST BACKUP;
    EXIT;

2) RMAN을 구동하고 작성한 스크립트를 @ 아규먼트로 실행시킨다.

구 분 명령어 실행 실행 결과
방법1 $ rman TARGET / @my_command_file.txt 실행이 완료되면 RMAN에서 exit함
방법2 RMAN> @my_command_file.txt **end-of-file** 메시지가 출력되며 RMAN에서 exit하지 않음

작성되는 명령문 스크립트에서 비실행문은 #으로 시작되고 또한 중간에 #을 넣으면 #이하는 비실행으로 처리한다.
rman 프롬프트에서 명령을 입력할 때도 #이하는 비실행문으로 처리한다

【예제】☜
RMAN> BACKUP # 이 부분부터 줄 끝까지는 비실행임
2> SPFILE;

Starting backup at 04-JAN-10
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 04-JAN-10
channel ORA_DISK_1: finished piece 1 at 04-JAN-10
piece handle=/export/home/oracle/flash_recovery_area/ORCL/backupset/2010_01_04/o1_mf_nnsnf_TAG20100104T130430_5n2t6gt7_.bkp tag=TAG20100104T130430 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 04-JAN-10

RMAN>

RMAN 동작의 레포트

RMAN의 LISTREPORT 문을 사용하여 RMAN을 사용한 백업 상태에 대한 정보를 알 수 있고, SHOW ALL 문을 사용하여 configuration에 대한 정보를 확인할 수 있다.

백업정보 list

LIST BACKUPLIST COPY 문을 사용하여 백업과 데이터파일에 대한 정보를 나타낸다.
다음 표는 백업에 대한 LIST 문의 옵션이다.

option 예제 설명
BY BACKUP LIST BACKUP OF DATABASE BY BACKUP 백업셋의 출력으로 디폴트임
BY FILE LIST BACKUP BY FILE 백업된 파일에 대한 정보
SUMMARY LIST BACKUP SUMMARY 요약이 출력되는데 디폴트이며 출력은 VERBOSE임
EXPIRED LIST EXPIRED COPY RMAN에의 해 기록된 백업에 관한 목록이지만, 최근 CROSSCHECK 문에 의한 것은 제외함
RECOVERABLE LIST BACKUP RECOVERABLE AVAILABLE 상태에 있는 datafile이 backup, copy된 사항이 나열됨

【예제】☜ LIST BACKUP/COPY 실행
1) RMAN을 시작하고 타킷 DB에 접속한다.

$ rman TARGET /

2) LIST 문을 실행한다.

RMAN> LIST BACKUP OF DATABASE;
RMAN> LIST COPY OF DATAFILE 1,2;
RMAN> LIST BACKUP OF ARCHIVELOG FROM SEQUENCE 10;
RMAN> LIST BACKUPSET OF DATAFILE;

데이터베이스 파일과 백업에 관한 REPORT

REPORT 문을 실행하여 LIST 문보다 더 다양한 정보를 알 수 있다.
다음은 REPORT 문의 옵션이다.

option 예제 설명
NEED BACKUP REPORT NEED BACKUP DATABASE 백업해야할 파일을 보임, 추가적으로 REDUNDANCY, RECOVERY WINDOW 를 사용할 수 있음
OBSOLETE REPORT OBSOLETE backup retention policy로 구성된 쓸모없는(폐기된) 백업을 나열함
SCHEMA REPORT SCHEMA 데이터베이스 내의 테이블스페이스와 데이터파일을 출력
UNRECOVERABLE REPORT UNRECOVERABLE 최근의 데이터파일 백업에서 복구될수 없는 데이터파일을 출력

【예제】☜
1) RMAN을 시작하고 타킷 DB에 접속한다.

$ rman TARGET /

2) REPORT 문을 실행한다.

RMAN> REPORT SCHEMA;
RMAN> REPORT OBSOLETE;

RMAN 백업 Maintaining

타킷 데이터베이스의 control 파일에 저장된 RMAN의 정보가 RMAN maintence command에 의해 사용된다.

Crosschecking backup

CROSSCHECK 명령에 의해 RMAN에 의해 백업된 논리적 기록물과 저장매체에 있는 파일을 동기화한다.

【예제】☜ crosscheck all backups & copies on disk
1) RMAN을 시작하고 타킷 DB에 접속한다.

$ rman TARGET /

2) CROSSCHECK 문을 실행한다.

RMAN> CROSSCHECK BACKUP;
RMAN> CROSSCHECK COPY;

Delete Obsolete Backups

DELETE 명령으로 RMAN으로 디스크나 테이프에 백업하였지만 쓸모없는 백업이나 파일을 삭제하게 된다.

control 파일의 파일 상태를 DELETED로 갱신하고, NOPROMPT를 지정하지 않으면 삭제할 때 의지를 묻게된다.
DELETE OBSOLETE 명령은 더 이상 필요없는 백업이나 복사된 파일을 지울 때 사용된다.

【예제】☜ delete obsolete backups & copies
1) RMAN을 시작하고 타킷 DB에 접속한다.

$ rman TARGET /

2) DELETE OBSOLETE 문을 실행한다.

RMAN> DELETE OBSOLETE;

Diagnosing & Repairing Failures with Data Recovery Advisor

data recovery advisor를 이용하여 간단하게 데이터베이스의 문제점을 진단하고 수리할 수 있다.

Listing Failures & Determing Repair Options

Failure란 데이터의 오염(corruption)을 의미한다. failure에는 fail priorityfailure status가 있는데, priority에는 CRITICAL, HIGH, LOW가 있으며, 상태는 OPEN이나 CLOSED일 수 있다.

LIST FAILURE : 모든 종류의 failure를 출력
ADVISE FAILURE : repair option으로 수동과 자동을 결정

【예제】☜ LIST FAILURE & ADVISE FAILURE
RMAN을 시작하고 타킷 DB에 접속한다.

$ rman TARGET /

RMAN> LIST FAILURE;
RMAN> ADVISE FAILURE;

Repairing Failures

앞의 LIST FAILURE나 ADVISE FAILURE를 실행하고 나서 REPAIR FAILURE 명령으로 수리할 수 있다.

【예제】☜ REPAIR FAILURE
RMAN을 시작하고 타킷 DB에 접속한다.

$ rman TARGET /

RMAN> REPAIR FAILURE;

Flashback Database

데이터베이스를 과거 어느 시점으로 되돌리는 것으로 이는 미디어 복구와 달리데이터파일을 restore할 필요가 없다.
FLASHBACK DATABASE 명령을 사용하면 과거 어느 시점으로 되돌릴 수 있는데, 이 기능은 반드시 데이터베이스가 mount 되어 있어야 한다.

【예제】☜ Flashback database
1) RMAN을 시작하고 타킷 DB에 접속한다.

$ rman TARGET /

2) 데이터베이스가 mount 되어 있어야 한다.

RMAN> SHUTDOWN IMMEDIATE;
RMAN> STARTUP MOUNT;

3) FLASHBACK DATABASE를 다음중 하나를 실행한다.


SQL> select name,scn, time, database_incarnation#,
  2  guarantee_flashback_database
  3  from v$restore_point
  4  where guarantee_flashback_database='YES';

RMAN> FLASHBACK DATABASE TO SCN 86115;
RMAN> FLASHBACK DATABASE TO RESTORE POINT BEFORE_CHANGE;
RMAN> FLASHBACK DATABASE TO TIME "TO_DATE('11/20/10','MM/DD/YY')";

4) 데이터베이스를 SQL*Plus에서 검증하기 위해 open한다.

RMAN> SQL "ALTER DATABASE OPEN READ ONLY";

5) 데이터베이스를 open한다.

RMAN> SHUTDOWN IMMEDIATE;
RMAN> STARTUP MOUNT;
RMAN> ALTER DATABASE OPEN RESETLOGS;

Restore & Recover Database Files

RESTORE나 RECOVER 명령으로 데이터베이스 파일을 복구할 수 있다.

데이터베이스 파일 복구 준비

RESTORE ... PREVIEW 명령으로 사전에 미리보기를 하지만 RESTORE는 실행되지 않는다.

【예제】☜ Preview a database restore & recovery
1) RMAN을 시작하고 타킷 DB에 접속한다.

$ rman TARGET /

2) 필요한 경우라면 테이블스페이스와 데이터파일을 확인한다.

RMAN> REPORT SCHEMA;

3) RESTORE DATABASE 명령에 PREVIEW 옵션을 실행한다.

RMAN> RESTORE DATABASE PREVIEW SUMMARY;

데이터베이스 전체를 recover

RESTORE DATABASE와 RECOVER DATABASE 명령을 사용하여 데이터베이스 전체를 복구할 수 있다.

【예제】☜ Recover whole database
1) RMAN을 시작하고 타킷 DB에 접속한다.

$ rman TARGET /

2) 파일 복구 준비를 실행한다.

RMAN> RESTORE DATABASE PREVIEW SUMMARY;

3) 데이터베이스를 mount 상태로 만든다.

RMAN> STARTUP FORCE MOUNT;

4) 데이터베이스를 restore한다.

RMAN> RESTORE DATABASE;

5) 데이터베이스를 recover한다.

RMAN> RECOVER DATABASE;

6) 데이터베이스를 open한다.

RMAN> ALTER DATABASE OPEN;

테이블스페이스만 recover

RESTORE TABLESPACE와 RECOVER TABLESPACE 명령을 사용하여 필요한 테이블스페이스만 복구할 수 있다.
데이터파일을 새 위치에 restore할 수 없다면, SET NEWNAME 명령을 RUN하고 SWITCH DATAFILE 명령이나 또는 ALTER DATABASE RENAME FILE 문으로 control file을 갱신할 수 있다.

【예제】☜ Recover tablespace when the database is open
1) RMAN을 시작하고 타킷 DB에 접속한다.

$ rman TARGET /

2) 파일 복구 준비를 실행한다.

RMAN> RESTORE DATABASE PREVIEW SUMMARY;

3) OFFLINE 복구를 준비한다.(예: 테이블스페이스 이름::=users)

RMAN> SQL 'ALTER TABLESPACE users OFFLINE';

4) 테이블스페이스를 restore와 recover 한다.

RMAN>

     RUN 
        {
         SET NEWNAME FOR DATAFILE '/disk1/oradata/prod/users01.dbf'
           TO '/disk2/users01.dbf';
         RESTORE TABLESPACE users;
         SWITCH DATAFILE ALL;
         RECOVER TABLESPACE users;
        }

5) 테이블스페이스를 ONLINE한다.

RMAN> SQL 'ALTER TABLESPACE users ONLINE';

이 방법외에 RESTORE DATAFILERECOVER DATAFILE을 사용하여 데이터파일 레벨로 복구할 수 도 있다.

데이터 블럭(block)별로 recover

잘못된 데이터파일 블럭 단위로 복구도 가능한데, v$database_block_corruption 뷰에서 오류된 데이터 파일 블럭을 확인할 수 있다.

【예제】☜ Recover data blocks
1) SQLPlus에서 오류된 데이터블럭 번호를 확인한다.

SQL> SELECT NAME, VALUE FROM V$DIAG_INFO

2) RMAN을 시작하고 타킷 DB에 접속한다.

$ rman TARGET /

3) RECOVER 명령을 실행하여 블럭을 수리한다.

RMAN> RECOVER CORRUPTION LIST;

개별 블럭을 수리하려면 다음과 같이 실행한다.

RMAN> RECOVER DATAFILE 1 BLOCK 233, 235 DATAFILE 2 BLOCK 100 TO 200;


출처 : http://radiocom.kunsan.ac.kr/lecture/oracle/backup_restore/rman.html

반응형

+ Recent posts