RMAN工具

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Borntodieee/article/details/81164020

1、使用恢复目录

注意:如果目标数据库不在本地,需要远程连接,可在用户名和密码之后输入@目标数据库的服务名连接目标数据库。如system/123456@orcl

创建恢复目录

1、连接数据库
conn username/password@servicename;
eg:conn system/abc@rm;
2、创建rman单独表空间,为了便于管理
create tablespace rman datafile ‘E:\ORACLE\ORADATA\ORCL\rman.DBF’ size 100m reuse autoextend on next 40m maxsize unlimited;
3、创建恢复目录的用户
create username identified by password [default tablespace tablespace_name]
eg:create user rmanuser identified by rman default tablespace rman;
4、给恢复目录用户赋角色
grant connect, resource, recovery_catalog_owner to rmanuser;
5、创建恢复目录
1)进入恢复目录管理器
rman
2)连接至恢复目录数据库
RMAN>connect catalog rmanuser/rman@rm
3)创建恢复目录
RMAN>create catalog;

使用RMAN连接

1、使用目标数据库中的控制文件备份数据
rman target username/password nocatalog;
说明:
target代表要连接的是目标数据库。
nocatalog代表不使用恢复目录。
2、连接到恢复目录数据库
1)方法1
rman target username/password@servicename catalog username/password@servicename
eg:rman target system/123456 catalog rmanuser/rman
说明:
catalog指恢复目录,在catalog后面是恢复目录数据库的用户名和密码。
rmanuser/rman是恢复目录的用户名和密码
2)方法2
连接到目标数据库
rman>connect target username/password@servicename
连接到恢复目录数据库
rman>connect catalog username/password@servicename

在恢复目录中注册数据库

rman>connect catalog username/password@servicename
register database

2、通道分配

手动通道分配

run命令语法:
run
{
allocate channel channel_name1 device type type_name1;
allocate channel channel_name2 device type type_name2;

backup …
}
语法说明:
channel_name:分配的通道名称
type_name:分配的设备类型,磁带(sbt)或者磁盘(disk)
backup:备份数据库的关键字,可以在backup后面写上要备份的表空间等信息
示例:使用磁盘备份表空间users
1、进入rman工具
连接到目标数据库
rman>connect target username/password@servicename
连接到恢复目录数据库
rman>connect catalog username/password@servicename
2、关闭数据库,数据库在运行中无法备份数据库中的文件,会报错。
shutdown immediate
3、Mount模式(加载数据库但不打开数据库)
startup mounted
4、手动通道分配
run
{
allocate channel c device type disk;
backup tablespace users;
}

自动通道分配

自动通道分配时通道名称由数据库自己指定,具体命令如下:
01 configure device type type_name parallelism n
02 configure default device type to type_name
语法说明:
第1行用来指定设备的类型和通道的个数,type_name是类型的名称,n代表通道的个数。
第2行用来指定默认设备的类型,如果使用的设备基本都是磁盘,那么可以把默认设备设置成磁盘。
示例:备份表空间users
1、进入rman工具
连接到目标数据库
rman>connect target username/password@servicename
连接到恢复目录数据库
rman>connect catalog username/password@servicename
2、关闭数据库,数据库在运行中无法备份数据库中的文件,会报错。
shutdown immediate
3、Mount模式(加载数据库但不打开数据库)
startup mounted
4、自动通道分配,创建2个通道备份。
configure device type disk parallelism 2
5、备份表空间users
backup tablespace users;

3、backup的使用

语法:
backup [level][backup type][option]
说明:
level:备份的增量,可以是1、2、3、4或者full,full代表的是全备份。
backup type:备份数据库中的对象类型,可以是database,datafile,tablespace,controlfilecopy,archivelog all等对象。
option:一个可选项,包括channel(用于指定备份所使用的通道)、maxsetsize(定义备份集的最大值)等信息。

4、从备份中恢复

使用restore还原

语法:
restore database_object
说明:
database_object:数据库对象,可以是database(数据库)、tablespace(表空间)、datafile(数据文件)、controlfile(控制文件)、archivelog(归档日志)、spfile(参数文件)。其中,只能在mount状态下使用的对象有database、controlfile、spfile,只能在open状态下使用的对象是tablespace。

使用recover恢复

命令:
recover database_object
说明:
database_object:数据库对象,可以是database(数据库)、tablespace(表空间)、datafile(数据文件)其中,只能在mount状态下使用的对象有database,只能在open状态下使用的对象是tablespace。

5、使用RMAN创建恢复目录演示

--创建表空间
create tablespace rman_tbs 
datafile 'F:\app\hanlin\oradata\orcl\rman_tbs.dbf'
size 200M  autoextend on next 5m maxsize unlimited;
--创建用户并赋予权限
create user rman_user identified by 123456 default tablespace rman_tbs
temporary tablespace temp
quota unlimited on rman_tbs;
grant connect,recovery_catalog_owner,resource to rman_user;
--连接恢复管理器
C:\Users\hanlin>rman catalog rman_user/123456 target orcl;
恢复管理器: Release 12.1.0.1.0 - Production on 星期日 514 13:42:48 2017
Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.
目标数据库口令:
已连接到目标数据库: ORCL (DBID=1462838276)
连接到恢复目录数据库
--创建恢复目录,报错
RMAN> create catalog tablespace rman_tbs;
创建 config_update 时出现'对表空间 'RMAN_TBS' 无权限'错误
恢复目录数据库发生 ORACLE 错误: ORA-01950: 对表空间 'RMAN_TBS' 无权限
恢复目录数据库发生 ORACLE 错误: ORA-00942: 表或视图不存在
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-06433: 安装恢复目录时出错
--再次创建,则出现'名称已由现有对象使用'错误
RMAN> create catalog tablespace rman_tbs;
创建 db 时出错
恢复目录数据库发生 ORACLE 错误: ORA-00955: 名称已由现有对象使用
恢复目录数据库发生 ORACLE 错误: ORA-00942: 表或视图不存在
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-06433: 安装恢复目录时出错
--推测是之前的恢复目录创建报错导致的,先删除
RMAN> drop catalog;
恢复目录所有者是RMAN_USER
再输入一次 DROP CATALOG 命令来确认目录删除
RMAN> drop catalog;
恢复目录已删除
--针对对表空间没有权限问题,在pl/sql上查询该用户有没有正确授权
select * from dba_role_privs where grantee='RMAN_USER';
--发现角色有正确授权,可能是角色没有生效导致
set role recovery_catalog_owner;
--再次到恢复管理器,创建恢复目录
RMAN> create catalog tablespace rman_tbs;
恢复目录已创建
--注册数据库
RMAN> register database;
注册在恢复目录中的数据库
正在启动恢复目录的全部重新同步
完成全部重新同步

猜你喜欢

转载自blog.csdn.net/Borntodieee/article/details/81164020