建立恢复目录等前期准备工作
第一步:在目录数据库中创建恢复目录所用表空间:
SQL> create tablespace rman_ts datafile "d:\oracle\oradata\rman\rman_ts.dbf" size 20M;
第二步:在目录数据库中创建RMAN用户并授权:
SQL> create user rman identified by rman default tablespace rman_ts temporary
tablespace temp quota unlimited on rman_ts;
第三步:用户授权
SQL> grant recovery_catalog_owner to rman;
SQL> grant connect, resource to rman;
第四步:在目录数据库中创建恢复目录
rman catalog rman/rman
RMAN>create catalog tablespace rman_ts;
注:虽然使用RMAN不一定必需恢复目录,但是推荐使用。因为恢复目录记载的信息大部分可以通过控制文件来记载,RMAN在恢复数据库时使用这些信息。不使用恢复目录将会对备份恢复操作有限制。
第五步:连接目标数据库
rman target sys/123456@orcl11g catalog rman/rman;@orcl11g;
第六步:将目标数据库注册到目录数据库中
RMAN> register database;
至此,前期准备工作结束,接下来开始进行备份恢复操作。
联机备份:
设置rman参数,oracle推荐将控制文件自动备份设为开启状态
RMAN>configure controlfile autobackup on
将数据库启动至mount状态
SQL>startup mount
将数据库更改为归档模式(需在mount状态下)
SQL>alter database archivelog
全库备份:
RMAN>backup database plus archivelog;
全库恢复:
RMAN>restore database;
基于时间点的不完全恢复
RMAN>
RUN {
SET UNTIL TIME "to_date('2019-09-13 15:03:00','yyyy-mm-dd hh24:mi:ss')";
RESTORE DATABASE;
RECOVER DATABASE;
}
基于SCN号的不完全恢复
RMAN>
run{
set until scn 1028220;
restore database;
recover database;
alter database open resetlogs;
}
数据文件丢失后的恢复 (在rman中执行sql语句,在sql后面用双引号括起来):
1. sql 'alter database datafile 7 offline';
2. restore datafile 7;
3. recover datafile 7;
4. sql 'alter database datafile 7 online';