关于rman backup
这篇文章写的非常不错
最新题库 & 考试交流 & 培训班视频
+微信 cycleyu
https://blog.csdn.net/zwwdll/article/details/19155745
RMAN备份
1、spfile和controlfile的自动备份
当configure controlfile autobackup off时,仅当备份system01.dbf时才会自动备份controlfile和spfile;
当configure controlfile autobackup on时,当任意文件备份时,都会自动备份controlfile和spfile;
2、备份整个库
backup database;
backup databse plus achivelog; 同时备份归档日志
3、备份表空间和数据文件
备份users空间到磁带上: backup device type sbt tabelspace users;
备份1到4的数据文件及/tmp/system01.dbf: backup device type sbt datafile 1,2,3,4 datafilecopy '/tmp/system01.dbf';
4、非归档模式的备份(仅一致性备份)
shutdown immediate;
startup mount;
backup incremental level 0 maxsetsize 10m database tag ‘back_1’;
5、备份归档日志
执行其他备份时加上plus archivelog或 backup archivelog all 或 backup archivelog from sequence 100 until sequence 125;
archived redo log failover功能:当某个归档文件损坏了,RMAN会自动扫描该文件的其他拷贝;
自动归档redo日志:备份前,RMAN会执行alter system archive log current来归档所有未归档的redo日志,再备份,备份结束后,再一次归档在线redo日志;
备份后删除归档日志文件:可在备份语句中加上delete [all] input子句;
7、增量备份
0级增量:backup incremental level 0 database;
1级differential备份:backup incremental level 1 [differential] tablespace users;
1级cumulative备份:backup incremental level 1 cumulative tablespace users;
8、备份输出选项
指定备份集存放设备:configure default device type; 或 backup database device type disk;
指定备份集类型:backup as copy device type diskdatabase;( 即image copy )
backup as backupset database;
backup as backupset device type disk database;
backup as backupset device type sbt database;
指定备份集文件命名规则:backup database format ‘+dggroup1'; 存放到名为dggroup的磁盘组上
backup database format "/disk1/backup_%U"; /disk目录下,%U表示每次备份集文件名要不同
9、指定tag
使用tag标记备份集,多个备份集可公用一个tag,若不显示指定,则每个备份集默认一个tag
backup as backupset copies 1 datafile 7 tag xxxx
RMAN恢复
1、完全恢复整个DB,步骤如下:
确保DB处于mount状态,未open;
RMAN> restore database; 文件还原到应存放位置;
RMAN> recover database; 执行恢复,redo及归档日志中为应用内容将应用到DB中;
打开DB;
2、恢复controlfile,步骤如下:
RMAN> list backup of controlfile; 检查备份文件;
确保DB处于nomount状态;
RMAN> restore controlfile from autobackup; 文件还原到应存放位置;
修改DB为mount状态;
RMAN> recover database; 执行恢复;
SQL> alter database open resetlogs; 打开DB,resetlog,即
其他RMAN命令:
1、删除备份集或镜像
crosscheck backup(copy); 必须先检验有哪些备份集和镜像
delete backup(copy); 删除所有备份或镜像
2、report 用于判断DB的当前恢复状态和提供DB备份的特定信息
2.1 指定最近没有备份过数据文件
RMAN> report need backup days=3; 3天内没有备份过的表空间
RMAN> report need backup incremental=3; 需要多少个增量备份文件才能恢复的数据文件;
2.2 报告备份冗余或恢复窗口,确定为满足备份冗余策略而需要备份的数据文件
RMAN> report need backup redundancy 2; 文件备份冗余度少于2个,若是1,则表示文件没有任何备份
RMAN> report need backup recovery window of 1 days; 为备份建立一个时间值最小的恢复窗口,且报告备份时间长于这个恢复窗口的数据文件(报告出恢复需要1天归档日志的数据文件)
2.3 报告不可恢复的数据文件
RMAN> report unrecoverable;
2.4 报告DB的模式(数据文件名、文件号、对应表空间、文件大小、是否含有回滚段)
RMAN> report schema;
2.5 报告丢失的备份
RMAN> report obsolete;
3、LIST命令
list incarnation; 汇总查询
list backup summary; 概述可用的备份
list backup by file; 按照文件类型分别列出
list backup; 列出已有备份集的详细信息
list expired backup; 列出过期的备份文件
list backup of {archivelog,controlfile,database,datafile,spfile,tablespace};
list backup of archivelog {all,from,high,like,logseq,low,scn,sequence,time,until};
list copy; 列出镜像
list copy of database;
list copy of controlfile;
list copy of tablespace users;
list copy of datafile n,n,n;
list copy of archivelog all;
list copy of archivelog from scn 100;
list copy of archivelog until sequence 11;
4、设置备份标记
backup database tag=‘full_bak1’; 每个标记都是唯一的,相同标记可用于多个备份只还原最新的那个;
5、设置备份集大小
backup database maxsetsize=100m tag='datafile1'; 这里的大于DB总数据文件大小,否则报错;
6、设置备份片大小(文件系统限制)
run {
allocate channel c1 type disk maxpicesize 100m format '/home/oracle/app/flash_recovery_area/ORA11G/backupset/full_0_%U_%T';
backup database tag='full_0';
release channel c1;
}
也可configure中配置
configure channel device type disk maxpiecesize 100m;
configure channel device type disk clear;
7、备份集的保存策略
backup database keep forever; 永久保留
backup database keep until time='sysdate+30'; 保存备份30天
8、重写configure exclude 配置RMAN,排除上一次备份以来没有发生变化的数据文件,若要备份该些文件,则用noexclude
backup databse noexclude(exclude) keep forever tag='full_backup';
9、检查DB错误
backup validate database; 扫描DB的逻辑和物理错误,不执行实际备份
10、跳过脱机、不可存取、只读文件
backup database skip readonly;
backup database skip offline;
backup database skip inaccessible;
backup database skip readonly skip offline skip inaccessible;
11、强制备份
backup database force;
12、基于上次备份时间备份数据文件
1>只备份添加的新文件 backup database not backed up;
2>备份在限定周期内未备份的文件 backup database not backed up since time='sysdate-2';
3>备份期间检查逻辑错误
backup check logical database;
backup validate check logical database;
13、生成备份副本
backup database copies=2;
14、备份控制文件
backup database device type disk include current controlfile;