前景:因为修改表的结构后,导致程序执行中出现问题,将原有表全部刷新,需要将这张表数据恢复到2021.10.15日下午14:30的状态
版本:数据库19c rac
恢复机器:19c 单机
备份工具:NBU
备份情况:10.14日,10.15日都是累计增量备份,全备时间为10.13日。
需要有一个大致的恢复思路,为了恢复的较快一点,选择了恢复单个表空间的方法。
恢复过程:
首先去查看需要恢复的表所在的表空间,包括表的约束,索引等元数据情况。这张表无任何约束索引,也不是分区表,这就很好办了。
找到这张表所存在表空间大小
TBS_CRM_DEF_2 340 270.67 69.33 79.61
这个表空间还是挺大的,恢复单个表空间条件:需要恢复system,sysaux,以及undo表空间。
去恢复机器上创建pfile。
[oracle@db-buss ~]$ more pfilengxsd.ora
*.audit_file_dest='/oracle19/admin/ngxsd/adump'
*.audit_trail=NONE
*.cluster_database=false
*.compatible='19.0.0'
*.control_files='/oradata/ngxsd/control01.ctl','/oradata/ngxsd/control02.ctl'#Restore Controlfile
*.db_block_size=8192
*.db_domain=''
*.db_name='ngxsd'
*.diagnostic_dest='/oracle19'#oracle_base
*.log_archive_dest='/oradata/ngxsd/archivelog'
*.open_cursors=300
*.processes=5000
*.remote_login_passwordfile='exclusive'
*.pga_aggregate_target=4G
*.sga_max_size=12G
*.sga_target=12G
*.db_create_file_dest='/oradata/ngxsd/'
*.db_files=4000
*.undo_tablespace='UNDOTBS1'
使用参数文件将数据库启动到nomount。
去nbu备份master服务器上查看10.13-10.15日的备份情况,我们只需要15日的控制文件
-rw-rw---- oracle asmadmin 22806528 Oct 15 02:57 /c-1331723944-20211015-04
-rw-rw---- oracle asmadmin 22806528 Oct 15 02:57 /cntrl_12522_1_1085972229
-rw-rw---- oracle asmadmin 22806528 Oct 15 02:56 /c-1331723944-20211015-03
使用rman 将控制文件恢复到恢复机器上:
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: NGXSD (not mounted)
RMAN> run {
2> allocate channel c1 type 'sbt_tape';
3> SEND 'NB_ORA_SERV=tapebak,NB_ORA_CLIENT=bssdb1';
4> restore controlfile from 'cntrl_12522_1_1085972229';
5> release channel c1;
6> }
最后输出文件:
output file name=/oradata/ngxsd/control01.ctl
output file name=/oradata/ngxsd/control02.ctl
手动将数据库启动到mount:
SQL> alter database mount;
Database altered.
将system,sysaux,undotbs表空间里的数据文件使用sql拼接后留着备用:
select 'set newname for datafile '''||FILE_NAME||''' to ''/oradata/ngxsd/'|| substr(FILE_NAME,26,100)||''';' from dba_data_files where tablespace_name='TBS_CRM_DEF_2';
select 'set newname for datafile '''||FILE_NAME||''' to ''/oradata/ngxsd/'|| substr(FILE_NAME,26,100)||''';' from dba_data_files where tablespace_name='SYSTEM';
select 'set newname for datafile '''||FILE_NAME||''' to ''/oradata/ngxsd/'|| substr(FILE_NAME,26,100)||''';' from dba_data_files where tablespace_name='SYSAUX';
select 'set newname for datafile '''||FILE_NAME||''' to ''/oradata/ngxsd/'|| substr(FILE_NAME,26,100)||''';' from dba_data_files where tablespace_name='UNDOTBS1';
select 'set newname for datafile '''||FILE_NAME||''' to ''/oradata/ngxsd/'|| substr(FILE_NAME,26,100)||''';' from dba_data_files where tablespace_name='UNDOTBS2';
然后打开rman进行恢复:
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: NGXSD (DBID=1331723944, not open)
RMAN> run {
2> set newname for datafile '+DATAXSDB/NGXSD/DATAFILE/tbs_crm_def_201.dbf' to '/oradata/ngxsd/tbs_crm_def_201.dbf';
此处省略类似内容
45> allocate channel c1 type 'sbt_tape';
46> allocate channel c2 type 'sbt_tape';
47> allocate channel c3 type 'sbt_tape';
48> allocate channel c4 type 'sbt_tape';
49> allocate channel c5 type 'sbt_tape';
50> SEND 'NB_ORA_SERV=tapebak,NB_ORA_CLIENT=bssdb1';
51> restore database skip forever tablespace TEMP....(这里需要将数据库不需要恢复的表空间全部写上)
52> switch datafile all;
53> release channel c1;
54> release channel c2;
55> release channel c3;
56> release channel c4;
57> release channel c5;
58> }
恢复完成后继续应用增量恢复:
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: NGXSD (DBID=1331723944, not open)
RMAN> run {
2> allocate channel c1 type 'sbt_tape';
3> allocate channel c2 type 'sbt_tape';
4> allocate channel c3 type 'sbt_tape';
5> allocate channel c4 type 'sbt_tape';
6> allocate channel c5 type 'sbt_tape';
7> SEND 'NB_ORA_SERV=tapebak,NB_ORA_CLIENT=bssdb1';
8> recover database skip forever tablespace xxx
9> release channel c1;
10> release channel c2;
11> release channel c3;
12> release channel c4;
13> release channel c5;
14> }
恢复完成后 就将数据库恢复到了10.15日的状态,恢复完成后会有一个缺少归档日志的提示
archived log file name=/oradata/ngxsd/archivelog/2_3883_1064020780.dbf thread=2 sequence=3883
archived log file name=/oradata/ngxsd/archivelog/2_3884_1064020780.dbf thread=2 sequence=3884
archived log file name=/oradata/ngxsd/archivelog/1_6753_1064020780.dbf thread=1 sequence=6753
此处省略部分内容...
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 6754 and starting SCN of 16810846944944
RMAN> exit
接下来就需要恢复15日14:30的归档信息
将数据库shutdow abort之后 继续使用参数启动到nomount ,将现有的控制文件mv 改名之后,使用rman恢复10.16日的控制文件,然后恢复所需要的归档信息(此时的归档信息可以去原来数据库中去查找,一定要恢复的多一点 防止出现需要二次恢复归档的情况)
这里省略恢复步骤.......
恢复完成后将数据库shutdown abort之后 将原来控制文件修改回来,然后手动注册归档信息
这里需要手动注册信息是因为咱们的控制文件的状态是15日凌晨的 而归档则是15日的,注册之后继续进行恢复,将数据库恢复到15日14:30
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: NGXSD (DBID=1331723944, not open)
RMAN> run {
2> set until time "to_date('2021-10-15 14:30:00','yyyy-mm-dd hh24:mi:ss')";
3> recover database skip forever tablespace xxx
4> }
executing command: SET until clause
这里应用完成之后咱们的数据库就恢复完成了,这里需要在修改一下redo的位置,修改完成之后将数据库open resetlogs打开
SQL> alter database open RESETLOGS;
Database altered.
开库这里花费了很长时间,毕竟咱们的数据库只恢复了一个表空间,在alert会有很多很多信息,这些咱都不用管,第一时间将这张表exp导出即可。



