반응형
이전에 포스팅한 recover table 글을 보고 다시 테스트해보았습니다.
해당 기능은 아래글에 정리를 해놨습니다.
https://bae9086.tistory.com/22?category=825635
시나리오는 아래와 같습니다.
1.rman full backup
2.테이블 truncate
3.recover table
1.rman full backup
RMAN> BACKUP AS COMPRESSED BACKUPSET DATABASE;
확인
RMAN> list backup;
...생략
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
141 Full 21.55G DISK 00:33:41 01-JUL-22
BP Key: 163 Status: AVAILABLE Compressed: YES Tag: TAG20220701T093948
Piece Name: /ora_work/rman/db_backup_DBARAC_5611gmn5_1_1_20220701.RMAN.bk
List of Datafiles in backup set 141
File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name
---- -- ---- ---------- --------- ----------- ------ ----
1 Full 9386020138928 01-JUL-22 NO +DG_DATA01/DBARAC/DATAFILE/system.257.1079561135
2 Full 9386020138928 01-JUL-22 NO +DG_DATA01/DBARAC/DATAFILE/mkpark_test.292.1104339801
3 Full 9386020138928 01-JUL-22 NO +DG_DATA01/DBARAC/DATAFILE/sysaux.258.1079561177
4 Full 9386020138928 01-JUL-22 NO +DG_DATA01/DBARAC/DATAFILE/undotbs1.259.1079561201
5 Full 9386020138928 01-JUL-22 NO +DG_DATA01/DBARAC/DATAFILE/undotbs2.265.1079561303
7 Full 9386020138928 01-JUL-22 NO +DG_DATA01/DBARAC/DATAFILE/users.260.1079561203
9 Full 9386020138928 01-JUL-22 NO +DG_DATA01/DBARAC/DATAFILE/ts_data01.287.1091539667
10 Full 9386020138928 01-JUL-22 NO +DG_DATA01/DBARAC/DATAFILE/ts_data01.288.1092476729
13 Full 9386020138928 01-JUL-22 NO +DG_DATA01/DBARAC/DATAFILE/my_data.290.1094207519
14 Full 9386020138928 01-JUL-22 NO +DG_DATA01/DBARAC/DATAFILE/my_data.293.1094219363
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
142 Full 1.20M DISK 00:00:01 01-JUL-22
BP Key: 164 Status: AVAILABLE Compressed: YES Tag: TAG20220701T093948
Piece Name: /ora_work/rman/db_backup_DBARAC_5711gome_1_1_20220701.RMAN.bk
SPFILE Included: Modification time: 30-JUN-22
SPFILE db_unique_name: DBARAC
Control File Included: Ckp SCN: 9386020143418 Ckp time: 01-JUL-22
2.테이블 확인 및 truncate
YSBAE@dbarac1 SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ------------------ ---------- ---------- ----------
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 30
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.
--시간 기반 복구를 하기 때문에 해당 시점의 시간을 알아야 합니다.
YSBAE@dbarac1 SQL> alter session set nls_date_format='YYYY/MM/DD HH24:MI:SS';
Session altered.
YSBAE@dbarac1 SQL> select sysdate from dual;
SYSDATE
-------------------
2022/07/01 10:55:02
YSBAE@dbarac1 SQL> truncate table emp;
Table truncated.
YSBAE@dbarac1 SQL> select * from emp;
no rows selected
3.recover table 수행
RMAN 의 로그를 따라가보면 clone DB를 auxiliary destination 에 파일들을 복사하여 만들고 그 DB에서 해당 테이블을 exp 후 대상 DB에 imp하는 과정을 거칩니다.
자동으로 해주니 편하네요..
기존 테이블을 rename
YSBAE@dbarac1 SQL> rename emp to emp_bak;
Table renamed.
$ rman target /
RMAN> recover table ysbae.emp until time "to_date('2022/07/01 10:55:00', 'yyyy-mm-dd:hh24:mi:ss')" auxiliary destination '/ora_work/dba/ysbae';
Starting recover at 01-JUL-22
using target database control file instead of recovery catalog
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=4 instance=dbarac1 device type=DISK
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='aaml'
initialization parameters used for automatic instance:
db_name=DBARAC
db_unique_name=aaml_pitr_DBARAC
compatible=12.2.0
db_block_size=8192
db_files=4000
diagnostic_dest=/oracle/db/base
_system_trig_enabled=FALSE
sga_target=6144M
processes=200
db_create_file_dest=/ora_work/dba/ysbae
log_archive_dest_1='location=/ora_work/dba/ysbae'
#No auxiliary parameter file used
starting up automatic instance DBARAC
Oracle instance started
Total System Global Area 6442450944 bytes
Fixed Size 8729096 bytes
Variable Size 1157631480 bytes
Database Buffers 5268045824 bytes
Redo Buffers 8044544 bytes
Automatic instance created
contents of Memory Script:
{
# set requested point in time
set until time "to_date('2022/07/01 10:55:00', '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 01-JUL-22
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=297 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 /ora_work/rman/db_backup_DBARAC_5711gome_1_1_20220701.RMAN.bk
channel ORA_AUX_DISK_1: piece handle=/ora_work/rman/db_backup_DBARAC_5711gome_1_1_20220701.RMAN.bk tag=TAG20220701T093948
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/ora_work/dba/ysbae/DBARAC/controlfile/o1_mf_kcwopqs6_.ctl
Finished restore at 01-JUL-22
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('2022/07/01 10:55:00', '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 4 to new;
set newname for clone datafile 5 to new;
set newname for clone datafile 3 to new;
set newname for clone tempfile 1 to new;
set newname for clone tempfile 2 to new;
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 1, 4, 5, 3;
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
executing command: SET NEWNAME
renamed tempfile 1 to /ora_work/dba/ysbae/DBARAC/datafile/o1_mf_temp_%u_.tmp in control file
renamed tempfile 2 to /ora_work/dba/ysbae/DBARAC/datafile/o1_mf_temp_ys_%u_.tmp in control file
Starting restore at 01-JUL-22
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 /ora_work/dba/ysbae/DBARAC/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /ora_work/dba/ysbae/DBARAC/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /ora_work/dba/ysbae/DBARAC/datafile/o1_mf_undotbs2_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /ora_work/dba/ysbae/DBARAC/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /ora_work/rman/db_backup_DBARAC_5611gmn5_1_1_20220701.RMAN.bk
channel ORA_AUX_DISK_1: piece handle=/ora_work/rman/db_backup_DBARAC_5611gmn5_1_1_20220701.RMAN.bk tag=TAG20220701T093948
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:11:01
Finished restore at 01-JUL-22
datafile 1 switched to datafile copy
input datafile copy RECID=12 STAMP=1108898310 file name=/ora_work/dba/ysbae/DBARAC/datafile/o1_mf_system_kcwoq1hz_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=13 STAMP=1108898310 file name=/ora_work/dba/ysbae/DBARAC/datafile/o1_mf_undotbs1_kcwoq1g6_.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=14 STAMP=1108898310 file name=/ora_work/dba/ysbae/DBARAC/datafile/o1_mf_undotbs2_kcwoq1gv_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=15 STAMP=1108898310 file name=/ora_work/dba/ysbae/DBARAC/datafile/o1_mf_sysaux_kcwoq1jm_.dbf
contents of Memory Script:
{
# set requested point in time
set until time "to_date('2022/07/01 10:55:00', 'yyyy-mm-dd:hh24:mi:ss')";
# online the datafiles restored or switched
sql clone "alter database datafile 1 online";
sql clone "alter database datafile 4 online";
sql clone "alter database datafile 5 online";
sql clone "alter database datafile 3 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 4 online
sql statement: alter database datafile 5 online
sql statement: alter database datafile 3 online
Starting recover at 01-JUL-22
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 3124 is already on disk as file +DG_RECO01/DBARAC/ARCHIVELOG/2022_07_01/thread_1_seq_3124.693.1108897603
archived log for thread 2 with sequence 975 is already on disk as file +DG_RECO01/DBARAC/ARCHIVELOG/2022_07_01/thread_2_seq_975.692.1108897597
archived log file name=+DG_RECO01/DBARAC/ARCHIVELOG/2022_07_01/thread_1_seq_3124.693.1108897603 thread=1 sequence=3124
archived log file name=+DG_RECO01/DBARAC/ARCHIVELOG/2022_07_01/thread_2_seq_975.692.1108897597 thread=2 sequence=975
media recovery complete, elapsed time: 00:00:04
Finished recover at 01-JUL-22
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 =
''/ora_work/dba/ysbae/DBARAC/controlfile/o1_mf_kcwopqs6_.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 6442450944 bytes
Fixed Size 8729096 bytes
Variable Size 1157631480 bytes
Database Buffers 5268045824 bytes
Redo Buffers 8044544 bytes
sql statement: alter system set control_files = ''/ora_work/dba/ysbae/DBARAC/controlfile/o1_mf_kcwopqs6_.ctl'' comment= ''RMAN set'' scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 6442450944 bytes
Fixed Size 8729096 bytes
Variable Size 1157631480 bytes
Database Buffers 5268045824 bytes
Redo Buffers 8044544 bytes
sql statement: alter database mount clone database
contents of Memory Script:
{
# set requested point in time
set until time "to_date('2022/07/01 10:55:00', 'yyyy-mm-dd:hh24:mi:ss')";
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile 7 to new;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 7;
switch clone datafile all;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
Starting restore at 01-JUL-22
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=67 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 00007 to /ora_work/dba/ysbae/AAML_PITR_DBARAC/datafile/o1_mf_users_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /ora_work/rman/db_backup_DBARAC_5611gmn5_1_1_20220701.RMAN.bk
channel ORA_AUX_DISK_1: piece handle=/ora_work/rman/db_backup_DBARAC_5611gmn5_1_1_20220701.RMAN.bk tag=TAG20220701T093948
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:08:12
Finished restore at 01-JUL-22
datafile 7 switched to datafile copy
input datafile copy RECID=17 STAMP=1108898900 file name=/ora_work/dba/ysbae/AAML_PITR_DBARAC/datafile/o1_mf_users_kcwpgr4y_.dbf
contents of Memory Script:
{
# set requested point in time
set until time "to_date('2022/07/01 10:55:00', 'yyyy-mm-dd:hh24:mi:ss')";
# online the datafiles restored or switched
sql clone "alter database datafile 7 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 7 online
Starting recover at 01-JUL-22
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 3124 is already on disk as file +DG_RECO01/DBARAC/ARCHIVELOG/2022_07_01/thread_1_seq_3124.693.1108897603
archived log for thread 2 with sequence 975 is already on disk as file +DG_RECO01/DBARAC/ARCHIVELOG/2022_07_01/thread_2_seq_975.692.1108897597
archived log file name=+DG_RECO01/DBARAC/ARCHIVELOG/2022_07_01/thread_1_seq_3124.693.1108897603 thread=1 sequence=3124
archived log file name=+DG_RECO01/DBARAC/ARCHIVELOG/2022_07_01/thread_2_seq_975.692.1108897597 thread=2 sequence=975
media recovery complete, elapsed time: 00:00:00
Finished recover at 01-JUL-22
database opened
contents of Memory Script:
{
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/ora_work/dba/ysbae''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/ora_work/dba/ysbae''";
}
executing Memory Script
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/ora_work/dba/ysbae''
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/ora_work/dba/ysbae''
Performing export of tables...
EXPDP> Starting "SYS"."TSPITR_EXP_aaml_aBlc":
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/STATISTICS/MARKER
EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
EXPDP> . . exported "YSBAE"."EMP" 8.781 KB 14 rows
EXPDP> Master table "SYS"."TSPITR_EXP_aaml_aBlc" successfully loaded/unloaded
EXPDP> ******************************************************************************
EXPDP> Dump file set for SYS.TSPITR_EXP_aaml_aBlc is:
EXPDP> /ora_work/dba/ysbae/tspitr_aaml_92089.dmp
EXPDP> Job "SYS"."TSPITR_EXP_aaml_aBlc" successfully completed at Fri Jul 1 11:29:27 2022 elapsed 0 00:00:30
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_aaml_aDrf" successfully loaded/unloaded
IMPDP> Starting "SYS"."TSPITR_IMP_aaml_aDrf":
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
IMPDP> . . imported "YSBAE"."EMP" 8.781 KB 14 rows
IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
IMPDP> Job "SYS"."TSPITR_IMP_aaml_aDrf" successfully completed at Fri Jul 1 11:30:03 2022 elapsed 0 00:00:29
Import completed
Removing automatic instance
Automatic instance removed
auxiliary instance file /ora_work/dba/ysbae/DBARAC/datafile/o1_mf_temp_ys_kcwpd79m_.tmp deleted
auxiliary instance file /ora_work/dba/ysbae/DBARAC/datafile/o1_mf_temp_kcwpd78d_.tmp deleted
auxiliary instance file /ora_work/dba/ysbae/AAML_PITR_DBARAC/onlinelog/o1_mf_25_kcwpytkz_.log deleted
auxiliary instance file /ora_work/dba/ysbae/AAML_PITR_DBARAC/onlinelog/o1_mf_24_kcwpygz3_.log deleted
auxiliary instance file /ora_work/dba/ysbae/AAML_PITR_DBARAC/onlinelog/o1_mf_23_kcwpypsw_.log deleted
auxiliary instance file /ora_work/dba/ysbae/AAML_PITR_DBARAC/onlinelog/o1_mf_22_kcwpyo80_.log deleted
auxiliary instance file /ora_work/dba/ysbae/AAML_PITR_DBARAC/onlinelog/o1_mf_21_kcwpybtm_.log deleted
auxiliary instance file /ora_work/dba/ysbae/AAML_PITR_DBARAC/onlinelog/o1_mf_15_kcwpybsw_.log deleted
auxiliary instance file /ora_work/dba/ysbae/AAML_PITR_DBARAC/onlinelog/o1_mf_14_kcwpybsf_.log deleted
auxiliary instance file /ora_work/dba/ysbae/AAML_PITR_DBARAC/onlinelog/o1_mf_13_kcwpybsd_.log deleted
auxiliary instance file /ora_work/dba/ysbae/AAML_PITR_DBARAC/onlinelog/o1_mf_12_kcwpybsd_.log deleted
auxiliary instance file /ora_work/dba/ysbae/AAML_PITR_DBARAC/onlinelog/o1_mf_11_kcwpy98g_.log deleted
auxiliary instance file /ora_work/dba/ysbae/AAML_PITR_DBARAC/onlinelog/o1_mf_5_kcwpy923_.log deleted
auxiliary instance file /ora_work/dba/ysbae/AAML_PITR_DBARAC/datafile/o1_mf_users_kcwpgr4y_.dbf deleted
auxiliary instance file /ora_work/dba/ysbae/DBARAC/datafile/o1_mf_sysaux_kcwoq1jm_.dbf deleted
auxiliary instance file /ora_work/dba/ysbae/DBARAC/datafile/o1_mf_undotbs2_kcwoq1gv_.dbf deleted
auxiliary instance file /ora_work/dba/ysbae/DBARAC/datafile/o1_mf_undotbs1_kcwoq1g6_.dbf deleted
auxiliary instance file /ora_work/dba/ysbae/DBARAC/datafile/o1_mf_system_kcwoq1hz_.dbf deleted
auxiliary instance file /ora_work/dba/ysbae/DBARAC/controlfile/o1_mf_kcwopqs6_.ctl deleted
auxiliary instance file tspitr_aaml_92089.dmp deleted
Finished recover at 01-JUL-22
YSBAE@dbarac1 SQL> select * from ysbae.emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ------------------ ---------- ---------- ----------
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 30
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.
복구완료.
반응형
'Oracle > RMAN' 카테고리의 다른 글
RMAN FULL BACKUP을 활용한 임시DB 완전 복구 (0) | 2024.05.10 |
---|---|
[Recover Table] 여러 테이블 recover 및 remap 옵션 (0) | 2023.06.14 |
RMAN을 사용하여 Clone DB 생성 (0) | 2019.12.23 |
[RMAN]Recover Table (2) | 2019.12.22 |
[RMAN]Database 사전 예방 점검 기능 (0) | 2019.12.21 |
댓글