当前位置:操作系统 > Unix/Linux >>

rman备份恢复测试

rman备份恢复测试
 
1,打开数据库新建测试数据
 
  $sqlplus / nolog
 
  SQL>conn / as sysdba
 
  SQL>startup
 
  SQL>create table cds(id number(1),name varchar2(20));
 
  SQL>insert into cds(id,name) values('1','litao');
 
 
 
2,启动到归档模式
 
  $sqlplus / nolog
 
  SQL>conn / as sysdba
 
  SQL>alter database archivelog;
 
  SQL>archive log list;
 
 
 
 
 
* #data 记录时间,将该时间点添加到恢复脚本中
 
 
 
3,做数据库全备份
 
  $rman  target  /
 
  RMAN> configure controlfile autobackup on;
 
  RMAN>configure channel device type disk format ‘/home/oracle/backup/%U’;
 
  RMAN>backup database;
 
 
 
4,修改数据库
 
  SQL>drop table cds;
 
 
 
5,启动数据库到mount状态
 
  $sqlplus / nolog
 
  SQL>conn / as sysdba
 
  SQL>startup mount
 
 
 
6,恢复数据库
 
  $rman target /
 
  RMAN>configure channel device type disk format '/home/oracle/backup/%U';
 
  RMAN> restore database;
 
  RMAN>recover database until time "to_date('2011-02-17 12:30:00','yyyy-mm-dd hh24:mi:ss')";
 
   恢复到某一个时间点,时间点为删除数据库之前的系统时间
 
# RMAN>release channel t1;
 
(实际上rman也是一个数据库的连接,我们一般做测试的时候都是起一个通道;如果是在生产环境下,我们可能同时开多个通道进行数据库的备份,恢复完成需要释放通道)
 
 
 
 
 
7,查看恢复后的数据库
 
  $sqlplus / nolog
 
  SQL>conn / as sysdba
 
  SQL>startup mount;
 
  SQL>alter database open resetlogs;
 
  SQL>select * from cds;
 
 
 
 
 
 
 
RMAN> shutdown immediate;
 
 
 
database dismounted
 
Oracle instance shut down
 
 
 
RMAN> startup nomount
 
 
 
connected to target database (not started)
 
Oracle instance started
 
 
 
Total System Global Area     167772160 bytes
 
 
 
Fixed Size                     1260672 bytes
 
Variable Size                150995840 bytes
 
Database Buffers               8388608 bytes
 
Redo Buffers                   7127040 bytes
 
 
 
RMAN> alter database mount
 
2> ;
 
 
 
database mounted
 
released channel: ORA_DISK_1
 
 
 
RMAN> reset database to incarnation 2 ;
 
 
 
 
 
RMAN> list incarnation;
 
 
 
 
 
List of Database Incarnations
 
DB Key Inc Key DB Name  DB ID            STATUS  Reset SCN Reset Time
 
------- ------- -------- ---------------- --- ---------- ----------
 
1      1       ORCL     1168992346       PARENT 1          2006-11-16 18:40:24
 
2       2      ORCL     1168992346       CURRENT 456954     2007-12-13 10:20:12
 
3      3       ORCL     1168992346       ORPHAN 3326890    2008-06-23 11:07:57
 
 
 
RMAN> RESTORE DATABASE UNTIL SCN 3326890
 
2> ;
 
 
 
Starting restore at 2008-06-23 12:27:19
 
using channel ORA_DISK_1
 
 
 
skipping datafile 1; already restored to file /u/app/oracle/oradata/orcl/systemf
 
skipping datafile 2; already restored to file /u/app/oracle/oradata/orcl/undotbf
 
skipping datafile 3; already restored to file /u/app/oracle/oradata/orcl/sysauxf
 
skipping datafile 4; already restored to file /u/app/oracle/oradata/orcl/users0f
 
restore not done; all files readonly, offline, or already restored
 
Finished restore at 2008-06-23 12:27:19
 
 
 
RMAN> alter database open resetlogs;
 
 
 
database opened
 
 
 
RMAN> list incarnation;
 
List of Database Incarnations
 
DB Key Inc Key DB Name  DB ID            STATUS  Reset SCN Reset Time
 
------- ------- -------- ---------------- --- ---------- ----------
 
1      1       ORCL     1168992346       PARENT 1          2006-11-16 18:40:24
 
2      2       ORCL     1168992346       PARENT 456954     2007-12-13 10:20:12
 
4      4       ORCL     1168992346       CURRENT 3326784    2008-06-23 12:27:43
 
3      3       ORCL     1168992346       ORPHAN 3326890    2008-06-23 11:07:57
 
 
 
 
 
至此数据库恢复到较早前一个时间点。
 
 
 
 
 
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,