标签:ons shutdown history dash automatic 初始 改变 locate tsp
在 RMAN 中提供了表级别恢复( RECOVER TABLE )。在 Oracle 12c 中,在发生 drop 或 truncate 的情况下,
可以从 RMAN 备份种将一个特定的表或分区恢复到某个时间点、 SCN 或归档序列号,并且可以有下面的选择:
l 使用REMAP选项将表恢复为一个新表或者分区中,也可以恢复到其他用户中。
l 只生成一个需要被恢复表的expdp格式的dump文件,选择后期再进行恢复。
Oracle 12c的Recover Table新特性是利用创建辅助临时实例加数据泵工具来实现的。通常在进行Recover Table之前应该准备好两个目录(AUXILIARY DESTINATION和DATAPUMP DESTINATION),AUXILIARY DESTINATION用来临时存放辅助实例的数据文件,DATAPUMP DESTINATION用来临时存放数据泵导出的文件。
只要之前创建了RMAN备份,那么就可以根据指定的的时间来进行表级和表分区级的恢复操作,而且不影响其他的数据库对象。RMAN的表级和表分区级恢复可以使用在如下场景:
① 在恢复小表或数据库中的某几张表时,但发现使用Restore Database或Tablespace的代价很高而且效率很低。也可以使用TSPITR(表空间基于时间点的恢复)的方法,但该方法效率很低,因为需要移动表空间中的所有对象。
② 恢复有逻辑损坏或者被删除的表。
③ Flashback Table不可用,例如Undo数据已经被覆盖的情况。
④ DDL操作后需要恢复数据。Flashback Table不支持表结构发生改变后的回退,例如TRUNCATE TABLE。
RMAN从备份中自动处理恢复表或者表分区时会执行如下步骤:
1.判断哪些备份包含需要恢复的表或表分区,然后根据指定的时间来进行恢复。
2.判断目标主机上是否有足够的空间来创建auxiliary instance,该实例用于处理表或分区的恢复。如果需要的空间不足,那么RMAN会报错并退出恢复操作。
3.创建auxiliary database,并根据指定的时间来恢复指定的表或表分区到auxiliary database中。辅助数据库的数据文件位置可以在命令中指定。
4.创建包含恢复表或表分区的数据泵文件(expdp dump file)。数据泵的名称和位置也可以在命令中指定。
5.(可选操作)将上一步生产的数据泵文件导入到目标实例中。当然也可以选择不导入,如果选择不导入就必须使用impdp手工导入。
6.(可选操作)在目标数据库中rename恢复表或表分区。
关于RECOVER TABLE需要注意的几个问题:
l 目标数据库必须被置于读写模式。
l 目标数据库必须被置于归档模式。
l 如果要恢复表或者分区,你必须拥有这些表或者分区存在后的时间的备份。
l 想要恢复单个表分区,COMPATIBLE初始化参数所在的目标库必须设置为11.1.0或以上。
l SYS用户下的表或分区无法恢复。
l 存储于SYSAUX和SYSTEM表空间下的表和分区无法恢复。
l Standby数据库上的表或表分区不能进行恢复。
l 在使用REMAP的情况下,有NOT NULL 约束的表不能进行恢复。
l 确保对于辅助数据库在文件系统下有足够的可用空间,同时对数据泵文件也有同样保证。
l 必须要存在一份完整的数据库备份,至少要有SYSTEM、UNDO、SYSAUX和表所在表空间相关的备份。如果恢复的表在PDB中,那么需要备份Root Container的SYSTEM,SYSAUX、UNDO和PDB的SYSTEM、SYSAUX以及包含了要恢复的表的表空间。
在执行“RECOVER TABLE”命令时,可以根据需要在以下三种级别指定时间:
(1)SCN号
(2)Sequence number(日志序列号)
(3)Time:根据NLS_LANG和NLS_DATE_FORMAT环境变量中的格式来指定时间,也可以用SYSDATE,比如"SYSDATE-30"、"to_date(‘2018-04-09:13:51:48‘,‘yyyy-mm-dd hh24:mi:ss‘)"
“RECOVER TABLE”命令的一般格式为:
RMAN> connect target "username/password as SYSBACKUP";
RMAN> RECOVER TABLE username.tablename UNTIL TIME ‘TIMESTAMP…‘
AUXILIARY DESTINATION ‘/u01/tablerecovery‘
DATAPUMP DESTINATION ‘/u01/dpump‘
DUMP FILE ‘tablename.dmp‘
NOTABLEIMPORT -- this option avoids importing the table automatically.(此选项避免自动导入表)
REMAP TABLE ‘username.tablename‘: ‘username.new_table_name‘; -- can rename table with this option.(此选项可以对表重命名)
示例1:在PDB中恢复表HR.PDB_EMP,恢复后的表命名为EMP_RECVR
RECOVER TABLE HR.PDB_EMP OF PLUGGABLE DATABASE HR_PDB
UNTIL TIME ‘SYSDATE-4‘
AUXILIARY DESTINATION ‘/tmp/backups‘
REMAP TABLE ‘HR‘.‘PDB_EMP‘:‘EMP_RECVR‘;
RECOVER TABLE DB12C.T
UNTIL SCN 1932621
AUXILIARY DESTINATION ‘/tmp/oracle/recover‘
REMAP TABLE ‘DB12C‘.‘T‘:‘T_HISTORY_20130717‘;
RECOVER TABLE LHR.TEST_RT
UNTIL TIME "to_date(‘2018-04-09:13:51:48‘,‘yyyy-mm-dd hh24:mi:ss‘)"
AUXILIARY DESTINATION ‘/tmp‘
REMAP TABLE ‘LHR‘.‘TEST_RT‘:‘TEST_RT_LHR‘;
RECOVER TABLE HR.DEPARTMENTS, SH.CHANNELS
UNTIL TIME ‘SYSDATE – 1‘
AUXILIARY DESTINATION ‘/tmp/auxdest‘
REMAP TABLE hr.departments:example.new_departments, sh.channels:example.new_channels;
示例2:从RMAN备份中恢复表SCOTT.EMP,SCOTT.DEPT,并以数据泵格式导出emp_dept_exp_dump.dat,并不进行表的导入
RECOVER TABLE SCOTT.EMP, SCOTT.DEPT
UNTIL TIME ‘SYSDATE-1‘
AUXILIARY DESTINATION ‘/tmp/oracle/recover‘
DATAPUMP DESTINATION ‘/tmp/recover/dumpfiles‘
DUMP FILE ‘emp_dept_exp_dump.dat‘
NOTABLEIMPORT;
示例3:恢复表的两个分区,恢复后表分区重新命名并且放置于SALES_PRE_2000_TS表空间
RECOVER TABLE SH.SALES:SALES_1998, SH.SALES:SALES_1999
UNTIL SEQUENCE 354
AUXILIARY DESTINATION ‘/tmp/oracle/recover‘
REMAP TABLE ‘SH‘.‘SALES‘:‘SALES_1998‘:‘HISTORIC_SALES_1998‘,
‘SH‘.‘SALES‘:‘SALES_1999‘:‘HISTORIC_SALES_1999‘
REMAP TABLESPACE ‘SALES_TS‘:‘SALES_PRE_2000_TS‘;
====================================================================================================================================
9. RMAN 中的 表恢复和分区恢复
recover table hr.tab_test
until time "to_date(‘2020-07-12 21:31:37‘,‘yyyy-mm-dd hh24:mi:ss‘)"
auxiliary destination ‘/backup/recover‘
datapump destination ‘/home/oracle/dumpfiles‘
dump file ‘hr_tab_test.dmp‘
notableimport;
RMAN>
RMAN>
RMAN> recover table hr.tab_test
until time "to_date(‘2020-07-12 21:31:37‘,‘yyyy-mm-dd hh24:mi:ss‘)"
auxiliary destination ‘/backup/recover‘
datapump destination ‘/home/oracle/dumpfiles‘
dump file ‘hr_tab_test.dmp‘
notableimport;2> 3> 4> 5> 6>
Starting recover at 2020-07-12 21:34:23
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
Creating automatic instance, with SID=‘DCCl‘
initialization parameters used for automatic instance:
db_name=ORCL
db_unique_name=DCCl_pitr_ORCL
compatible=19.0.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle
_system_trig_enabled=FALSE
sga_target=4768M
processes=200
db_create_file_dest=/backup/recover
log_archive_dest_1=‘location=/backup/recover‘
#No auxiliary parameter file used
starting up automatic instance ORCL
Oracle instance started
Total System Global Area 4999608360 bytes
Fixed Size 8906792 bytes
Variable Size 905969664 bytes
Database Buffers 4076863488 bytes
Redo Buffers 7868416 bytes
Automatic instance created
contents of Memory Script:
{
# set requested point in time
set until time "to_date(‘2020-07-12 21:31:37‘,‘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 2020-07-12 21:34:32
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=4 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 /u01/app/oracle/product/19.0.0/dbhome_1/dbs/c-1573073554-20200712-02
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/c-1573073554-20200712-02 tag=TAG20200712T213125
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/backup/recover/ORCL/controlfile/o1_mf_hjp4c8v2_.ctl
Finished restore at 2020-07-12 21:34:33
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(‘2020-07-12 21:31:37‘,‘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 3 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, 4, 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
renamed tempfile 1 to /backup/recover/ORCL/datafile/o1_mf_temp_%u_.tmp in control file
Starting restore at 2020-07-12 21:34:41
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 /backup/recover/ORCL/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /backup/recover/ORCL/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /backup/recover/ORCL/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /backup/ORCL_05v559gu_1_1_20200712.full
channel ORA_AUX_DISK_1: piece handle=/backup/ORCL_05v559gu_1_1_20200712.full tag=TAG20200712T213110
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 2020-07-12 21:34:56
datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=1045604096 file name=/backup/recover/ORCL/datafile/o1_mf_system_hjp4ck7d_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=1045604096 file name=/backup/recover/ORCL/datafile/o1_mf_undotbs1_hjp4ck7w_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=1045604096 file name=/backup/recover/ORCL/datafile/o1_mf_sysaux_hjp4ck7n_.dbf
contents of Memory Script:
{
# set requested point in time
set until time "to_date(‘2020-07-12 21:31:37‘,‘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 3 online";
# recover and open database read only
recover clone database tablespace "SYSTEM", "UNDOTBS1", "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 3 online
Starting recover at 2020-07-12 21:34:56
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 28 is already on disk as file /arch/1_28_1045292820.dbf
archived log file name=/arch/1_28_1045292820.dbf thread=1 sequence=28
media recovery complete, elapsed time: 00:00:00
Finished recover at 2020-07-12 21:34:57
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 =
‘‘/backup/recover/ORCL/controlfile/o1_mf_hjp4c8v2_.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 4999608360 bytes
Fixed Size 8906792 bytes
Variable Size 905969664 bytes
Database Buffers 4076863488 bytes
Redo Buffers 7868416 bytes
sql statement: alter system set control_files = ‘‘/backup/recover/ORCL/controlfile/o1_mf_hjp4c8v2_.ctl‘‘ comment= ‘‘RMAN set‘‘ scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 4999608360 bytes
Fixed Size 8906792 bytes
Variable Size 905969664 bytes
Database Buffers 4076863488 bytes
Redo Buffers 7868416 bytes
sql statement: alter database mount clone database
contents of Memory Script:
{
# set requested point in time
set until time "to_date(‘2020-07-12 21:31:37‘,‘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 2020-07-12 21:35:43
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=181 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 /backup/recover/DCCL_PITR_ORCL/datafile/o1_mf_users_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /backup/ORCL_05v559gu_1_1_20200712.full
channel ORA_AUX_DISK_1: piece handle=/backup/ORCL_05v559gu_1_1_20200712.full tag=TAG20200712T213110
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 2020-07-12 21:35:45
datafile 7 switched to datafile copy
input datafile copy RECID=8 STAMP=1045604145 file name=/backup/recover/DCCL_PITR_ORCL/datafile/o1_mf_users_hjp4fjbq_.dbf
contents of Memory Script:
{
# set requested point in time
set until time "to_date(‘2020-07-12 21:31:37‘,‘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", "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 2020-07-12 21:35:45
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 28 is already on disk as file /arch/1_28_1045292820.dbf
archived log file name=/arch/1_28_1045292820.dbf thread=1 sequence=28
media recovery complete, elapsed time: 00:00:01
Finished recover at 2020-07-12 21:35:46
database opened
contents of Memory Script:
{
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ‘‘
/home/oracle/dumpfiles‘‘";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ‘‘
/home/oracle/dumpfiles‘‘";
}
executing Memory Script
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ‘‘/home/oracle/dumpfiles‘‘
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ‘‘/home/oracle/dumpfiles‘‘
Performing export of tables...
EXPDP> Starting "SYS"."TSPITR_EXP_DCCl_Dbwd":
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 "HR"."TAB_TEST" 9.547 MB 72407 rows
EXPDP> Master table "SYS"."TSPITR_EXP_DCCl_Dbwd" successfully loaded/unloaded
EXPDP> ******************************************************************************
EXPDP> Dump file set for SYS.TSPITR_EXP_DCCl_Dbwd is:
EXPDP> /home/oracle/dumpfiles/hr_tab_test.dmp
EXPDP> Job "SYS"."TSPITR_EXP_DCCl_Dbwd" successfully completed at Sun Jul 12 21:36:09 2020 elapsed 0 00:00:16
Export completed
Not performing table import after point-in-time recovery
Removing automatic instance
shutting down automatic instance
Oracle instance shut down
Automatic instance removed
auxiliary instance file /backup/recover/ORCL/datafile/o1_mf_temp_hjp4d1j1_.tmp deleted
auxiliary instance file /backup/recover/DCCL_PITR_ORCL/onlinelog/o1_mf_3_hjp4flfo_.log deleted
auxiliary instance file /backup/recover/DCCL_PITR_ORCL/onlinelog/o1_mf_2_hjp4fldb_.log deleted
auxiliary instance file /backup/recover/DCCL_PITR_ORCL/onlinelog/o1_mf_1_hjp4fl9d_.log deleted
auxiliary instance file /backup/recover/DCCL_PITR_ORCL/datafile/o1_mf_users_hjp4fjbq_.dbf deleted
auxiliary instance file /backup/recover/ORCL/datafile/o1_mf_sysaux_hjp4ck7n_.dbf deleted
auxiliary instance file /backup/recover/ORCL/datafile/o1_mf_undotbs1_hjp4ck7w_.dbf deleted
auxiliary instance file /backup/recover/ORCL/datafile/o1_mf_system_hjp4ck7d_.dbf deleted
auxiliary instance file /backup/recover/ORCL/controlfile/o1_mf_hjp4c8v2_.ctl deleted
Finished recover at 2020-07-12 21:36:12
RMAN>
12c中在 RMAN 中提供了表级别恢复 RECOVER TABLE
标签:ons shutdown history dash automatic 初始 改变 locate tsp
原文地址:https://www.cnblogs.com/chendian0/p/13291370.html