列出对应物 RMAN>list incarnation; 列出备份 概述可用的备份RMAN>list backup summary; B 表示 backup F 表示 FULL A 表示 archive log 表示 incremental backup S 说明备份状态 (AAVAILABLEX EXPIRED ) 按备份类型列出备份RMAN>list backup by file; 按照 数据文件备份归档日志备份控制文件备份服务器参数文件备份列出 列出详细备份RMAN>list backup 列出过期备份RMAN>list expired backup; 列出表空间和数据文件备份 list backup of tablespace 和list backup of datafile 输出和list backup 相似 如list backup of tablespace user_tbs; list backup of datafile ; 列出归档日志备份RMAN>list archivelog all;简要信息 RMAN>list backup of archivelog all;详细信息 列出控制文件和服务器参数文件 RMAN>list backup of controlfile; RMAN>list backup of spfile; ===================================================== ===================================================== RMAN 的 report命令 报告最近没有被备份的数据文件 RMAN>report need backup days=; 报告备份冗余或恢复窗口 RMAN>report needbackup redundancy=; RMAN>report need backup recovery window of days; 报告数据文件的不可恢复操作 RMAN>report unrecoverable; 报告数据库模式 RMAN>report schema; 报告丢弃的备份 如果使用了保存策略备份会标记为丢弃状态 RMAN>report obsolete;删除丢弃状态备份RMAN>delete obsolete; ===================================================== ===================================================== RMAN的crosscheck 命令 备份集有两种状态A(AvailableRMAN认为该项存在于备份介质上)X(Expired备份存在于控制文件或恢复目录中但是并没有物理存在于备份介质上) crosscheck 的目的是检查RMAN 的目录以及物理文件如果物理文件不存在于介质上将标记为Expired如果物理文件存在将维持Available如果原先标记为Expired 的备份集再次存在于备份介质上(如恢复了损坏的磁盘驱动器后)crosscheck将把状态重新从Expired标记回Available crosscheck 输出分两部分第一部分列出确定存在于备份介质上的所有备份集片第二部分列出不存在于备份介质上的备份集片并将其标记为Expired当设置备份保 存策略后一个备份过期crosscheck之后标记为丢弃的备份状态依旧为availabel要删除丢弃备份delete obsolete 示例 crosscheck backup crosscheck backup of datafile ; crosscheck backup of tablespace users; crosscheck backup of controfile; crosscheck backup of controlfile; crosscheck backup tag=SAT_BACKUP; crosscheck backup completed after sysdate crosscheck backup completed between sysdate and sysdate crosscheck backup device type sbt; crosscheck archivelog all; crosscheck archivelog like %ARC crosscheck archivelog from sequence ; crosscheck archivelog until sequence ; ===================================================== 使用delete expired archivelog all 命令删除所有过期归档日志 ===================================================== RMAN 的validate 命令 validate 命令验证备份集片是否能够被还原 list backup summary; 得到了备份集得主键ID如然后validate backupset ; ===================================================== ===================================================== RMAN 的备份保存策略以及change delete命令 带delete参数的change 命令删除备份集从备份介质并且从控制文件和恢复目录中删除 change backupset delete; change backuppiece delete; change archivelog until logseq = delete; 两类策略恢复窗口备份保存策略(recovery windows backup retension policy)基于时间 备份冗余备份保存策略(backup redundancy backup retension policy) 基于备份的数量 两类策略互相排斥 即使使用了备份保存策略备份到期并不删除只是在RMAN目录中标记为丢弃看到的状态依旧为available; 要查看标记为丢弃的备份 report obsolete只有使用delete obsolete才真正物理删除 nfigure retension policy to recovery window of days; configure retension policy to redundancy ; 显示结果 show all; 查看到期丢弃的备份时可能需要手工保存一些备份 可以使用change 命令带keep 参数使用这个命令后那些被修改的备份将被认为是个longterm backup不在受保存策略影响也就是说delete obsolete 也不删除 要使备份时候不受保存策略影响 使用带keep参数的backup 命令 backup database keep forever; backup database keep days; change 命令功能 可以修改备份为永久保存并将以及该备份的相关的日志保存下来保证总能将备份恢复到当前时间点 change backupset keep forever logs; 可以设置备份丢弃的新日期将备份在多保存 天 天后将删除 change backupset keep until time sysdata + logs; change 可以将备份集设置为unavailable change backupset unavailable; 标记为unavailable状态的备份集并不参与crosscheck; ===================================================== ===================================================== 恢复目录的记录删除 $ORACLE_HOME/rdbms/admin/prgrmancsql 脚本定期删除恢复目录中具有DELETED状态的记录 要删除旧的对应物记录incarnation必须从DBINC 表中删除这些对应物使用RC_DATABASE_INCARNATION 视图来确定要删除的对应物记录要删除的每个对应物的DBINC_KEY 随后启动SQL*Plus执行delete from dbinc where dbinc_key=; ===================================================== ===================================================== 手工同步恢复目录 resync catalog; Oracle同步恢复目录的时候首先创建快照控制文件然后比较这个文件和恢复目录完成后Oracle 更新恢复目录使恢复目录和控制文件同步 ===================================================== ===================================================== 在RMAN 中存储脚本 连接到目标数据库和恢复目录 rman target / catalog rman/rman@rmani 创建脚本 RMAN>create script my_bk_script >{backup database plus archivelog;} create script my_bk_script 打印脚本 RMAN>print script my_bk_script; printing stored scipt:my_bk_script {backup database plus archivelog;} 运行这个脚本备份目标数据库 RMAN>run {execute scipt my_bk_script;} 删除脚本 RMAN>delete script my_bk_script; ===================================================== ===================================================== archivelog模式下的完全恢复 stepset oracle_sid=recover rman target rman_backup/password configure controlfile autobackup on; stepbackup database plus archivelog delete input; stepshutdown immediate; step重命名所有的数据文件和控制文件不重命名联机重做日志 step: startup nomount; set DBID=**** restore controlfile from autobackup; alter database mount; step: restore database; recover database; alter database open resetlogs; 表空间恢复 sqlalter tablespace users offline; sqlalter tablespace tools offline; restore tablespace userstools; recover tablespace userstools; sqlalter tablespace users online; sqlalter tablespace tools online; 数据文件恢复 sqlalter database datafile offline; sqlalter database datafile d:oracleoradatausersdbf offline; restore datafile restore datafile d:oracleoradatausersdbf; recover datafile recover datafile d:oracleoradatausersdbf; sqlalter database datafile online; sqlalter database datafile d:oracleoradatausersdbfonline; ===================================================== ===================================================== 切换当前的incarnation 回到resetlogs 前RESET DATABASE TO INCARNATION inc_key ===================================================== ===================================================== RMAN 高级恢复 基于时间点的恢复 run { set until time to_date(// ::mm/dd/yy hh:mi:ss) restore database; recover database; alter database open resetlogs; } 基于SCN 的恢复 startup mount; restore database UNTIL SCN ; recover database UNTIL SCN ; alter database open resetlogs; 基于日志序列的恢复 startup mount; restore database UNTIL SEQUENCE thread ; recover database UNTIL SEQUENCE thread ; alter database open resetlogs; |