RMAN 으로 rawdevice 백업 복구하기

 

RMAN 으로 rawdevice 백업 복구하기

 

테스트 1 : Raw device 상태의 데이터파일을 RMAN 의 backupset 으로 백업 받은 후 정상적으로 복구 되는지 확인

Step 1. 현재상태 확인

[oracle@localhost ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Wed Feb 1 11:05:19 2012
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> !vi dd.sql
set line 200
col tablespace_name for a10
col file_name for a45
select tablespace_name,bytes/1024/1024 MB,file_name from dba_data_files
/
:wq!

SQL> @dd <- Data file 상태 확인
TABLESPACE          MB         FILE_NAME
------------------- ---------- ---------------------------------------------
USERS                        5 /dev/raw/raw4
SYSAUX                     250 /dev/raw/raw2
UNDOTBS1                    30 /dev/raw/raw3
SYSTEM                     440 /dev/raw/raw1
EXAMPLE                    100 /dev/raw/raw5
SQL> !vi log.sql <- Redo log file 상태 확인
set line 200
col group# for 999
col member for a20
col mb for 999
col seq# for 999
col archived for a4
col status for a8
select a.group#,a.member,b.bytes/1024/1024 MB,b.sequence# "SEQ#" ,b.archived,b.status
from v$logfile a, v$log b
where a.group#=b.group#
order by 1,2
/
:wq!

SQL> @log
GROUP#     MEMBER               MB     SEQ#    ARCH       STATUS
---------- -------------------- ------ ------- ---------- -----------
1          /dev/raw/raw10           50       4 NO         CURRENT
1          /dev/raw/raw9            50       4 NO         CURRENT
2          /dev/raw/raw11           50       2 YES        INACTIVE
2          /dev/raw/raw12           50       2 YES        INACTIVE
3          /dev/raw/raw13           50       3 YES        INACTIVE
3          /dev/raw/raw14           50       3 YES        INACTIVE
6 rows selected.
SQL> select name from v$controlfile;
NAME
---------------------------------
/dev/raw/raw6
/dev/raw/raw7
/dev/raw/raw8
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /data/arc2
Oldest online log sequence 2
Next log sequence to archive 4
Current log sequence 4

Step 2. RMAN 을 사용하여 전체 백업 (백업경로는 /data/backup/rman/ )

[oracle@localhost ~]$ rman target /
Recovery Manager: Release 10.2.0.5.0 - Production on Wed Feb 1 10:47:50 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: TESTDB (DBID=2557423915)

RMAN> backup as compressed backupset
2> format '/data/backup/rman/%U_%T'
3> database;

Starting backup at 01-FEB-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=144 devtype=DISK
channel ORA_DISK_1: starting compressed full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/dev/raw/raw1
input datafile fno=00003 name=/dev/raw/raw2
input datafile fno=00005 name=/dev/raw/raw5
input datafile fno=00002 name=/dev/raw/raw3
input datafile fno=00004 name=/dev/raw/raw4
channel ORA_DISK_1: starting piece 1 at 01-FEB-12
channel ORA_DISK_1: finished piece 1 at 01-FEB-12
piece handle=/data/backup/rman/01n27hl4_1_1_20120201 tag=TAG20120201T104907
comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:36
channel ORA_DISK_1: starting compressed full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 01-FEB-12
channel ORA_DISK_1: finished piece 1 at 01-FEB-12
piece handle=/data/backup/rman/02n27hm8_1_1_20120201 tag=TAG20120201T104907
comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 01-FEB-12
[oracle@localhost ~]$ ls -lSh /data/backup/rman/
합계 112M
-rw-r----- 1 oracle dba 111M 2월 1 10:49 01n27hl4_1_1_20120201
-rw-r----- 1 oracle dba 1.1M 2월 1 10:49 02n27hm8_1_1_20120201

Step 3. 테스트용 테이블 scott.gogak 테이블 생성 후 장애 발생시킴

[oracle@localhost ~]$ sqlplus scott/tiger
SQL*Plus: Release 10.2.0.5.0 - Production on Wed Feb 1 11:14:21 2012
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> create table gogak (no number, name varchar2(10)) tablespace users;
Table created.

SQL> insert into gogak values (1,'AAA');
1 row created.

SQL> insert into gogak values (2,'BBB');
1 row created.

SQL> commit;
Commit complete.

SQL> select * from gogak;
NO         NAME
---------- ----------
1          AAA
2          BBB

SQL> conn / as sysdba
Connected.

SQL> @dd
TABLESPACE       MB         FILE_NAME
---------------- ---------- ---------------------------------------------
USERS                     5 /dev/raw/raw4 <- 이 파일에 장애 발생시킴
SYSAUX                  250 /dev/raw/raw2
UNDOTBS1                 30 /dev/raw/raw3
SYSTEM                  440 /dev/raw/raw1
EXAMPLE                 100 /dev/raw/raw5

SQL> !dd if=/dev/zero of=/dev/raw/raw4 bs=8k
dd: writing '/dev/raw/raw4': 장치에 남은 공간이 없음
12801+0개의 레코드를 입력하였습니다
12800+0개의 레코드를 출력하였습니다

SQL> alter tablespace users offline immediate;
Tablespace altered.

SQL> alter tablespace users online;
alter tablespace users online
*
ERROR at line 1:
ORA-01122: database file 4 failed verification check
ORA-01110: data file 4: '/dev/raw/raw4'
ORA-01210: data file header is media corrupt

SQL> select * from scott.gogak;
select * from scott.gogak
*
ERROR at line 1:
ORA-00376: file 4 cannot be read at this time
ORA-01110: data file 4: '/dev/raw/raw4'

Step 4. RMAN 으로 해당 장애 복구하기

[oracle@localhost ~]$ rman target /
Recovery Manager: Release 10.2.0.5.0 - Production on Wed Feb 1 11:19:20 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: TESTDB (DBID=2557423915)

RMAN> run {
2> sql "alter tablespace users offline immediate";
3> restore tablespace users;
4> recover tablespace users;
5> sql "alter tablespace users online";
6> }

sql statement: alter tablespace users offline immediate
Starting restore at 01-FEB-12
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00004 to /dev/raw/raw4
channel ORA_DISK_1: reading from backup piece /data/backup/rman/01n27hl4_1_1_20120201
channel ORA_DISK_1: restored backup piece 1
piece handle=/data/backup/rman/01n27hl4_1_1_20120201 tag=TAG20120201T104907
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
Finished restore at 01-FEB-12
Starting recover at 01-FEB-12
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished recover at 01-FEB-12
sql statement: alter tablespace users online
RMAN> exit
Recovery Manager complete.

[oracle@localhost ~]$ sqlplus scott/tiger
SQL*Plus: Release 10.2.0.5.0 - Production on Wed Feb 1 11:21:53 2012
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select * from gogak;
NO         NAME
---------- ----------
1          AAA
2          BBB

위와 같이 rawdevice 도 RMAN 으로 백업 및 복구가 가능합니다.

 

테스트 2. Raw device 상태의 데이터 파일을 backupset 으로 증분 백업 가능한지와 복구 가능한지 테스트

Step 1. 현재 상태 확인

[oracle@localhost ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Wed Feb 1 11:24:25 2012
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> @dd
TABLESPACE        MB         FILE_NAME
----------------- ---------- ---------------------------------------------
USERS                      5 /dev/raw/raw4
SYSAUX                   250 /dev/raw/raw2
UNDOTBS1                  30 /dev/raw/raw3
SYSTEM                   440 /dev/raw/raw1
EXAMPLE                  100 /dev/raw/raw5
SQL> @log
GROUP#     MEMBER               MB     SEQ#    ARCH       STATUS
---------- -------------------- ------ ------- ---------- -----------
1          /dev/raw/raw10           50       4 NO         CURRENT
1          /dev/raw/raw9            50       4 NO         CURRENT
2          /dev/raw/raw11           50       2 YES        INACTIVE
2          /dev/raw/raw12           50       2 YES        INACTIVE
3          /dev/raw/raw13           50       3 YES        INACTIVE
3          /dev/raw/raw14           50       3 YES        INACTIVE
6 rows selected.
SQL> select name from v$controlfile;
NAME
----------------------------------------
/dev/raw/raw6
/dev/raw/raw7
/dev/raw/raw8

Step 2. RMAN 을 사용하여 증분 백업을 여러 차례 수행합니다.

[oracle@localhost ~]$ rman target /
Recovery Manager: Release 10.2.0.5.0 - Production on Wed Feb 1 11:28:05 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: TESTDB (DBID=2557423915)

RMAN> backup as compressed backupset
2> incremental level 0
3> format '/data/backup/rman/%U_%T'
4> database;

Starting backup at 01-FEB-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=145 devtype=DISK
channel ORA_DISK_1: starting compressed full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/dev/raw/raw1
input datafile fno=00003 name=/dev/raw/raw2
input datafile fno=00005 name=/dev/raw/raw5
input datafile fno=00002 name=/dev/raw/raw3
input datafile fno=00004 name=/dev/raw/raw4
channel ORA_DISK_1: starting piece 1 at 01-FEB-12
channel ORA_DISK_1: finished piece 1 at 01-FEB-12
piece handle=/data/backup/rman/03n27jur_1_1_20120201 tag=TAG20120201T112827
comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting compressed full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 01-FEB-12
channel ORA_DISK_1: finished piece 1 at 01-FEB-12
piece handle=/data/backup/rman/04n27jvu_1_1_20120201 tag=TAG20120201T112827
comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 01-FEB-12

다른 터미널에서 데이터 변경을 위해 테이블 생성하고 데이터 입력합니다.

SQL> create table scott.gogak2 (no number,name varchar2(10)) tablespace users;
Table created.

SQL> insert into scott.gogak2 values (1,'CCC');
1 row created.

SQL> insert into scott.gogak2 values (2,'DDD');
1 row created.

SQL> commit;
Commit complete.

RMAN 터미널에서 증분 백업을 수행합니다.

RMAN> backup as compressed backupset
2> incremental level 2
3> format '/data/backup/rman/%U_%T'
4> tablespace users;

Starting backup at 01-FEB-12
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed incremental level 2 datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00004 name=/dev/raw/raw4
channel ORA_DISK_1: starting piece 1 at 01-FEB-12
channel ORA_DISK_1: finished piece 1 at 01-FEB-12
piece handle=/data/backup/rman/05n27knu_1_1_20120201 tag=TAG20120201T114150
comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 01-FEB-12

Step 3. 장애를 발생 시킵니다

SQL> @dd
TABLESPACE        MB         FILE_NAME
----------------- ---------- ---------------------------------------------
USERS                      5 /dev/raw/raw4
SYSAUX                   250 /dev/raw/raw2
UNDOTBS1                  30 /dev/raw/raw3
SYSTEM                   440 /dev/raw/raw1
EXAMPLE                  100 /dev/raw/raw5

SQL> !dd if=/dev/zero of=/dev/raw/raw4 bs=8k <- 장애를 발생시킵니다
dd: writing '/dev/raw/raw4': 장치에 남은 공간이 없음
12801+0개의 레코드를 입력하였습니다
12800+0개의 레코드를 출력하였습니다

SQL> alter tablespace users offline immediate;
Tablespace altered.

SQL> alter tablespace users online;
alter tablespace users online
*
ERROR at line 1:
ORA-01122: database file 4 failed verification check
ORA-01110: data file 4: '/dev/raw/raw4'
ORA-01210: data file header is media corrupt

SQL> select * from scott.gogak2;
select * from scott.gogak2
*
ERROR at line 1:
ORA-00376: file 4 cannot be read at this time
ORA-01110: data file 4: '/dev/raw/raw4'

Step 4. RMAN 으로 복구 후 확인합니다.

RMAN> run {
2> restore tablespace users;
3> recover tablespace users;
4> sql "alter tablespace users online" ;
5> }

Starting restore at 01-FEB-12
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00004 to /dev/raw/raw4
channel ORA_DISK_1: reading from backup piece /data/backup/rman/05n27knu_1_1_20120201
channel ORA_DISK_1: restored backup piece 1
piece handle=/data/backup/rman/05n27knu_1_1_20120201 tag=TAG20120201T114150
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 01-FEB-12
Starting recover at 01-FEB-12
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished recover at 01-FEB-12
sql statement: alter tablespace users online

SQL> select * from scott.gogak2;
NO         NAME
---------- ----------
1          CCC
2          DDD

 

테스트 3. RMAN 으로 rawdevice 상태의 데이터 파일을 rawdevice 형태로 백업 받은 후 복구 가능한지 테스트

Step 1. 현재 상태 확인

RMAN> report schema;
Report of database schema
List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
   1      440 SYSTEM                   *** /dev/raw/raw1
   2       30 UNDOTBS1                 *** /dev/raw/raw3
   3      250 SYSAUX                   *** /dev/raw/raw2
   4        5 USERS                    *** /dev/raw/raw4
   5      100 EXAMPLE                  *** /dev/raw/raw5
   
List of Temporary Files
=======================
File Size(MB) Tablespace           Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
   1       20 TEMP                         100 /dev/raw/raw15

Step 2. RMAN 으로 Raw device 파일 백업 수행

RMAN> copy
2> datafile 1 to '/data/backup/rman/system' ,
3> datafile 2 to '/data/backup/rman/undotbs1' ,
4> datafile 3 to '/data/backup/rman/sysaux' ,
5> datafile 4 to '/data/backup/rman/users' ,
6> datafile 5 to '/data/backup/rman/example' ;

Starting backup at 01-FEB-12
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile fno=00001 name=/dev/raw/raw1
output filename=/data/backup/rman/system tag=TAG20120201T115814 recid=9
stamp=774100724
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile copy
input datafile fno=00003 name=/dev/raw/raw2
output filename=/data/backup/rman/sysaux tag=TAG20120201T115814 recid=10
stamp=774100744
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:16
channel ORA_DISK_1: starting datafile copy
input datafile fno=00005 name=/dev/raw/raw5
output filename=/data/backup/rman/example tag=TAG20120201T115814 recid=11
stamp=774100749
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile fno=00002 name=/dev/raw/raw3
output filename=/data/backup/rman/undotbs1 tag=TAG20120201T115814 recid=12
stamp=774100754
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile fno=00004 name=/dev/raw/raw4
output filename=/data/backup/rman/users tag=TAG20120201T115814 recid=13
stamp=774100756
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 01-FEB-12

다른 창에서 백업 파일을 확인합니다

[oracle@localhost rman]$ pwd
/data/backup/rman

[oracle@localhost rman]$ ls –lSh
-rw-r----- 1 oracle dba 441M 2?? 1 11:58 system
-rw-r----- 1 oracle dba 251M 2?? 1 11:59 sysaux
-rw-r----- 1 oracle dba 101M 2?? 1 11:59 example
-rw-r----- 1 oracle dba 31M 2?? 1 11:59 undotbs1
-rw-r----- 1 oracle dba 5.1M 2?? 1 11:59 users

Step 3. 테스트용 테이블 scott.gogak3 을 생성 후 장애를 발생시킵니다.

SQL> create table scott.gogak3 (no number, name varchar2(10))
2 tablespace users;
Table created.

SQL> insert into scott.gogak3 values (1,'EEE');
1 row created.

SQL> insert into scott.gogak3 values (2,'FFF');
1 row created.

SQL> commit;
Commit complete.

SQL> select * from scott.gogak3;
NO         NAME
---------- ----------
         1 EEE
         2 FFF

SQL> @dd
TABLESPACE        MB         FILE_NAME
----------------- ---------- ---------------------------------------------
USERS                      5 /dev/raw/raw4
SYSAUX                   250 /dev/raw/raw2
UNDOTBS1                  30 /dev/raw/raw3
SYSTEM                   440 /dev/raw/raw1
EXAMPLE                  100 /dev/raw/raw5

SQL> !dd if=/dev/zero of=/dev/raw/raw4 bs=8k
dd: writing '/dev/raw/raw4': 장치에 남은 공간이 없음
12801+0개의 레코드를 입력하였습니다
12800+0개의 레코드를 출력하였습니다

SQL> alter tablespace users offline immediate;
Tablespace altered.

SQL> alter tablespace users online;
alter tablespace users online
*
ERROR at line 1:
ORA-01122: database file 4 failed verification check
ORA-01110: data file 4: '/dev/raw/raw4'
ORA-01210: data file header is media corrupt

SQL> select * from scott.gogak3;
select * from scott.gogak3
*
ERROR at line 1:
ORA-00376: file 4 cannot be read at this time
ORA-01110: data file 4: '/dev/raw/raw4'

Step 4. RMAN 으로 파일을 복원 한 후 복구합니다.

RMAN> restore tablespace users;
Starting restore at 01-FEB-12
using channel ORA_DISK_1
channel ORA_DISK_1: restoring datafile 00004
input datafile copy recid=13 stamp=774100756 filename=/data/backup/rman/users
destination for restore of datafile 00004: /dev/raw/raw4
channel ORA_DISK_1: copied datafile copy of datafile 00004
output filename=/dev/raw/raw4 recid=14 stamp=774101682
Finished restore at 01-FEB-12

RMAN 에서 자동으로 copy 된 raw device 를 찾아서 복원하는 것을 알 수 있습니다.

RMAN> recover tablespace users;
Starting recover at 01-FEB-12
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 01-FEB-12

sqlplus 창에서 데이터가 복구되었는지 확인합니다.

SQL> alter tablespace users online;
Tablespace altered.

SQL> select * from scott.gogak3;
NO         NAME
---------- ----------
         1 EEE
         2 FFF

정상적으로 복구가 된 것을 알 수 있습니다.

위에서 살펴본 바와 같이 rawdvice 로 구성된 데이터베이스도 RMAN 으로 동일하게 관리할 수 있습니다.

소셜 미디어로 공유하기

You may also like...

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.