Oracle归档模式下热备恢复表空间

Oracle归档模式下热备恢复表空间-数据库完全恢复方法实例1
参考文档:https://blog.csdn.net/hunhun1122/article/details/78113738

创建测试表 t
create tablespace test datafile '/u01/app/oracle/oradata/orcl/test.dbf' size 1024m autoextend on next 10m;
create user c##test identified by test;
grant dba to c##test;
ALTER USER c##test DEFAULT TABLESPACE test;
ALTER USER c##test TEMPORARY TABLESPACE TEMP;
conn c##test/test
create table t (ID int,NAME varchar2(20));    
insert into t values(1,'ZhangSan');
select * from c##test.t;


开启归档,否则报如下错误:
alter tablespace NNC_DATA01 begin backup
*
ERROR at line 1:
ORA-01123: cannot start online backup; media recovery not enabled

col username for a30;
col default_tablespace for a30;
set pagesize 0
select username,default_tablespace from dba_users;        --查看默认表空间

备份表空间
alter tablespace test begin backup;    --开启热备模式
host cp /u01/app/oracle/oradata/orcl/test.dbf /home/oracle/;    --备份表空间
alter tablespace test end backup;    --结束热备模式

破坏数据库
shutdown immediate
host rm -rf /u01/app/oracle/oradata/orcl/test.dbf
host ls -l /u01/app/oracle/oradata/orcl/

此时启动数据库报错,数据文件 14 出了问题:
startup
ORACLE instance started.
Total System Global Area 1.0066E+10 bytes
Fixed Size           12342064 bytes
Variable Size         2248150224 bytes
Database Buffers     7784628224 bytes
Redo Buffers           21209088 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 14 - see DBWR trace file
ORA-01110: data file 14: '/u01/app/oracle/oradata/orcl/test.dbf'


alter database datafile 14 offline;    --将数据文件 14 脱机
select file#,status from v$datafile;    --在 mount 状态下查看表空间的联机情况,可以看到数据文件 14 是 offline 状态
select * from v$recover_file;    --查找恢复区的信息( 注:error:数据文件not found 丢了)
host cp /home/oracle/test.dbf /u01/app/oracle/oradata/orcl/    --恢复文件到原始位置
recover datafile 14;    --恢复文件(Media recovery complete. 完成介质恢复)
alter database open;    --打开数据库
alter tablespace test online;    --将表空间联机
select file#,status from v$datafile;    --检查联机状态,发现,已经联机
select * from c##test.t;    --最后就可以查询到数据了
     1 ZhangSan


    


 


 

猜你喜欢

转载自blog.csdn.net/yaoshixian/article/details/85263341