第十二章、RMAN 高级恢复主题
1. Resetlogs 表示一个逻辑生存期的结束和另一个逻辑生存期的开始,每次使用resetlogs 时,SCN 不会被重置,不过会重置其他计数器,如日志序列,同时还会重置联机重做日志的内容(如果必要,还可以重新创建联机日志)。
2. 基于时间点的不完全恢复:
Run{
Set until time “to_date( ‘date ’,’format ’)”;
Restore database;
Recover database;
Alter database open resetlogs;
}
Startup mount;
Restore database until time “to_date( ‘date ’,’format ’)”;
recover database until time “to_date( ‘date ’,’format ’)”;
alter database open resetlogs;
3. 基于SCN 的不完全恢复(不包含指定的SCN ):
Restore database until scn 10000;
Recover database until scn 10000;
4. 基于日志序列的不完全恢复:
Restore database until sequence 111 thread 1;
Recover database until sequence 111 thread 1;
5. 只读表空间的恢复:
默认情况下,RMAN 在restore 时不会还原只读的数据文件,要想恢复,必须指定:
Restore database check readonly;
Recover tablespace 或recover datafile 时,不管是否是只读的,都会执行恢复。
6. 归档日志还原:
Restore archivelog all;
Restore archivelog from logseq=22 thread=1;
Restore archivelog from logseq=22 until logseq=33 thread=1;
Run{
Set archivelog destination to “location ”; (将归档日志还原到新位置)
Restore archivelog all;
}
如果RMAN 认为一个归档重做日志已经存在,则不管是否指定了新的位置,都不会在磁盘上还原这个归档日志文件。
7. 从数据文件副本的还原:
Sql “alter database datafile 5/ ’xxx ’ offline ”;
Restore (datafile 5) from datafilecopy; (圆括号很重要!)
Recover datafile 5;
Sql “alter database datafile 5/ ’xxx ’ online ”;
8. 块介质恢复(Block Media Recover ,BMR ):
u Blockrecover datafile 19 block 44;
u Blockrecover datafile 19 block 44,55,66;
u Blockrecover datafile 19 block 44 datafile 20 block 55 datafile 21 block 66;
9. Backup validate database 命令会在v$backup_corruption 和v$database_block_corruption 视图中留下坏块记录,v$backup_corruption 记录的是历史错误信息,v$database_block_corruption 记录的是当前错误信息,如果块错误发生在复制期间,则在v$copy_corruption 视图中留下记录。
10. 批量修改坏块(还原最近5 天的所有坏块):
blockrecover corruption list restore until time ‘sysdate-5 ’;
11. 恢复到resetlogs 之前(incarnation 恢复):
u 查看历史incarnation 记录:list incarnation;
u 使用catalog 恢复到resetlogs 之前:
Startup force nomount;
Reset database to incarnation 2;
Restore controlfile;
Restore database until scn xxx; (xxx 为恢复到的resetlog scn-1 )
Recover database until scn xxx;
Alter database open resetlogs;
u 不使用catalog 恢复到resetlogs 之前(步骤类似,但是要确保当前控制文件中,包含要恢复到的incarnation 的信息)。
12. 表空间时间点恢复(TSPITR ):
n 确定要恢复到的时间点:这是非常重要的,在nocatalog 中,表空间的恢复是一次性的过程,如果恢复了错误的时间点,则不能重新来过,但是在catalog 中就没有这个限制。
n 确保表空间中的对象是自包含的:可以从ts_pitr_check 查看是否和其他表空间有关联,或者某些限制,如果没有返回任何行,则不存在冲突。
n 保存可能在恢复中丢失的对象或者数据:可以从ts_pitr_objects_to_be_dropped 视图查看可能在恢复期间丢失的对象。
n 执行实际的TSPITR:
Recover tablespace xxx until time “to_date( ‘date ’,’format ’)” auxiliary destination ‘location ’;
Sql ‘alter tablespace xxx online ’;
删除辅助实例:
SQL*Plus 中:exec dbms_backup_recovery.manageauxinstance( ‘aux_sid ’,1);
n 自定义选项:
Set newname 设置单个文件的新位置和名称。
Configure auxname 定义辅助实例的名称。
Set auxiliary instance parameter file 指示辅助实例的参数文件路径,或者通过在/rdbms/admin 中创建parms_auxint.ora 文件来实现同样的功能。
n 手工执行的TSPITR:
u 创建辅助实例步骤:1、创建口令文件;2 、创建参数文件;3 、NT OS 上添加服务,Linux/Unix 中跳过;4 、启动实例,检查网络。
u Run{
Set until time “to_date( ‘date ’,’format ’)”;
Restore clone controlfile;
Sql clone ‘alter database mount clone database ’;
Sql ‘alter system archive log current ’;
}
u TSPITR 需要的相关文件:1、System 表空间;2 、undo 表空间;3 、temp 表空间;4 、将要还原的表空间。
u 将执行恢复的表空间脱机:sql ‘alter tablespace xxx offline for recover ’;
u Run{
Set until time “to_date( ‘date ’,’format ’)”;
Set newname for clone datafile 1 to new/xxx; (如果是OMF ,则可使用new )
Set newname for clone tempfile 1 to xxx;
Set newname for clone datafile 7 to ‘location ’; (这里用真文件名,用于恢复)
Switch clone tempfile all;
Restore datafile 1,2,7;
Switch clone datafile all;
Sql clone ‘alter database datafile 1 online ’;
Sql clone ‘alter database datafile 2 online ’;
Sql clone ‘alter database datafile 7 online ’;
Sql clone ‘alter database mount clone database ’;
}
u Run{
Set until time “to_date( ‘date ’,’format ’)”;
Recover clone database tablespace “xxx ”,”xxx ”,”xxx ” delete archivelog;
Alter clone database open resetlogs;
}
u 将元数据从副本数据库中导出:
exp ‘sys/pwd as sysdba’ point_in_time_recover=y tablespace=xxx file=xxx
u 关闭副本数据库,然后将元数据导入到目标数据库:
Imp ‘sys/pwd as sysdba’ point_in_time_recover=y file=xxx
u 最后,将目标数据库中的还原表空间联机,恢复完成:
Alter tablespace xxx online;
u 善后工作:删除辅助数据库,备份刚恢复的表空间。
13. TSPITR 的限制:
l 不能恢复包含sys 用户特有对象的表空间,即表空间中不能有sys 对象;
l 不能恢复含有复制主表的表空间;
l 不支持使用快照日志的表空间;
l 不能还原含有回滚段的表空间;
l 不能回复含有下面类型对象的表空间:varray 、嵌套表、外部文件。
l 不能用于恢复删除的表空间,也不能恢复旧的对象统计表;
l 若没有使用catalog ,则回滚段在恢复期间不能发生变化;
l 若没有使用catalog ,则TSPITR 后,前面的备份就不能使用了,需要再次备份,才能执行下一个TSPITR 操作。
14. 验证备份的可恢复性:
l Restore database preview [recall];
l Restore database validate;
l Restore database check logical validate; (除了验证可恢复性,还会检查逻辑错误,并且填充v$database_block_corruption 视图)
l 检查特定的备份集:validate backupset 11 [check logical];
15. 跨平台的数据库移动:可通过v$transportable_platform 视图来确定不同系统的尾数格式(endian format )。
l 源站点上转换:convert tablespace xxx to platform. ‘platform_name ’
Db_file_name_convert= ’C:\old_dir ’,’C:\new_dir ’;
l 目标站点转换“convert datafile= ’C:\xxx\* ’ from platform. ‘platform_name ’
Db_file_name_convert= ’c:\old_dir ’,’C:\new_dir ’;
l 跨平台移动步骤:
u 以只读方式打开数据库:
startup mount;
alter database open read only;
u 检查数据库状态:
declare
db_ready boolean;
begin
db_ready:=dbms_tdb.check_db('platform_name',dbms_tdb.skip_readonly);
end;
/
u 标识外部对象:
declare
db_external boolean;
begin
db_external:=dbms_tdb.check_external;
end;
/
u 使用RMAN 的convert database 命令产生脚本
Convert database new database ‘xxx ’ transport script. ‘script_dir ’ to platform. ‘planform_name ’;
第13 章、从用户错误中恢复,闪回技术
16. 如果启用表空间或数据文件的自动扩展,那么回收站对象空间就会在自动扩展之前被删除,从而释放空间。
17. 闪回数据库需要一种新的类型的日志,闪回日志,必须要在FRA 中保存闪回日志,不能再其他别的地方创建闪回日志。
18. 一旦启动了flashback database ,Oracle 就会跟踪闪回日志,并在v$flashback_database_log 中留下记录(该视图中只有一条汇总的记录),若要查看闪回日志的具体活动,可查看v$flashback_database_stat 视图,该视图提供了一段时间内闪回日志的相关信息(一般是从sysdate 向后扩展一小时的记录)。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24465008/viewspace-688023/ ,如需转载,请注明出处,否则将追究法律责任。