ITPub博客

首页 > Linux操作系统 > Linux操作系统 > rman命令的简单介绍

rman命令的简单介绍

原创 Linux操作系统 作者:caisanpx 时间:2013-10-23 00:42:03 0 删除 编辑
RMAN的简单介绍:rman是oracle自带的备份恢复工具,可以直接运行在dos上。
运行rman之前必须先启动加载你要使用的数据库。

关于rman的命令

backup database;
backup database format 'e:/app/rman/backup/full_bak.bak';--指点备份到哪个目录
list backup of database;查看备份集信息

backup tablespace users format '文件地址';备份表空间

backup database '文件地址'/'序号';备份数据文件

backup current controlfile;备份控制文件主动备份
backup database include current controlfile;附带备份
list backup of controlfile;
configure controlfile autobackup on;RMAN做任何备份都会自动备份控制文件

backup archivelog all--备份归档日志
backup current controlfile plus archivelog 备份控制文件前先备份归档日志文件
backup archivelog all delete all input备后份归档日志文件删除先前的归档日志

对备份集进行备份
备份所有备分集backup backupset all;
指定备份集 backup backupset n;

查看RMAN的配置参数

RMAN>show all
db_unique_name 为 ORCL 的数据库的 RMAN 配置参数为:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 4 BACKUP TYPE TO COPY;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT   'e:/app/';
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOA
D TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO 'E:\APP\CJ\PRODUCT\11.2.0\DBHOME_1\DATABA
SE\SNCFORCL.ORA'; # default

list device type disk backup;列出某个设备上的所有信息
list archivelog all列出数据库当前的所有归档;
list expired backup;列出所有无效备份

#delete命令
删除过期的备份 delete obsolete;
删除无效备份:delete expired backup;
删除expired副本 delete expired copy;
删除特定备分集 delete backupset 1;
删除特定备份片 delete backuppiece  '文件地址'
删除所有备份集 delete backup
删除特定映像副本 delete datafile copy '文件地址'
删除所有映像 delete copy
在备份后删除输入对象 backup archivelog all delete input

#report命令主要是用于当前备份信息的分析
report need backup 查看需要备份的文件
report need backup tablespace system; 查看指点表空间是否需要备份
report obsolete 查看过期的备份


#crosscheck命令检查备份或归档文件的状态
crosscheck archivelog all; 检查所有归档日志
crosscheck backup; 检查所有备份集


#change命令用来修改备份文件或归档文件的状态
改变备份集的状态 unavailable不可用 available可用
change backup of tablespace users unavailable; 修改指定表空间备份集为unavailable
change archivelog logseq=n unavailable; 修改指定文档文件状态为unavailable;

#增量备份
backup incremental level=0 database; 建立增量级别为0的全库备份
backup incremental level=1 datafile '文件地址'; 为数据文件建立增量级别为1的备份;
backup incremental level=1 tablespace tbsp 问表空间建立增量级别为1的备份

#增量备份类型
differential(差异) 和cumulative(累积) 前者为默认的
backup incremental level=1 comulative database;

#启用快修改跟踪
创建一个跟踪文件
alter database enable block change tracking using file 'e:/app/rman/backup/trk_file';
关闭跟踪文件
alter database disable block change tracking;
查看跟踪文件状态
select * from v$block_change_tracking;

#基于时间的备份保留策略
设置数据库最早能恢复到几天前
configure retention policy to recovery window of n days

#基于冗余数量的备份保留策略
configure retention policy to redundancy n; 最大冗余为n;
configure retention policy to none;


#手动分配通道
run{
allocate channel c1 device type disk format ''
backup tablespace users;
}

configure device type sbt/disk parallelism n;
configure default device type to sbt/disk;
configure channel device type sbt/disk format...;
configure channel n device type sbt/disk format...;


#复合备份
run{
set backup copies 2;
backip device type disk format '',''
tablespace users,system;
}
将生成的两个表空间备分集存放在‘’,''目录

