ITPub博客

首页 > 数据库 > Oracle > 使用存储脚本还原恢复数据库

使用存储脚本还原恢复数据库

原创 Oracle 作者:hooca 时间:2016-04-07 11:11:51 0 删除 编辑
如果要使用存储脚本,首先需要启用恢复目录。

1. 创建存储脚本

点击(此处)折叠或打开

  1. #RMAN连接到恢复目录
  2. rman target / catalog rcowner/oracle@rcata

  3. #创建备份用脚本
  4. create script bak_db_arch
  5. comment 'backup database plus archivelog, then clean archivelog.'
    {
    allocate channel c1 device type disk;
    allocate channel c2 device type disk;
    backup database plus archivelog;
    delete noprompt archivelog all;
    release channel c1;
    release channel c2;
    }
  6. #创建还原脚本
  7. create script restore_db
  8. comment 'restore database, then db can be recovered.'
    {
    restore spfile;
    shutdown immediate;
    startup nomount;
    restore controlfile;
    alter database mount;
    allocate channel c1 device type disk;
    allocate channel c2 device type disk;
    restore database;
    release channel c1;
    release channel c2;
    }
  9. #创建恢复脚本,需要用到替换变量
  10. create script recover_db
    {
    set until sequence &1 thread &2;
    recover database;
    alter database open resetlogs;
    }
  11. #注意:在有替换变量的这一行,RMAN会立即要求输入初始值,因此不能将整段语句直接粘贴上去!
以下是一些与存储脚本有关的命令

点击(此处)折叠或打开

  1. # 查看恢复目录里有哪些脚本,同时会显示comment
  2. list script names;

  3. # 查看脚本内容
  4. print script <脚本名>;

  5. # 编辑脚本
  6. replace script ......与创建命令相同)

  7. # 删除脚本
  8. delete script <脚本名>;
接下来,先执行备份

点击(此处)折叠或打开

  1. run { execute script bak_db_arch; }
然后故意破坏参数文件

点击(此处)折叠或打开

  1. mv spfileprod.ora spfileprod.ora.old
在RMAN中启动到nomount

点击(此处)折叠或打开

  1. RMAN> startup nomount
然后执行restore脚本

点击(此处)折叠或打开

  1. RMAN> run { execute script restore_db; }
完成后,查看日志序列号和线程号,这个将在恢复时用到。

点击(此处)折叠或打开

  1. RMAN> list backup by file;

  2. List of Archived Log Backups
  3. ============================

  4. Thrd Seq Low SCN Low Time BS Key S #Pieces #Copies Compressed Tag
  5. ---- ------- ---------- ------------------- ------- - ------- ------- ---------- ---
  6. 1 2 4471363 2016-04-02 09:00:53 1104 A 1 1 NO TAG20160407T084606
  7. 1 3 4532043 2016-04-04 01:00:10 1104 A 1 1 NO TAG20160407T084606
  8. 1 4 4607063 2016-04-06 00:30:18 1105 A 1 1 NO TAG20160407T084606
  9. 1 1 4625382 2016-04-06 12:55:14 1106 A 1 1 NO TAG20160407T084606
  10. 1 1 4626459 2016-04-06 13:20:54 1107 A 1 1 NO TAG20160407T084606
  11. 1 2 4656086 2016-04-07 08:46:00 1142 A 1 1 NO TAG20160407T085111
执行恢复脚本

点击(此处)折叠或打开

  1. RMAN> print script recover_db;

  2. printing stored script: recover_db
  3. {
  4. set until sequence &1 thread &2;
  5. recover database;
  6. alter database open resetlogs;
  7. }

  8. RMAN> run { execute script recover_db; }

  9. executing script: recover_db

  10. Enter value for 1: 3

  11. Enter value for 2: 1

  12. executing command: SET until clause

  13. Starting recover at 2016-04-07 09:17:40
  14. allocated channel: ORA_DISK_1
  15. channel ORA_DISK_1: SID=63 device type=DISK

  16. starting media recovery

  17. archived log for thread 1 with sequence 2 is already on disk as file /u01/app/oracle/oradata/prod/disk1/redo02a.log
  18. archived log file name=/u01/app/oracle/oradata/prod/disk1/redo02a.log thread=1 sequence=2
  19. media recovery complete, elapsed time: 00:00:00
  20. Finished recover at 2016-04-07 09:17:46

  21. database opened
  22. new incarnation of database registered in recovery catalog
  23. starting full resync of recovery catalog
  24. full resync complete
完成!

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

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

注册时间:2009-09-29

  • 博文量
    215
  • 访问量
    403421