Oracle 19C 数据库表被误删除的模拟恢复

Oracle 19C 数据库表被误删除的模拟恢复操作

1、模拟创建表用于恢复测试
sqlplus zzh/zzh
SQL> create table obj_tb tablespace users as select * from dba_objects;

Table created.

SQL> select count(*) from obj_tb;

  COUNT(*)
----------
     72373

2、记录当前状态下数据库的时间
SQL> select systimestamp from dual;

SYSTIMESTAMP
---------------------------------------------------------------------------
13-JUN-24 11.10.10.097481 AM +08:00


3、模拟表被误操作永久删除
SQL> drop table obj_tb purge;

Table dropped.

SQL> select * from obj_tb
  2  ;
select * from obj_tb
              *
ERROR at line 1:
ORA-00942: table or view does not exist

4、基于时间点通过RMAN恢复被删除的表
[oracle@oel backup]$ rman target /

Recovery Manager: Release 19.0.0.0.0 - Production on Thu Jun 13 11:11:57 2024
Version 19.3.0.0.0

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

connected to target database: ORCL (DBID=1699315892)

RMAN> recover table zzh.obj_tb until time "to_date('2024-06-13 11:10:10','yyyy-mm-dd hh24:mi:ss')" auxiliary destination '/u01/dump';

Starting recover at 2024-06-13 11:12:03
using target database control file instead of recovery catalog
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=257 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

Creating automatic instance, with SID='pEpF'

initialization parameters used for automatic instance:
db_name=ORCL
db_unique_name=pEpF_pitr_ORCL
compatible=19.0.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle
_system_trig_enabled=FALSE
sga_target=6144M
processes=200
db_create_file_dest=/u01/dump
log_archive_dest_1='location=/u01/dump'
#No auxiliary parameter file used


starting up automatic instance ORCL

Oracle instance started

Total System Global Area    6442448984 bytes

