手动实现表空间基于时间点的恢复

实验说明:

      (1)先创建2个表空间。

create tablespace user01
  datafile '/opt/oracle/oradata/ocp/user01.dbf' size 1M;
create tablespace user02
 datafile '/opt/oracle/oradata/ocp/user02.dbf' size 1M;


 (2)在每个表空间上各创建一张表。
create table scott.customers
 (cust_id int,cust_name varchar2(10)) tablespace user01;
create table scott.sales
 (id int,cust_name varchar2(10),sales_amount number(8,2)) tablespace user02;

 

(3)对数据库进行热备

alter database begin backup;
select 'cp '||name || ' /home/oracle/backup/' from v$datafile;

alter database end backup;
alter database backup controlfiles to '/home/oracle/backup/demo.ctl' reuse;

(4)在每个表中插入2条记录,提交。检查当前的时间点,待会表空间user01要恢复到当前时间点。

insert into scott.customers values(1,'SOCTT');
insert into scott.customers values(2,'SMITH');
insert into scott.sales values(1,'SCOTT',8000);
insert into scott.sales values(1,'SMITH',10000);

COMMIT;
ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM SWITCH LOGFILE;

date
2010年 03月 11日 星期四 21:44:52 CST

(5) truncate 表1,往表2中插入2条记录。在表空间1中再创建一个表。

truncate table scott.customers;
insert into scott.sales values(3,'SCOTT',6000);
insert into scott.sales values(4,'BLAKE',6700);
commit;

create table scott.employee(id int,name varchar2(10)) tablespace user01;

 

从现在开始进行表空间基于时间点的恢复

(6) 创建辅助库的密码文件,从现在的主库创建辅助库的参数文件,修改参数文件

orapwd file=/opt/oracle/product/10g/dbs/orapwauxi password=uplooking entries=10 force=y

create pfile='?/dbs/initauxi.ora' from spfile;

vim $ORACLE_HOME/dbs/initauxi.ora
 DB_UNIQUE_NAME=auxi
 CONTROL_FILES=/opt/oracle/oradata/auxi/demo.ctl
 DB_FILE_NAME_CONVERT=('/opt/oracle/oradata/ocp','/opt/oracle/oradata/auxi')
 LOG_FILE_NAME_CONVERT=('/opt/oracle/oradata/ocp','/opt/oracle/oradata/auxi')

 

(7) 拷贝对应几个数据文件和控制文件到辅助库的对应位置

cp /home/oracle/backup/system01.dbf /opt/oracle/oradata/auxi/
cp /home/oracle/backup/undotbs01.dbf /opt/oracle/oradata/auxi/
cp /home/oracle/backup/user01.dbf /opt/oracle/oradata/auxi/
cp /home/oracle/backup/demo.ctl /opt/oracle/oradata/auxi/

 

(8) 用步骤6中建立的参数文件启动辅助实例

export ORACLE_SID=auxi
sql / as sysdba
startup nomount pfile='?/dbs/initauxi.ora';

 

(9) 启动数据库到mount状态

alter database mount clone database;

 

(10) 将数据文件联机

alter database datafile '/opt/oracle/oradata/auxi/system01.dbf' online;
alter database datafile '/opt/oracle/oradata/auxi/undotbs01.dbf' online;
alter database datafile '/opt/oracle/oradata/auxi/user01.dbf' online;

 

(11) 恢复数据库
recover database until time '2010-03-11 23:42:30' using backup controlfile;

 

(12)开启数据库,查询user01表空间是否恢复到指定时间点

alter database open resetlogs;

select * from scott.customers;

 

(13) 添加临时文件,exp中可能用到

alter tablespace temp add tempfile '/opt/oracle/oradata/ocp/temp.dbf' size 5M;

 

(14) exp 辅助数据库中的user01表空间

export ORACLE_SID=auxi

exp point_in_time_recover=y tablespace=user01 file=/home/oracle/backup/user01.dmp

用户名:sys as sysdba

密码:****

(15) 关闭辅助库

export ORACLE_SID=auxi

shutdown immediate

 

(16)将主库的user01表空间offline

alter tablespace user01 offline;

 

(17)覆盖主库的user01表空间数据文件

cp /opt/oracle/oradata/auxi/user01.dbf /opt/oracle/oradata/ocp/user01.dbf

 

(18) 将刚刚dump出来的文件导入到主库中

imp point_in_time_recover=y file=/home/oracle/backup/user01.dmp

用户名:sys as sysdba

密码:****

 

(19) 主库中user01 表空间online

alter tablespace user01 online;

 

select * from scott.customers; --判断是否恢复到指定时间

select * from scott.sales; --判断别的表空间是否不受影响

 

(20) 删除辅助库相关的文件。

 

至此,手动执行表空间基于时间点的恢复完成。如果看过“RMAN TSPITR 使用rman进行表空间基于时间点的恢复”这篇文章的话,其实发现和那篇文章的步骤差不多,只是那里用rman,rman自动为我们完成了很多工作。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值