RMAN使用小记

RMAN使用简单步骤[@more@]

SQL>conn /as sysdba
SQL>create user rman identified by rman;
SQL>grant connect,resource to rman;
SQL>grant recovery_catalog_owner to rman;

c:>rman
#进入rman,并以rman用户登录
rman>connect catalog rman/rman
#创建恢复目录
rman>create catalog;

#或者
c:>rman target sys/sys@resorce_dtzx catalog rman/rman

#注册目标数据库
rman>register database

#取消注册目标数据库
SQL> conn rman/rman
#428为select * from db中查找到key
SQL>exec dbms_rcvcat.unregisterdatabase(428,3165229176);

#将目标数据库与恢复目录进行同步化
#该操作保证目标库与恢复目录的控制文件的同步化。系统莫认7天左右同步一次.
rman>resync catalog;

2.RMAN命令分类
#启动关闭数据库
rman>shutdown immediate
rman>startup
rman>startup force
rman>startup mount force
rman>startup mount pfile=/$ORACLE_HOME/.../initora9i.ora
rman>alter database open

#数据库备份与恢复命令

rman>copy datefile 2 to 'd:backupundotbs.dbf'
rman>backup database;
rman>backup tablespace tools;
rman>restore database;
rman>recover database;
rman>restore tablespace tools;
rman>recover tablespace tools;

#恢复目录维护命令
rman>report schema;
rman>list copy;
rman>change datafilecopy 'd:backupundotbs.dbf' delete
rman>backup tablespace users;
rman>list backup;
rman>delete backup;

#
#使用copy命令备份数据库
#
#使用自动通道备份数据文件以及控制文件
RMAN> copy
2> DATAFILE 1 TO '/oracle/copy_data/datafile_1.dbf',
3> DATAFILE 2 TO '/oracle/copy_data/datafile_2.dbf',
4> DATAFILE 3 TO '/oracle/copy_data/datafile_3.dbf',
5> DATAFILE 4 TO '/oracle/copy_data/datafile_4.dbf',
6> CURRENT CONTROLFILE TO '/oracle/copy_data/control_cp.ctl';

#
#使用backup命令备份数据库
#
#备份数据库,忽略只读表空间
rman>backup database skip readnoly;

#备份数据库,而不备份所有离线表空间
rman>bakcup database skip offline

#备份数据库,忽略只读以及离线的表空间
rman>backup database skip offline skip readonly;

#制定备份文件格式
#默认情况下,数据库备份方式是全备份方式?
rman>backup database format '/oracle/bakcup/%U';

#backup增量备份
rman>backup incremental level= <0,1,2,3> DATABASE;
rman>backup incremental level =0 database;

#仅备份系统表空间system自最近一次1级增量备份以后改变的数据块
rman>backup incremental level =1 tablespace system;

#仅备份表空间sales自最近一次1级或0级以后改变的数据块
rman>backup incremental levle = 2 cumulative tablespace sales;


8.使用Rman恢复数据库
.RESTORE:将备份数据复制到指定目录
.RECOVER:对数据库实施同步恢复.

#语法格式
rman>restore ;
包括:datafile,tablespace,database,cotrolfile to,Archivelog All
包括:....

#
#1.恢复数据库的一个实例
#
#将数据库启动到MOUNT状态下
SQL>startup mount;

rman>restore database;

#delete archivelog:可选,恢复结束时自动显示已经使用过的归档日志;
#skip tablespace temp:恢复时跳过temp表空间.
rman>recover database delete archivelog skip tablespace temp;

SQL>alert database open;

#
#2.恢复表空间
#
#恢复表空间时,数据库必须在运行状态下,数据库在关闭状态时表空间是不能操作的.
#在恢复表空间之前,先把要恢复的表空间离线,然后实施表空间恢复,恢复之后再将
#表空间联机.tax_data为表空间名
#
rman>sql 'alter tablespace tax_data offline';
rman>restore tablespace tax_data;
rman>recover tablespace tax_data;
rman>sql 'alter tablespace tax_data online';

#
#3.恢复控制文件
#
#恢复控制文件,数据库只能启动到nomount状态.
#
SQL>startup nomount
#复制控制文件的备份文件
rman>restore controlfile;
#将数据库修改到mount状态下,恢复数据库.
rman>alter database mount;
rman>restore database;
rman>recover database;
SQL>alter database open resetlogs;

#
#4.恢复一个没有备份的数据文件
#
#数据文件没有备份时,不能使用resotre命令,必须在物理上创建一个新的数据文件,通过
#日志对新数据文件进行恢复.
#将破坏的数据文件离线
rman>sql "alter database datafile ''/u01/oracle/sales01.dbf'' offline";
#创建一个新的,空的数据文件
rman>sql "alter database create datafile ''/u01/oracle/sales01.dbf''";
#通过日志恢复数据文件
rman>recover datafile '/u01/oracle/sales01.dbf';
#将数据文件联机
rman>sql "alter database datafile ''/u01/oracle/sales01.dbf'' online";

#
#5.将数据文件恢复到一个新的目录中
#
#在磁盘损坏时,需要将数据文件恢复到另一个目录中。这样可使用set newname命令将
#数据文件路径修改为新路径。
#语法:
#set newname for datafile '原数据文件名称及路径'
# to'目标数据文件名称及路径'
#switch datafile '原数据文件名称及路径';
rman>run
{
set newname for datafile 'disk1/oracle/tbs_1.f' to '/disk2/oracle/tbs_1.f';
sql 'alter database datafile '/disk1/oracle/tbs_1.f' offline';
restore datafile '/disk1/oracle/tbs_1.f';
switch datafile '/disk1/oracle/tbs_1.f';
recover datafile '/disk1/oracle/tbs_1.f';
sql 'alter datbase datafile 'disk1/oracle/tbs_1.f' online';
}

#一次恢复多个文件
rman>run
{
sql 'alter tablespace cust_data offline immediate';
sql 'alter tablespace emp_data offline immediate';
#将数据文件恢复到新目录
set newname for datafile 'disk1/oracle/tbs_1.f' to '/disk2/oracle/tbs_1.f';
set newname for datafile 'disk1/oracle/tbs_2.f' to '/disk2/oracle/tbs_2.f';
set newname for datafile 'disk1/oracle/tbs_3.f' to '/disk2/oracle/tbs_3.f';
restore tablespace cust_data,emp_data;

#修改控制文件中数据文件路径
switch datafile all;
recover tablespace cust_data,emp_data;

sql 'alter tablespace cust_data online';
sql 'alter tablespace emp_data online';
}

#
#6.不完全恢复
#
$NLS_LANG = "simplified chinese"_china.zhs16gbk
$export NLS_LANG
$NLS_DATE_PROMAT = "YYYY-MM-DD HH24:MI:SS"
RUN
{
SET UNTILL TIME '2002-10-15 09:00:00';
restore database;
recover database;
sql 'alter database open resetlogs';
}

#
#7.多通道恢复
#

#
#8.非归档方式下恢复
#
rman>restore database;
rman>recover database noredo;
SQL>alter database open resetlogs;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8683736/viewspace-910985/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/8683736/viewspace-910985/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值