Fixed Size                     8910936 bytes
Variable Size               1107296256 bytes
Database Buffers            5318377472 bytes
Redo Buffers                   7864320 bytes
Automatic instance created

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2024-06-13 11:10:10','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 2024-06-13 11:12:23
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=169 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/backup/ctl_spf_c-1699315892-20240613-00.BKU
channel ORA_AUX_DISK_1: piece handle=/u01/backup/ctl_spf_c-1699315892-20240613-00.BKU tag=TAG20240613T110741
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/dump/ORCL/controlfile/o1_mf_m6nrwr5f_.ctl
Finished restore at 2024-06-13 11:12:25

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('2024-06-13 11:10:10','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 /u01/dump/ORCL/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 2024-06-13 11:12:29
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 /u01/dump/ORCL/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/dump/ORCL/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/dump/ORCL/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/backup/zzh_full_022t8fks_1_1.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/backup/zzh_full_022t8fks_1_1.bkp tag=TAG20240613T110604
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:45
Finished restore at 2024-06-13 11:14:15

datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=1171538055 file name=/u01/dump/ORCL/datafile/o1_mf_system_m6nrwybv_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=1171538055 file name=/u01/dump/ORCL/datafile/o1_mf_undotbs1_m6nrwyhw_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=1171538055 file name=/u01/dump/ORCL/datafile/o1_mf_sysaux_m6nrwygk_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2024-06-13 11:10:10','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 2024-06-13 11:14:15
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 6 is already on disk as file /u01/app/archivelog/1_6_1171535158.dbf
archived log for thread 1 with sequence 7 is already on disk as file /u01/app/archivelog/1_7_1171535158.dbf
archived log file name=/u01/app/archivelog/1_6_1171535158.dbf thread=1 sequence=6
archived log file name=/u01/app/archivelog/1_7_1171535158.dbf thread=1 sequence=7
media recovery complete, elapsed time: 00:00:01
Finished recover at 2024-06-13 11:14:18

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 = 
  ''/u01/dump/ORCL/controlfile/o1_mf_m6nrwr5f_.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    6442448984 bytes

Fixed Size                     8910936 bytes
Variable Size               1107296256 bytes
Database Buffers            5318377472 bytes
Redo Buffers                   7864320 bytes

sql statement: alter system set  control_files =   ''/u01/dump/ORCL/controlfile/o1_mf_m6nrwr5f_.ctl'' comment= ''RMAN set'' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area    6442448984 bytes

Fixed Size                     8910936 bytes
Variable Size               1107296256 bytes
Database Buffers            5318377472 bytes
Redo Buffers                   7864320 bytes

sql statement: alter database mount clone database

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2024-06-13 11:10:10','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 2024-06-13 11:15:32
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=129 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 /u01/dump/PEPF_PITR_ORCL/datafile/o1_mf_users_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/backup/zzh_full_022t8fks_1_1.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/backup/zzh_full_022t8fks_1_1.bkp tag=TAG20240613T110604
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 2024-06-13 11:15:33

datafile 7 switched to datafile copy
input datafile copy RECID=8 STAMP=1171538133 file name=/u01/dump/PEPF_PITR_ORCL/datafile/o1_mf_users_m6ns2npg_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2024-06-13 11:10:10','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 2024-06-13 11:15:33
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 6 is already on disk as file /u01/app/archivelog/1_6_1171535158.dbf
archived log for thread 1 with sequence 7 is already on disk as file /u01/app/archivelog/1_7_1171535158.dbf
archived log file name=/u01/app/archivelog/1_6_1171535158.dbf thread=1 sequence=6
archived log file name=/u01/app/archivelog/1_7_1171535158.dbf thread=1 sequence=7
media recovery complete, elapsed time: 00:00:01
Finished recover at 2024-06-13 11:15:36

database opened

contents of Memory Script:
{
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u01/dump''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u01/dump''";
}
executing Memory Script

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/dump''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/dump''

Performing export of tables...
   EXPDP> Starting "SYS"."TSPITR_EXP_pEpF_nBqn":  
   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 "ZZH"."OBJ_TB"                              9.543 MB   72373 rows
   EXPDP> Master table "SYS"."TSPITR_EXP_pEpF_nBqn" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_pEpF_nBqn is:
   EXPDP>   /u01/dump/tspitr_pEpF_92746.dmp
   EXPDP> Job "SYS"."TSPITR_EXP_pEpF_nBqn" successfully completed at Thu Jun 13 11:16:11 2024 elapsed 0 00:00:22
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_pEpF_Blkh" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_pEpF_Blkh":  
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
   IMPDP> . . imported "ZZH"."OBJ_TB"                              9.543 MB   72373 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_pEpF_Blkh" successfully completed at Thu Jun 13 11:16:44 2024 elapsed 0 00:00:25
Import completed


Removing automatic instance
Automatic instance removed
auxiliary instance file /u01/dump/ORCL/datafile/o1_mf_temp_m6ns0c2n_.tmp deleted
auxiliary instance file /u01/dump/PEPF_PITR_ORCL/onlinelog/o1_mf_3_m6ns2rcv_.log deleted
auxiliary instance file /u01/dump/PEPF_PITR_ORCL/onlinelog/o1_mf_2_m6ns2rb4_.log deleted
auxiliary instance file /u01/dump/PEPF_PITR_ORCL/onlinelog/o1_mf_1_m6ns2r8p_.log deleted
auxiliary instance file /u01/dump/PEPF_PITR_ORCL/datafile/o1_mf_users_m6ns2npg_.dbf deleted
auxiliary instance file /u01/dump/ORCL/datafile/o1_mf_sysaux_m6nrwygk_.dbf deleted
auxiliary instance file /u01/dump/ORCL/datafile/o1_mf_undotbs1_m6nrwyhw_.dbf deleted
auxiliary instance file /u01/dump/ORCL/datafile/o1_mf_system_m6nrwybv_.dbf deleted
auxiliary instance file /u01/dump/ORCL/controlfile/o1_mf_m6nrwr5f_.ctl deleted
auxiliary instance file tspitr_pEpF_92746.dmp deleted
Finished recover at 2024-06-13 11:16:46

RMAN> 

5、RMAN成功后查询并验证表是否恢复
SQL> select count(*) from obj_tb;

  COUNT(*)
----------
     72373
经过验证被误删除的表成功恢复。

  • 19
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ahern_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值