10 OCM考试大纲关于RMAN的考点:
三 Managing Database Availability
﹡ Create a recovery catalog database
﹡ Configure Recovery Manager
﹡ Use Recovery Manager to perform database backups
﹡ Use Recover Manager to perform complete database restore and recovery operations
整理rman日常操作如下:
1 备份
1.1 指定backup piece的大小
将较大的backupset分解为多个bakcup piece。
Rman> run {
Allocate channel c1 device type disk maxpiecesize 500m;
Backup database format ‘$ORACLE_BASE/backup’;
}
1.2 使用command file
将多条rman命令包含在command file中,批量执行,常用于数据库例行备份。
Cat > rman.csv
run {
backup datafile 1 format '$ORACLE_BASE/backup/system_%U.bpk';
backup datafile 2 format '$ORACLE_BASE/backup/sysaux_%U.bpk';
}
执行备份:
$ rman target / cmdfile=rman.rcv log=rman.log
1.3 备份时排除表空间
1.3.1 排除指定的表空间
设置备份时要排除的表空间:
Rman> configure exclude for tablespace users;
永久取消排除:
Rman> configure exclude for tablespace users clear ; -
临时取消排除:
Rman> backup database noexclude;
1.3.2 排除只读表空间和离线表空间
Rman> backup database skip readonly skip offline;
1.4 并行备份
1.4.1 永久配置PARALLELISM
Rman> CONFIGURE DEVICE TYPE DISK PARALLELISM 5 BACKUP TYPE TO BACKUPSET;
执行备份时,自动开5个channel进行备份,备到同一目录下。
通过配置channel可以备份到不同目录下:
Rman> CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET;
Rman> CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT '/u01/app/oracle/backup/%d_%s_%p.bpk';
CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT '/u01/app/oracle/backup2/%d_%s_%p.bpk';
1.4.1 临时配置PARALLELISM
通过allocate channel分配多个通道。
Rman> run {
Allocate channel c1 device type disk;
Allocate channel c2 device type disk;
Backup database format ‘$ORACLE_BASE/backup/db_%U.bpk’
(datafile 1,2,3 channel c1)
(datafile 4,5,6 channel c2);
}
1.5 copy备份
1.5.1 copy备份的方式
可以采取下面两种方式:
1、backup as copy
Rman> backup as copy datafile 4 format ‘$ORACLE_BASE/backup/users.dbf’;
2、copy
Rman> copy datafile 1 to ‘$ORACLE_BASE/backup/users.dbf’;
1.5.2 删除copy
Rman> delete datafilecopy 30;
删除key=30的copy。
1.6 备份的高级功能
1.6.1 filesperset
指定一个backupset中最多包含几个数据文件。
Rman> backup database filesperset 2;
每个备份集中最多只包含两个数据文件。
1.6.2 set maxcorrupt
设置备份时能跳过多少个坏块,默认为0,即一发现坏块,备份任务会报错退出。
Rman> run {
Set maxcorrupt for datafile 4 to 5; #允许5个坏块
Backup check logical datafile 4;
}
1.6.3 开启块改变跟踪
Sql> alter database enable block change tracking using file ‘tracking.f’ reuse;
2 恢复
2.1 将数据文件恢复到新的位置
出现硬件损坏时,需要将数据文件恢复到新的目录下。
Run {
Sql ‘alter tablespace users offline immediate’;
Set newname for datafile 4 to ‘/newpath/user.dbf’;
Restore datafile 4;
Swith datafile 4;
Recover datafile 4;
Sql ‘alter tablespace users online’;
}
2.2 基于SQL的不完全恢复
2.2.1 基于time恢复
将数据库恢复到过去一个时间点。
Sql> startup mount
Sql> recover database until time ‘2011-07-08 10:05:00’;
Sql> alter database open resetlogs;
下面是两个关于scn和time转换的函数。
注:通过时间得到scn
select timestamp_to_scn(to_timestamp('2011-07-05 10:30:00','yyyy-mm-dd hh24:mi:ss')) from dual;
通过scn得到时间:
select scn_to_timestamp(1418437) from dual;
2.2.2 基于scn恢复
将数据库恢复到过去的一个scn。
Sql> startup mount
Sql> recover database until scn 1418437;
Sql> alter database open resetlogs;
2.2.3 基于cancel恢复
当archivelog或onlinelog损坏,将数据库尽可能地恢复,最大限度地减少数据丢失。
Sql> startup mount
Sql> recover database until cancel; #可能需要选择online log,进行恢复
ORA-00279: change 1426537 generated at 07/06/2011 20:59:43 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/archive/1_44_754155512.dbf
ORA-00280: change 1426537 for thread 1 is in sequence #44
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
+DGROUPB/dg1/onlinelog/redo5.log #选择恢复需要的日志文件
Sql> alter database open resetlogs;
2.2.4 基于sequence恢复
根据online log sequence进行恢复,
Sql> startup mount
Sql> recover database until sequence 128; 将数据库恢复到log sequence 127
Sql> alter database open resetlogs;
2.2.5 通过备份控制文件恢复
1)备份控制文件
Sql> alter database backup controlfile to trace;
将控制文件创建语句写入user trace文件。或者
Sql> alter database backup controlfile to ‘/backup/control01.ctl’;
将控制文件备份。
2)恢复
Sql> startup nomount;
重建控制文件,从user trace找到创建控制文件的语句,执行:
Sql> recover database using backup controlfile;
ORA-00279: change 1426537 generated at 07/06/2011 20:59:43 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/archive/1_44_754155512.dbf
ORA-00280: change 1426537 for thread 1 is in sequence #44
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
由于是重建控制文件,找不到当前recover需要应用的日志,需要指定log文件:
+DGROUPB/dg1/onlinelog/redo5.log
Log applied.
Media recovery complete.
Resetlogs方式打开数据库:
Sql> alter database open resetlogs;
通过备份控制文件恢复数据库,tempfile不会自动产生,需通过手工创建:
Sql> alter tablespace temp add tempfile '+dgroupb/dg1/datafile/temp01.dbf';
2.3 基于rman的不完全恢复
2.3.1 基于time的恢复
Sql> startup mount;
Run {
Set until time = ‘2011-07-08 11:30:30’;
Restore database;
Recover database;
Alter database open resetlogs;
}
2.3.2 基于sequence的恢复
Sql> startup mount;
Run {
Set until sequence 128 thread 1;
Restore database;
Recover database;
Alter database open resetlogs;
}
2.3.3 基于scn的恢复
Sql> startup mount;
Run {
Set until scn 1418437;
Restore database;
Recover database;
Alter database open resetlogs;
}
2.3.4 基于还原点的恢复
Sql> create restore point p1
Rman> restore database;
Rman> recover database until restore point p1;
2.3.5 通过备份控制文件进行不完全恢复
1)控制文件备份
Rman> CONFIGURE CONTROLFILE AUTOBACKUP on;
或
Rman> backup current confile format ‘/backup/control%.bpk’;
或
Rman> backup database including current controlfile;
2)从备份控制文件恢复数据库
Sql> startup nomount;
Rman> restore controlfile to ‘/control01.ctl’ from autobackup; 或
Rman> restore controlfile from ‘备份集名称’;
Rman> run {
Alter database mount;
Restore database;
Recover database;
Alter database open resetlogs;
}
|