상세 컨텐츠

본문 제목

2024년 1월 26일 2교시 RMAN을 이용해서 복제DB (과거 시간 DB) 만들기 2

오라클 백업 리커버리

by 병아리 엔지니어 2024. 1. 26. 11:51

본문

★ 만약 1교시 때 선생님처럼 sqlplus 로 접속이 안된다면:

프로세스들이 엉켜 있어서 그런 것, 그래서 프로세스를 kill 하면 된다.

 

[oracle@oracle ~]$ ps -ef | grep clone

이렇게 해서 프로세스를 확인하면 프로세스 번호가 나오는데 

 

oracle    8966     1  0 10:49 ?        00:00:00 ora_pmon_clone

프로세스 번호를 가지고 프로세스를 kill 할 수 있다.

 

[oracle@oracle ~]$ kill -9 8966 수행하지마...

이러면 DB 를 불완전하게 내리게 된다. (shutdown abort)

 

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

 

1. 복제 DB 로 접속

 

1-1. DB 노마운트 단계까지 띄우기

(컨트롤파일이 없어서 마운트 단계까지는 못띄움)

 

SYS@clone> startup pfile=$ORACLE_HOME/dbs/initclone.ora nomount

 

ORACLE instance started.

Total System Global Area  167407616 bytes
Fixed Size                  1363300 bytes
Variable Size             109052572 bytes
Database Buffers           50331648 bytes
Redo Buffers                6660096 bytes

 

SYS@clone> select status from v$instance;

STATUS
------------
STARTED

 

2.  RMAN 을 이용해서 복제 DB 만들기

[oracle@oracle ~]$ rman auxiliary/

rman auxiliary / 는 복제 혹은 복구작업에 사용하는 추가 데이터베이스에서 RMAN 을 띄우는 마법의 주문,

rman target / 은 target DB, 즉 원본 DB 에서 RMAN 을 띄우는 마법의 주문

(뒤에 슬래시 빼먹으면 오류 난다...)

 

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Jan 26 10:56:57 2024
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to auxiliary database: CLONE (not mounted)

 

2-1. 

clone.txt
0.00MB

 

RUN {
  set newname for datafile 1 to '/home/oracle/clone/system01.dbf';
  set newname for datafile 2 to '/home/oracle/clone/sysaux01.dbf';
  set newname for datafile 4 to '/home/oracle/clone/users01.dbf';
  set newname for datafile 5 to '/home/oracle/clone/example01';
  set newname for datafile 6 to '/home/oracle/clone/undotbs01.dbf';
  DUPLICATE TARGET DATABASE TO 'clone'
  pfile='/u01/app/oracle/product/11.2.0.4/db_1/dbs/initclone.ora'
  nofilenamecheck
  backup location '/home/oracle/clone'
  until time "to_date('2024-01-26 10:02:20','yyyy-mm-dd hh24:mi:ss')"
  LOGFILE
    '/home/oracle/clone/redo01.log' SIZE 50M,
    '/home/oracle/clone/redo02.log' SIZE 50M,
    '/home/oracle/clone/redo03.log' SIZE 50M;
}

 

수행은 위에 걸로. 아래는 설명

 

RUN {
  set newname for datafile 1 to '/home/oracle/clone/system01.dbf';
  set newname for datafile to '/home/oracle/clone/sysaux01.dbf';
  set newname for datafile 4 to '/home/oracle/clone/users01.dbf';
  set newname for datafile 5 to '/home/oracle/clone/example01';
  set newname for datafile 6 to '/home/oracle/clone/undotbs01.dbf';
  DUPLICATE TARGET DATABASE TO 'clone'
  pfile='/u01/app/oracle/product/11.2.0.4/db_1/dbs/initclone.ora'
  nofilenamecheck  --- 저 데이터파일이 없으므로 파일체크하지 말라는 뜻
  backup location '/home/oracle/clone'
  until time "to_date('2024-01-26 10.02.20','yyyy-mm-dd hh24:mi:ss')"   --- 시간은 테이블 drop 전 시간으로 바꿔주기
  LOGFILE
    '/home/oracle/clone/redo01.log' SIZE 50M,
    '/home/oracle/clone/redo02.log' SIZE 50M,
    '/home/oracle/clone/redo03.log' SIZE 50M;
}   --- 위 세 줄은 로그파일이 없지만 위의 위치에 빈 깡통을 만들어달라는 뜻

컨트롤파일의 위치는 초기 파라미터 파일에 있다.

 

(자기 백업본의 데이터 파일 개수가 만약 다르면 : 다 맞춰주기,

백업본의 데이터파일 개수와 번호는 list backup 으로 확인)

 

2-2. QUESTION. 에러 발생 ㅠㅠ

 

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting Duplicate Db at 26-JAN-24
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 01/26/2024 11:08:57
RMAN-05501: aborting duplication of target database
RMAN-05575: CONTROLFILE backup created before to_date('2024-01-26 10:02:20','yyyy-mm-dd hh24:mi:ss') not found in /home/oracle/clone

 

(백업과 컨트롤파일이 안맞으면 오류 발생)

+ 초기 파라미터 파일 체크하기

하지만 초기 파라미터 파일이 틀렸으면 애초에 sqlplus / as sysdba 로 접속하는 단계에서부터 오류가 난다.

ANSWER. 알고보니 clone 폴더에 컨트롤파일이 들어가지 않아서 오류가 났던 것... ㅠㅠ

 

 

2-3. rman 에서 exit 해서 sqlplus 로 들어가기

 

RMAN> exit

[oracle@oracle ~]$ sqlplus / as sysdba

 

SYS@clone> select count(*) from hr.emp_new;

 

테이블 조회해보기: 살아나 있어야 정상

 

2-4. OS 로 나가서 테이블 익스포트받기

SYS@clone> !

[oracle@oracle ~]$ exp system/oracle tables=hr.emp_new file=emp_new.dmp

[oracle@oracle ~]$ ls

 

2-5. 익스포트한 파일 전송하기

[oracle@oracle ~]$ . oraenv
ORACLE_SID = [ora11g] ? ora11g

[oracle@oracle ~]$ sqlplus / as sysdba

 

2-6. 테이블 조회해보기

 

select count(*) from hr.emp_new;

결과 안 나온다.

(결과 아직 안 나와야 정상이라는데 난 나오는데?... 왜 그러지...)

 

2-7. 임포트 작업

[oracle@oracle ~]$ imp system/oracle tables=emp_temp file=emp_temp.dmp fromuser=hr

 

2-8. 테이블 조회해보기

 

select count(*) from hr.emp_new;

107건이 조회되어야 정상

 

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

 

다시 실습할 때는 ps -ef | grep clone

 

kill -9 프로세스아이디 해서 프로세스 죽이고 (DB 내려감)

클론 폴더 날려버리기

(QUESTION. 근데 여기서 어떤 프로세스 죽인 거야? PMON?)

(ANSWER. 필수 백그라운드 프로세스 죽이면 DB 는 abort 로 내려가므로

필수 백그라운드 프로세스 중에 아무거나 죽이면 된다. 그런데 pmon 이 가장 위에 떠있기 때문에

pmon 을 죽인 것, 참고로 -9 는 죽이는 옵션)

관련글 더보기