configure datafile backup copies for device disk to 2;备份的数据文件数量为2
configure archivelog backup copies for device disk to 2;


#设置备份集标签
backup tablespace users tag tag_userstbspc;


#设置备份片段大小
run{
allocate channel c1 device type disk maxpiecesize format ''
backip tablespace system;
}


#创建恢复目录
创建一个表空间 create tablespace tbs_rman datafile 'e:/app/ORCL/datafile/tbs_rman.bdf' size 50m;
SQL>  create tablespace tbs_rman datafile 'e:/app/ORCL/datafile/tbs_rman.bdf' si
ze 50m;

表空间已创建。
创建一个用户记录备份信息,并授予权限
grant resource,connect,recovery_catalog_owner to user_rman identified by user_rman;
SQL>
SQL> grant resource,connect,recovery_catalog_owner to user_rman identified by us
er_rman;

授权成功。

通过rman连接到恢复目录
rman catalog  user_rman/user_rman;
C:\Users\cj>rman catalog  user_rman/user_rman;

恢复管理器: Release 11.2.0.1.0 - Production on 星期二 10月 22 16:46:50 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

连接到恢复目录数据库

连接到恢复目录后创建catalog
create catalog tablespace tbs_rman;
RMAN> create catalog tablespace tbs_rman;

恢复目录已创建

使用恢复目录备份前要在恢复目录注册数据库
C:\Users\cj>rman target / catalog user_rman/user_rman@orcl;

恢复管理器: Release 11.2.0.1.0 - Production on 星期二 10月 22 16:52:13 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

连接到目标数据库: ORCL (DBID=1327337757)
连接到恢复目录数据库

RMAN> register database;

注册在恢复目录中的数据库
正在启动全部恢复目录的 resync
完成全部 resync


#对备份集表空间进行压缩
backup as compressed backupset tablespace system;


#加密
configure encryption for database on;

RMAN> configure encryption for database on;

新的 RMAN 配置参数:
CONFIGURE ENCRYPTION FOR DATABASE ON;
已成功存储新的 RMAN 配置参数
正在启动全部恢复目录的 resync
完成全部 resync

对表空间进行加密
configure encryption for tablespace users on;

用set encryption 进行加密
set encryption on identified by "encryption" only;
backup tablespace users;
该备份恢复的时候就要密钥


#rman批处理文件
run{
configure retention policy to recovery window of 14 days;
configure controlfile autobackup on;
configure controlfile antobackup format for device type disk to 'e:/app/rman/backup/%f';
allocate channel c1 device type disk format 'e:/app/rman/backup/a%';
backup databasae skip inaccessible
plus archivelog filesperset 20
delete all input;
release c1;
}
allocate channel for maintenance device type disk;
crosscheck backupset;
delete noprompt obsolete;

保存到'e:/app/rman/backup/test.rman'

编写命令执行批处理
set ORACLE_SID=cj
rman target /
log e:/app/rman/backup/logs/bak_%date:~0,10%.log cmdfile=e:/app/rman/backup/test.rman

save as e:/app/rman/backup/test.bat

configure archivelog deletion policy to applied on standby;


#常在Run快中运行的命令
给数据文件指定新的路径和名称
run{
allocate channel c1 device type disk;
set newname for datafile datafile_name '新地址';
}

run{
allocate channel c1 device type disk;
set newname for datafile datafile1 'e:/app/rman/backup/new_datf1.dbf';
}

设置恢复到的时间点或scn
run{
allocate channel c1 device type disk;
set until time "to_date('2013',yyyy-mm-dd hh24:mi:ss)";
}


设置备份片段的冗余数
run{
allocate channel c1 device type disk;
set backup copies 3;
}


设置新的归档文件地址
run{
allocate channel c1 device type disk;
set archivelog destination to '';
}


v$archive_log视图
v$backup_set
v$backup_piece
v$backup_corruption 记录了备份集损坏的数据块















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

请登录后发表评论 登录
全部评论

注册时间:2012-04-12

  • 博文量
    165
  • 访问量
    442540