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
经过验证被误删除的表成功恢复。

相关推荐

  1. Oracle 19C 数据库删除模拟恢复

    2024-06-16 23:28:03       25 阅读
  2. oracle恢复

    2024-06-16 23:28:03       62 阅读
  3. Oracle删除数据文件恢复---惜分飞

    2024-06-16 23:28:03       49 阅读
  4. Oracle 数据库恢复删除数据

    2024-06-16 23:28:03       64 阅读
  5. MySQL使用binlog恢复删除数据

    2024-06-16 23:28:03       39 阅读
  6. oracle 数据 delete 恢复

    2024-06-16 23:28:03       43 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-16 23:28:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-16 23:28:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-16 23:28:03       82 阅读
  4. Python语言-面向对象

    2024-06-16 23:28:03       91 阅读

热门阅读

  1. Ubuntu20.04 使用scrapy-splash爬取动态网页

    2024-06-16 23:28:03       31 阅读
  2. C++基础之红黑树

    2024-06-16 23:28:03       31 阅读
  3. jQuery中.text() 和 .val()辨析

    2024-06-16 23:28:03       26 阅读
  4. GitHub项目的core文件夹

    2024-06-16 23:28:03       28 阅读
  5. 指定GPU跑模型

    2024-06-16 23:28:03       34 阅读
  6. 分库分表实践:单 KEY 业务场景

    2024-06-16 23:28:03       33 阅读
  7. MySQL分组聚合

    2024-06-16 23:28:03       31 阅读
  8. Redis缓存穿透、缓存雪崩和缓存击穿的解决方案

    2024-06-16 23:28:03       32 阅读
  9. 计算机行业

    2024-06-16 23:28:03       19 阅读
  10. 002 IOC和DI使用

    2024-06-16 23:28:03       28 阅读
  11. Python中*args 和**kwargs的用法

    2024-06-16 23:28:03       25 阅读
  12. os实训课程模拟考试(1~7)

    2024-06-16 23:28:03       22 阅读