오라클 RMAN 백업 및 복구

심우열·2023년 10월 23일
0

Oracle DB

목록 보기
8/8
post-thumbnail

1. RMAN?

  • Recovery Manager

데이터 베이스 파일 형식 및 복구에 대한 주요 기능

  • Block Validation
  • Online block-level recovery
  • Unused block compression
  • Online, multi-streamed backup
  • Native encryption
  • Data Recovery Advisor

2. RMAN 기본 구성 요소

1. Target Database

2. Catalog Database(for RMAN)

Recovery Catalog

  • 하나 이상의 대상 데이터베이스에 대한 RMAN 활동을 기록
  • 별도의 데이터베이스 및 스키마
  • 복구 카탈로그는 제어 파일이 손실 된 경우, RMAN Repository 메타 데이터를 포함하여제어 파일 손실 후 복원 및 복구 수행
  • Control 파일을 사용할 경우 오래 된 레코드를 덮어 쓸 수는 있지만 RMAN 은 사용자가 레코드를 삭제하지 않는 한, 카탈로그에 레코드를 영구적으로 보관

3. Recovery Manager Client

4. Flash Recovery Area

5. Media Management

  • 안씀

3. RMAN의 제약 사항

  • Open 상태에서 백업 받으러면 Archive log mode 로 운영 필요
  • 데이터베이스가 Mount 또는 Open 상태에서만 백업 가능
  • No Archive Mode 에서는 Clean 백업만 가능
  • 백업하려는 테이블 스페이스는 백업모드이면 안됨

4. RMAN 사용 방식

  • RMAN 과 연동 가능한 3rd party 백업 솔루션을 이용 (주로 테이프 백업시)
    -> 베리타스 넷 백업 등 ...
  • 직접 명령어를 쳐서 하는 것이 훨씬 유연성 있긴 하나 어려움,,,

5. RMAN 구조

6. RMAN 의 장점

  • 백업 받을때 블락 falut를 체크해줌
  • 이전의 백업을 이용해 해당 블록을 리커버리 할 수 있음

7. RMAN 의 단점

  • 백업시 많은 CPU 리소스를 사용(압축해야되기 때문)
  • 업무 부하가 적을 때 백업하는 것이 중요함

RMAN 을 이용한 백업

1. DB 기동 및 리스너 시작

1. DB 기동

[root@edu ~]# su - oracle
마지막 로그인: 화 1024 11:16:58 KST 2023 일시 pts/0
ORA19C@/home/oracle> sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Tue Oct 24 11:17:27 2023
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area  591395496 bytes
Fixed Size                  8899240 bytes
Variable Size             239075328 bytes
Database Buffers          335544320 bytes
Redo Buffers                7876608 bytes
Database mounted.
Database opened.

2. 리스너 시작

SQL> !lsnrctl start

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 24-OCT-2023 11:18:06

Copyright (c) 1991, 2019, Oracle.  All rights reserved.

Starting /oracle/product/19.0.0/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 19.0.0.0.0 - Production
System parameter file is /oracle/product/19.0.0/network/admin/listener.ora
Log messages written to /oracle/diag/tnslsnr/edu/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=edu)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=edu)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date                24-OCT-2023 11:18:06
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /oracle/product/19.0.0/network/admin/listener.ora
Listener Log File         /oracle/diag/tnslsnr/edu/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=edu)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully

2. archive log 로 변경

[root@edu ~]# mkdir /archive_catalog
[root@edu ~]# chown -R oracle:dba /archive_catalog/

SQL> startup nomount

SQL> alter system set log_archive_dest_1='localtion=/archive_catalog' scope=spfile;

System altered.

SQL> alter database mount
ORACLE instance started.

Total System Global Area  629144664 bytes
Fixed Size		    8899672 bytes
Variable Size		  197132288 bytes
Database Buffers	  415236096 bytes
Redo Buffers		    7876608 bytes
Database mounted.
SQL> alter database archivelog;

Database altered.

SQL> alter database open;

Database altered.

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /archive_catalog
Oldest online log sequence     53
Next log sequence to archive   55
Current log sequence           55

3. 테스트를 위한 테이블 스페이스 생성

ORA19C@/home/oracle> sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Tue Oct 24 11:24:02 2023
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> select instance_name from v$instance
  2  ;

INSTANCE_NAME
----------------
ORA19C

SQL> create tablespace test_ts DATAFILE '/oracle/oradata/ORA19C/test_ts.dbf' SIZE 50M;

