설명
RMAN의 12c new feature인 Recover table을 테스트하는 시나리오.
기존에 클론 DB 생성 후 데이터 export 후 데이터 import하는 절차를 RMAN의 명령어 하나로 복구할 수 있게 된 기능
테스트 시나리오 요약
1. 테스트용 테이블 생성
2. 백업
3. 테스트용 테이블 DROP
4. 복구
5. 복구된 테이블 확인
테스트 상세
1. 테스트용 테이블 생성
SQL> create table test.test (co1l number);
Table created.
SQL> insert into test.test values(1);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test.test;
CO1L
----------
1
SQL> select sysdate from dual;
SYSDATE
-------------------
2019/03/30 11:19:19 ============> 복구될 시간
2. 백업
rman target /
RMAN> run {
allocate channel ch1 type disk format='/tmp/backup/%U_%T';
backup database;
}2> 3> 4>
released channel: ORA_DISK_1
allocated channel: ch1
channel ch1: SID=108 instance=bitek1 device type=DISK
Starting backup at 30-MAR-19
channel ch1: starting full datafile backup set
channel ch1: specifying datafile(s) in backup set
input datafile file number=00002 name=+DATA/BITEK/DATAFILE/sysaux.261.1002792885
input datafile file number=00001 name=+DATA/BITEK/DATAFILE/system.260.1002792865
input datafile file number=00003 name=+DATA/BITEK/DATAFILE/undotbs1.262.1002792889
input datafile file number=00004 name=+DATA/BITEK/DATAFILE/undotbs2.264.1002792943
input datafile file number=00006 name=+DATA/BITEK/DATAFILE/splex.296.1003324047
input datafile file number=00005 name=+DATA/BITEK/DATAFILE/users.265.1002792955
channel ch1: starting piece 1 at 30-MAR-19
channel ch1: finished piece 1 at 30-MAR-19
piece handle=/tmp/backup/2cttnpn9_1_1_20190330 tag=TAG20190330T110720 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:25
Finished backup at 30-MAR-19
Starting Control File and SPFILE Autobackup at 30-MAR-19
piece handle=/oracle/oracle/product/12.2.0/dbhome_1/dbs/c-120744536-20190330-03 comment=NONE
Finished Control File and SPFILE Autobackup at 30-MAR-19
released channel: ch1
3. 테스트용 테이블 drop
SQL> drop table test.test purge;
Table dropped.
SQL> desc test.test
ERROR:
ORA-04043: object test.test does not exist
4. 복구
RMAN> recover table "TEST"."TEST" until time "to_date('2019/03/30 11:19:19','yyyy/mm/dd hh24:mi:ss')" auxiliary destination '/oracle/oracle/recover';
=> 스키마(TEST)와 테이블명(TEST)은 큰따옴표로 묶고, 대문자를 반드시 써야한다. 그렇지 않으면 오류 발생
Starting recover at 30-MAR-19
current log archived
using channel ORA_DISK_1
RMAN-05026: warning: presuming following set of tablespaces applies to specified point-in-time
List of tablespaces expected to have UNDO segments
Tablespace SYSTEM
Tablespace UNDOTBS1
Tablespace UNDOTBS2
Creating automatic instance, with SID='prev'
initialization parameters used for automatic instance:
db_name=BITEK
db_unique_name=prev_pitr_BITEK
compatible=12.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/oracle/oracle
_system_trig_enabled=FALSE
sga_target=1024M
processes=200
db_create_file_dest=/oracle/oracle/recover
log_archive_dest_1='location=/oracle/oracle/recover'
#No auxiliary parameter file used
starting up automatic instance BITEK
Oracle instance started
Total System Global Area 1073741824 bytes
Fixed Size 8628936 bytes
Variable Size 281019704 bytes
Database Buffers 780140544 bytes
Redo Buffers 3952640 bytes
Automatic instance created
contents of Memory Script:
{
# set requested point in time
set until time "to_date('2019/03/30 11:19:19','yyyy/mm/dd hh24:mi:ss')";
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log
sql 'alter system archive log current';
}
executing Memory Script
executing command: SET until clause
Starting restore at 30-MAR-19
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=45 device type=DISK
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /oracle/oracle/product/12.2.0/dbhome_1/dbs/c-120744536-20190330-04
channel ORA_AUX_DISK_1: piece handle=/oracle/oracle/product/12.2.0/dbhome_1/dbs/c-120744536-20190330-04 tag=TAG20190330T111223
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/oracle/oracle/recover/BITEK/controlfile/o1_mf_g9xnlzst_.ctl
Finished restore at 30-MAR-19
sql statement: alter database mount clone database
sql statement: alter system archive log current
contents of Memory Script:
{
# set requested point in time
set until time "to_date('2019/03/30 11:19:19','yyyy/mm/dd hh24:mi:ss')";
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile 1 to new;
set newname for clone datafile 3 to new;
set newname for clone datafile 4 to new;
set newname for clone datafile 2 to new;
set newname for clone tempfile 1 to new;
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 1, 3, 4, 2;
switch clone datafile all;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
renamed tempfile 1 to /oracle/oracle/recover/BITEK/datafile/o1_mf_temp_%u_.tmp in control file
Starting restore at 30-MAR-19
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /oracle/oracle/recover/BITEK/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /oracle/oracle/recover/BITEK/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /oracle/oracle/recover/BITEK/datafile/o1_mf_undotbs2_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /oracle/oracle/recover/BITEK/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /tmp/backup/2ettnpvt_1_1_20190330
channel ORA_AUX_DISK_1: piece handle=/tmp/backup/2ettnpvt_1_1_20190330 tag=TAG20190330T111156
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 30-MAR-19
datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=1004268073 file name=/oracle/oracle/recover/BITEK/datafile/o1_mf_system_g9xnmcsd_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=1004268073 file name=/oracle/oracle/recover/BITEK/datafile/o1_mf_undotbs1_g9xnmcsw_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=7 STAMP=1004268073 file name=/oracle/oracle/recover/BITEK/datafile/o1_mf_undotbs2_g9xnmctb_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=8 STAMP=1004268073 file name=/oracle/oracle/recover/BITEK/datafile/o1_mf_sysaux_g9xnmcrw_.dbf
contents of Memory Script:
{
# set requested point in time
set until time "to_date('2019/03/30 11:19:19','yyyy/mm/dd hh24:mi:ss')";
# online the datafiles restored or switched
sql clone "alter database datafile 1 online";
sql clone "alter database datafile 3 online";
sql clone "alter database datafile 4 online";
sql clone "alter database datafile 2 online";
# recover and open database read only
recover clone database tablespace "SYSTEM", "UNDOTBS1", "UNDOTBS2", "SYSAUX";
sql clone 'alter database open read only';
}
executing Memory Script
executing command: SET until clause
sql statement: alter database datafile 1 online
sql statement: alter database datafile 3 online
sql statement: alter database datafile 4 online
sql statement: alter database datafile 2 online
Starting recover at 30-MAR-19
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 84 is already on disk as file +DATA/BITEK/ARCHIVELOG/2019_03_30/thread_1_seq_84.336.1004267561
archived log for thread 1 with sequence 85 is already on disk as file +DATA/BITEK/ARCHIVELOG/2019_03_30/thread_1_seq_85.337.1004267563
archived log for thread 1 with sequence 86 is already on disk as file +DATA/BITEK/ARCHIVELOG/2019_03_30/thread_1_seq_86.338.1004267991
archived log file name=+DATA/BITEK/ARCHIVELOG/2019_03_30/thread_1_seq_84.336.1004267561 thread=1 sequence=84
archived log file name=+DATA/BITEK/ARCHIVELOG/2019_03_30/thread_1_seq_85.337.1004267563 thread=1 sequence=85
archived log file name=+DATA/BITEK/ARCHIVELOG/2019_03_30/thread_1_seq_86.338.1004267991 thread=1 sequence=86
media recovery complete, elapsed time: 00:00:01
Finished recover at 30-MAR-19
sql statement: alter database open read only
contents of Memory Script:
{
sql clone "create spfile from memory";
shutdown clone immediate;
startup clone nomount;
sql clone "alter system set control_files =
''/oracle/oracle/recover/BITEK/controlfile/o1_mf_g9xnlzst_.ctl'' comment=
''RMAN set'' scope=spfile";
shutdown clone immediate;
startup clone nomount;
# mount database
sql clone 'alter database mount clone database';
}
executing Memory Script
sql statement: create spfile from memory
database closed
database dismounted
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 1073741824 bytes
Fixed Size 8628936 bytes
Variable Size 281019704 bytes
Database Buffers 780140544 bytes
Redo Buffers 3952640 bytes
sql statement: alter system set control_files = ''/oracle/oracle/recover/BITEK/controlfile/o1_mf_g9xnlzst_.ctl'' comment= ''RMAN set'' scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 1073741824 bytes
Fixed Size 8628936 bytes
Variable Size 281019704 bytes
Database Buffers 780140544 bytes
Redo Buffers 3952640 bytes
sql statement: alter database mount clone database
contents of Memory Script:
{
# set requested point in time
set until time "to_date('2019/03/30 11:19:19','yyyy/mm/dd hh24:mi:ss')";
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile 5 to new;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 5;
switch clone datafile all;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
Starting restore at 30-MAR-19
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=51 device type=DISK
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00005 to /oracle/oracle/recover/PREV_PITR_BITEK/datafile/o1_mf_users_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /tmp/backup/2ettnpvt_1_1_20190330
channel ORA_AUX_DISK_1: piece handle=/tmp/backup/2ettnpvt_1_1_20190330 tag=TAG20190330T111156
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 30-MAR-19
datafile 5 switched to datafile copy
input datafile copy RECID=10 STAMP=1004268201 file name=/oracle/oracle/recover/PREV_PITR_BITEK/datafile/o1_mf_users_g9xnrr06_.dbf
contents of Memory Script:
{
# set requested point in time
set until time "to_date('2019/03/30 11:19:19','yyyy/mm/dd hh24:mi:ss')";
# online the datafiles restored or switched
sql clone "alter database datafile 5 online";
# recover and open resetlogs
recover clone database tablespace "USERS", "SYSTEM", "UNDOTBS1", "UNDOTBS2", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script
executing command: SET until clause
sql statement: alter database datafile 5 online
Starting recover at 30-MAR-19
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 84 is already on disk as file +DATA/BITEK/ARCHIVELOG/2019_03_30/thread_1_seq_84.336.1004267561
archived log for thread 1 with sequence 85 is already on disk as file +DATA/BITEK/ARCHIVELOG/2019_03_30/thread_1_seq_85.337.1004267563
archived log for thread 1 with sequence 86 is already on disk as file +DATA/BITEK/ARCHIVELOG/2019_03_30/thread_1_seq_86.338.1004267991
archived log file name=+DATA/BITEK/ARCHIVELOG/2019_03_30/thread_1_seq_84.336.1004267561 thread=1 sequence=84
archived log file name=+DATA/BITEK/ARCHIVELOG/2019_03_30/thread_1_seq_85.337.1004267563 thread=1 sequence=85
archived log file name=+DATA/BITEK/ARCHIVELOG/2019_03_30/thread_1_seq_86.338.1004267991 thread=1 sequence=86
media recovery complete, elapsed time: 00:00:00
Finished recover at 30-MAR-19
database opened
contents of Memory Script:
{
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/oracle/oracle/recover''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/oracle/oracle/recover''";
}
executing Memory Script
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/oracle/oracle/recover''
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/oracle/oracle/recover''
Performing export of tables...
EXPDP> Starting "SYS"."TSPITR_EXP_prev_Fqyg":
EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
EXPDP> . . exported "TEST"."TEST" 5.054 KB 1 rows
EXPDP> Master table "SYS"."TSPITR_EXP_prev_Fqyg" successfully loaded/unloaded
EXPDP> ******************************************************************************
EXPDP> Dump file set for SYS.TSPITR_EXP_prev_Fqyg is:
EXPDP> /oracle/oracle/recover/tspitr_prev_99272.dmp
EXPDP> Job "SYS"."TSPITR_EXP_prev_Fqyg" successfully completed at Sat Mar 30 11:25:42 2019 elapsed 0 00:01:23
Export completed
contents of Memory Script:
{
# shutdown clone before import
shutdown clone abort
}
executing Memory Script
Oracle instance shut down
Performing import of tables...
IMPDP> Master table "SYS"."TSPITR_IMP_prev_Fyhj" successfully loaded/unloaded
IMPDP> Starting "SYS"."TSPITR_IMP_prev_Fyhj":
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
IMPDP> . . imported "TEST"."TEST" 5.054 KB 1 rows
IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
IMPDP> Job "SYS"."TSPITR_IMP_prev_Fyhj" successfully completed at Sat Mar 30 11:26:23 2019 elapsed 0 00:00:14
Import completed
Removing automatic instance
Automatic instance removed
auxiliary instance file /oracle/oracle/recover/BITEK/datafile/o1_mf_temp_g9xnockf_.tmp deleted
auxiliary instance file /oracle/oracle/recover/PREV_PITR_BITEK/onlinelog/o1_mf_4_g9xns44l_.log deleted
auxiliary instance file /oracle/oracle/recover/PREV_PITR_BITEK/onlinelog/o1_mf_3_g9xns32o_.log deleted
auxiliary instance file /oracle/oracle/recover/PREV_PITR_BITEK/onlinelog/o1_mf_2_g9xnrzx9_.log deleted
auxiliary instance file /oracle/oracle/recover/PREV_PITR_BITEK/onlinelog/o1_mf_1_g9xnrzfl_.log deleted
auxiliary instance file /oracle/oracle/recover/PREV_PITR_BITEK/datafile/o1_mf_users_g9xnrr06_.dbf deleted
auxiliary instance file /oracle/oracle/recover/BITEK/datafile/o1_mf_sysaux_g9xnmcrw_.dbf deleted
auxiliary instance file /oracle/oracle/recover/BITEK/datafile/o1_mf_undotbs2_g9xnmctb_.dbf deleted
auxiliary instance file /oracle/oracle/recover/BITEK/datafile/o1_mf_undotbs1_g9xnmcsw_.dbf deleted
auxiliary instance file /oracle/oracle/recover/BITEK/datafile/o1_mf_system_g9xnmcsd_.dbf deleted
auxiliary instance file /oracle/oracle/recover/BITEK/controlfile/o1_mf_g9xnlzst_.ctl deleted
auxiliary instance file tspitr_prev_99272.dmp deleted
Finished recover at 30-MAR-19
5. 복구된 테이블 확인
SQL> select * from test.test;
CO1L
----------
1
※ 추가내용
recover table "TEST"."TEST" until time "to_date('2019/03/30 16:01:17','yyyy/mm/dd hh24:mi:ss')" auxiliary destination '/oracle/oracle/recover'
remap table "TEST"."TEST":"TEST_OLD";
=> 기존에 테이블이 존재한다면 remap table 기능을 이용하여 복구도 가능하다.