RMAN介绍及使用
- 可以备份库、表空间、数据文件、控制文件及日志文件 exp不能备份控制文件/数据文件和日志文件
- 压缩备份可以之备份变化的内容
- 集成第三方磁带媒介软件
- 可以在oracle数据库的目录中存放备份信息,及用数据库管理备份信息
RMAN常用概念
- 目标库
- 客户端
- 闪回区(Flash Recovery Aera):存放备份和恢复相关信息的磁盘区域
- 介质管理 (System Backup to)
- 恢复目录(Recovery Catalog):一个独立的数据库,用于存放目标数据库的备份,可以存放多个数据库。
恢复目录
一般创建在异地设备中。
-
创建恢复目录
- 创建恢复目录数据库并创建用户
- 给恢复目录用户赋角色和权限
- 创建恢复目录
create tablespace rmtablesapce datafile 'e:\app\admin\oradata\orcl\rmtablespace.DBF' size 100m autoextend on next 10m maxsize 500m permanent extent management local;
create user rm identified by "123456" default tablespace rmtablespace temporary tablespace temp quota unlimited on rmtablespace profile default account unlock;
grant dba to rm; grant connect to rm; grant resource to rm; grant recovery_catalog_owner to rm;
rman --进入恢复目录管理器
connect catalog rm/123456 --通过创建好的恢复目录用户连接到恢复目录数据库。
create catalog --创建恢复目录
RMAN连接恢复目录
rman target user/password@servicename catalog user/password@servicename
RMAN通道分配
确定连接数据库备份的设置个数
通道–>设备与库进行关联
手动分配:run
自动分配:configure
手动分配
run {allocate channel ch_name1 device type typename1; allocate channel ch_name2 devices type typename2; ... backup... }
register database
run --单通道备份 {allocate channel c device type disk; backup tablespace users; }
- 通道备份后会自动释放
- run备份一定在rman命令状态下,并且连接到恢复目录和目标数据库前提下。
run {allocate channel c1 device type disk; allocate channel c2 device type disk; backup tablespace users }
自动分配
数据库自己定义分配数量和名称,但管理员徐定义参数(介质类型、通道最大个数、默认介质类型)
configure device type typename parallelism n --最大通道数 configure default device type to typename --默认介质类型
configure device type disk parallelism 3; congigure default device type to disk; backup tablespace users;
RMAN备份
- 备份集
- 备份片
backup [level] [backup_type] [option]
level:1 2 3 4 full
backup_type:database、datafile、tablespace、archivelog all
option:channel、maxsize
backup full tablespace users;
RMAN恢复
RESTORE还原
restore object
object:database、datafile、tablespace、archivelog、controfile
restore:还原
RECOVER恢复
recover object;
object:与restore语法一致
FlashBack开启
-
开启归档日志
mount状态:alter database archivelog;
-
设置闪回区
alter system set db_recovery_file_dest='C:\app\Administrator\flash_recovery_area' scop=both;
alter system set db_recovery_file_dest_size=4G scop=both;
alter system set db_recovery_retention_target=4320 scop=both;
- 在mount状态下,开启flashback
alter database flashback on;