Tablespace created.

SQL> create user test_user identified by test_user default tablespace test_ts;

User created.

SQL> alter user test_user quota unlimited on test_ts;

User altered.

SQL> grant connect,resource to test_user;

Grant succeeded.

SQL> connect test_user/test_user
Connected.
SQL> create table test_user.t1 as select * from all_objects;

Table created.

SQL> select * from tab;

TNAME
--------------------------------------------------------------------------------
TABTYPE        CLUSTERID
------------- ----------
T1
TABLE


SQL>

4. RMAN CONFIGURE COMMAND 설정 보기

ORA19C@/home/oracle> rman target / catalog rman/rman@catalog
# Catalog DB 인스턴스 없을때는
ORA19C@/home/oracle> rman target / nocatalog

Recovery Manager: Release 19.0.0.0.0 - Production on Mon Oct 23 01:15:42 2023
Version 19.3.0.0.0

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

connected to target database: ORA19C (DBID=1178632193)
connected to recovery catalog database

RMAN> show all;

RMAN configuration parameters for database with db_unique_name ORA19C are:

CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
-- Backup 보관 주기나 backup본의 갯수를 설정합니다.

CONFIGURE BACKUP OPTIMIZATION OFF; # default
-- 이미 backup 된 동일한(checkpoint SCN등) datafile, archived redolog, backup set이 있다면 skip 합니다.

CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
-- default backup device를 설정합니다.

CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
-- RMAN의 BACKUP이나 COPY 명령등의 수행후 자동으로 control file backup을 수행합니다.

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
-- autobackup되는 control file의 기본 format을 변경합니다.

CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
-- 특정 device에 automatic channel allocation 될때 channel의 갯수를 지정합니다.

CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
-- DATAFILE, CONTROL FILE의 backup set의 copy본 갯수를 지정합니다.

CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
-- ARCHIVELOG FILE의 backup set의 copy본 갯수를 지정합니다.

CONFIGURE MAXSETSIZE TO UNLIMITED; # default
-- backupset의 maximum size를 설정합니다.

CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
-- 암호화 백업 설정

CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
-- 암호화 백업 시 알고리즘 설정

CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
-- 압축 알고리즘 BZIP2(default), ZLIB와 같은 알고리즘을 이용하여 압축하여 백업할 수 있는데, BZIP2는 최고의 압축율을 자랑하며, ZLIB는 CPU에 많은 로드가 걸린다.

CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
-- flash recovery area의 archived redo log에 대한 삭제 여부를 설정합니다.

CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/oracle/app/oracle/product/11.2.0/db_1/dbs/snapcf_ORA19C.f'; # default
-- RMAN은 resync시 생성되는 임시 snapshot control file의 이름을 지정한다.

5. 백업대상 데이터 파일 조회

RMAN> report schema

Report of database schema for database with db_unique_name ORA19C

List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    760      SYSTEM               YES     /oracle/oradata/ORA19C/system01.dbf
2    550      SYSAUX               NO      /oracle/oradata/ORA19C/sysaux01.dbf
3    445      UNDOTBS1             YES     /oracle/oradata/ORA19C/undotbs01.dbf
4    5        USERS                NO      /oracle/oradata/ORA19C/users01.dbf
5    50       TEST_TS              NO      /oracle/oradata/ORA19C/test_ts.dbf

List of Temporary Files
=======================
File Size(MB) Tablespace           Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1    20       TEMP                 32767       /oracle/oradata/ORA19C/temp01.dbf

6. 컨트롤 파일 백업 설정

RMAN> configure controlfile autobackup on;

new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

RMAN> configure controlfile autobackup format for device type disk to '/backup/rman/cont/cf_%F';

new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/backup/rman/cont/cf_%F';
new RMAN configuration parameters are successfully stored

7. archivelog 파일의 자동 삭제 여부를 지정

# 아카이브 로그를 백업한 후 최근 2회분만 남겨놓고 삭제
RMAN> configure archivelog deletion policy to backed up 2 times to device type disk;

new RMAN configuration parameters:
CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 2 TIMES TO DISK;
new RMAN configuration parameters are successfully stored

# 설정 초기화
RMAN> configure archivelog deletion policy clear;

old RMAN configuration parameters:
CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 2 TIMES TO DISK;
RMAN configuration parameters are successfully reset to default value

8. RMAN Database 설정

1. Channel

RMAN> configure channel device type disk format '/backup/rman/database/%U';

new RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/backup/rman/database/%U';
new RMAN configuration parameters are successfully stored

RMAN> show channel;

RMAN configuration parameters for database with db_unique_name ORA19C are:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/backup/rman/database/%U';

2. Retention Policy 설정

# 7일로 백업 유지 기간 설정
RMAN> configure retention policy to recovery window of 7 days;

new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
new RMAN configuration parameters are successfully stored

RMAN> show retention policy;

RMAN configuration parameters for database with db_unique_name ORA19C are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;

# 백업 세트 개수 설정
RMAN> configure retention policy to redundancy 2;

old RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
new RMAN configuration parameters are successfully stored

RMAN> show retention policy;

RMAN configuration parameters for database with db_unique_name ORA19C are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;

# retention policy 초기화
RMAN> configure retention policy clear;

old RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
RMAN configuration parameters are successfully reset to default value

RMAN> show retention policy;

RMAN configuration parameters for database with db_unique_name ORA19C are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default

3. 백업 복사본 설정

# 백업 작업 시 2개의 복사본 생성
RMAN> configure datafile backup copies for device type disk to 2;

new RMAN configuration parameters:
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 2;
new RMAN configuration parameters are successfully stored

RMAN> show DATAFILE BACKUP COPIES;

RMAN configuration parameters for database with db_unique_name ORA19C are:
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 2;

# 초기화
RMAN> configure datafile backup copies for device type disk clear;

old RMAN configuration parameters:
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 2;
RMAN configuration parameters are successfully reset to default value

RMAN> show DATAFILE BACKUP COPIES;

RMAN configuration parameters for database with db_unique_name ORA19C are:
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

4. 백업 최적화 설정

# 백업 최적화 활성화 == 데이터 파일의 변경도니 부분만 백업(증분 백업)
RMAN> configure backup optimization on;

new RMAN configuration parameters:
CONFIGURE BACKUP OPTIMIZATION ON;
new RMAN configuration parameters are successfully stored

9. DB(incarnation) 정보 보기

  • RESETLOGS 작업을 수행할 때 마다 새로운 incarnation 이 생성
  • incarnation 은 데이터베이스의 논리적인 "버전" 또는 "상태"를 나타냄
RMAN> list incarnation of database;


List of Database Incarnations
DB Key  Inc Key DB Name  DB ID            STATUS  Reset SCN  Reset Time
------- ------- -------- ---------------- --- ---------- ----------
1       1       ORA19C   1178632193       CURRENT 1          06-JAN-23

10. 손상된 데이터 블록이 있는지 검증하는 방법

RMAN> validate database;

Starting validate at 24-OCT-23
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=23 device type=DISK
channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
input datafile file number=00001 name=/oracle/oradata/ORA19C/system01.dbf
input datafile file number=00002 name=/oracle/oradata/ORA19C/sysaux01.dbf
input datafile file number=00003 name=/oracle/oradata/ORA19C/undotbs01.dbf
input datafile file number=00005 name=/oracle/oradata/ORA19C/test_ts.dbf
input datafile file number=00004 name=/oracle/oradata/ORA19C/users01.dbf
channel ORA_DISK_1: validation complete, elapsed time: 00:00:03
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
1    OK     0              17164        97280           2914844
  File Name: /oracle/oradata/ORA19C/system01.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              64977
  Index      0              10017
  Other      0              5122

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
2    OK     0              45959        70400           2914861
  File Name: /oracle/oradata/ORA19C/sysaux01.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              3696
  Index      0              5724
  Other      0              15021

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
3    OK     0              278          56960           2914861
  File Name: /oracle/oradata/ORA19C/undotbs01.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              0
  Index      0              0
  Other      0              56682

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
4    OK     0              389          640             1539284
  File Name: /oracle/oradata/ORA19C/users01.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              30
  Index      0              19
  Other      0              202

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
5    OK     0              5360         6400            2902028
  File Name: /oracle/oradata/ORA19C/test_ts.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              889
  Index      0              0
  Other      0              151

channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
including current control file for validation
including current SPFILE in backup set
channel ORA_DISK_1: validation complete, elapsed time: 00:00:01
List of Control File and SPFILE
===============================
File Type    Status Blocks Failing Blocks Examined
------------ ------ -------------- ---------------
SPFILE       OK     0              2
Control File OK     0              646
Finished validate at 24-OCT-23

11. 손상된 아카이브로그 검증

profile
Dev Ops, "Git, Linux, Docker, Kubernetes, ansible, " .

0개의 댓글