ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 使用RMAN实现异机备份恢复(WIN平台)

使用RMAN实现异机备份恢复(WIN平台)

原创 Linux操作系统 作者:beatony 时间:2011-07-29 14:40:02 0 删除 编辑

使用RMAN实现异机备份恢复(WIN平台)

分类: RMAN 备份恢复 16人阅读 评论(0) 收藏 举报
--=================================
-- 使用RMAN实现异机备份恢复(WIN平台)
--=================================


    在有些情况下,如数据库服务器处于磁盘空间的压力或成本控制需要将数据文件备份到异机,使用RMAN可以完成该工作。基于Windows平台
所需完成的配置相对简单,仅仅是添加账户与使用新增的帐户来启动数据库服务以及设置共享路径。
    下面给出具体描述。
    
一、配置数据库服务器与备份目的主机
    1. 帐户配置(假定有主机A,B 且A为数据库服务器,B为备份目的主机,且能互相ping通)    
            如果主机A与主机B使用的Administrator密码相同,且A上的OracleServiceDBNAME服务和OracleOraHome92TNSListener服务都以"本
        地系统账户登陆"
            如果主机A与主机B使用不同的Administrator密码,处于安全考虑不宜设为相同,则则可以分别在主机A与主机B上新建一用户,假
        定在主机A上建立DBA_oracle,密码为ORA_PWD,则在主机B上也建立该用户(用户名可以不同,密码必须相同),密码同样设置为ORA_PWD
        。将刚建好的用户在各自主机将其加入到Aministrators组
    2. 设定OracleServiceDBNAME服务和OracleOraHome92TNSListener服务的启动帐户。在运行处输入services.msc。在主机A上设定使用此帐
        户登陆,即使用刚刚建立的DBA_oracle,输入密码启动,该设置需要重启后有效
    3. 在主机B上设定共享文件夹,如RMAN_Shared,设置其权限为完全控制(在A上使用\\IP\RMAN_Shared测试是否可写入文件)
        
二、查看RMAN的配置与数据库情况       
  1. RMAN> show CONTROLFILE AUTOBACKUP;                                                                                 
  2.                                                                                                                    
  3. RMAN 配置参数为:                                                                                                   
  4. CONFIGURE CONTROLFILE AUTOBACKUP ON;    -->控制文件自动备份,建议开启                                               
  5.                                                                                                                    
  6. RMAN> show CONTROLFILE AUTOBACKUP FORMAT;                                                                          
  7.                                                                                                                    
  8. RMAN 配置参数为:                                                                                                   
  9. CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '\\192.168.1.151\RMAN_Shared\CONTROL               
  10. _%F';                                   -->控制文件备份位置                                                         
  11.                                                                                                                    
  12. RMAN> show SNAPSHOT CONTROLFILE NAME;                                                                              
  13.                                                                                                                    
  14. RMAN 配置参数为:                                                                                                   
  15. CONFIGURE SNAPSHOT CONTROLFILE NAME TO 'D:\ORACLE\ORA92\DATABASE\SNCFTESTHH.ORA'; # default   -->快照控制文件位置   
  16.                                                                                                                    
  17. SQL> select * from v$version;    -->数据库的版本,当前演示环境为Oracle 9i                                           
  18.                                                                                                                    
  19. BANNER                                                                                                             
  20. ----------------------------------------------------------------                                                    
  21. Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production                                                         
  22. PL/SQL Release 9.2.0.1.0 - Production                                                                              
  23. CORE    9.2.0.1.0       Production                                                                                 
  24. TNS for 32-bit Windows: Version 9.2.0.1.0 - Production                                                             
  25. NLSRTL Version 9.2.0.1.0 - Production                                                                              
  26.                                                                                                                    
  27. SQL> show parameter db_name                                                                                        
  28.                                                                                                                    
  29. NAME                                 TYPE        VALUE                                                             
  30. ------------------------------------ ----------- ---------------                                                    
  31. db_name                              string      testHH                                                            
RMAN> show CONTROLFILE AUTOBACKUP; RMAN 配置参数为: CONFIGURE CONTROLFILE AUTOBACKUP ON; -->控制文件自动备份,建议开启 RMAN> show CONTROLFILE AUTOBACKUP FORMAT; RMAN 配置参数为: CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '\\192.168.1.151\RMAN_Shared\CONTROL _%F'; -->控制文件备份位置 RMAN> show SNAPSHOT CONTROLFILE NAME; RMAN 配置参数为: CONFIGURE SNAPSHOT CONTROLFILE NAME TO 'D:\ORACLE\ORA92\DATABASE\SNCFTESTHH.ORA'; # default -->快照控制文件位置 SQL> select * from v$version; -->数据库的版本,当前演示环境为Oracle 9i BANNER ---------------------------------------------------------------- Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production PL/SQL Release 9.2.0.1.0 - Production CORE 9.2.0.1.0 Production TNS for 32-bit Windows: Version 9.2.0.1.0 - Production NLSRTL Version 9.2.0.1.0 - Production SQL> show parameter db_name NAME TYPE VALUE ------------------------------------ ----------- --------------- db_name string testHH
三、备份数据库并关闭数据库,删除system01.dbf文件
    使用备份脚本对数据库进行备份,备份脚本在最后给出   
  1. D:\>rman target robinson/robin@testhh cmdfile=D:\oracle\oradata\testHH\backup.rman log=D:\oracle\ora    
  2. data\testHH\backup.log                                                                                  
D:\>rman target robinson/robin@testhh cmdfile=D:\oracle\oradata\testHH\backup.rman log=D:\oracle\ora data\testHH\backup.log
四、从异机进行还原与恢复
    1.关闭数据库        
  1. SQL> shutdown immediate;    
  2. 数据库已经关闭。            
  3. 已经卸载数据库。            
  4. ORACLE 例程已经关闭。       
SQL> shutdown immediate; 数据库已经关闭。 已经卸载数据库。 ORACLE 例程已经关闭。
    2.删除system01.dbf数据文件以便测试恢复       
  1. SQL> ho del D:\oracle\oradata\testHH\SYSTEM01.DBF  
SQL> ho del D:\oracle\oradata\testHH\SYSTEM01.DBF
    3.重启实例,收到错误提示     
  1. SQL> startup                                                    
  2. ORACLE 例程已经启动。                                           
  3.                                                                 
  4. Total System Global Area  126950220 bytes                       
  5. Fixed Size                   453452 bytes                       
  6. Variable Size             109051904 bytes                       
  7. Database Buffers           16777216 bytes                       
  8. Redo Buffers                 667648 bytes                       
  9. 数据库装载完毕。                                                
  10. ORA-01157: 无法标识/锁定数据文件 1 - 请参阅 DBWR 跟踪文件       
  11. ORA-01110: 数据文件 1: 'D:\ORACLE\ORADATA\TESTHH\SYSTEM01.DBF'  
SQL> startup ORACLE 例程已经启动。 Total System Global Area 126950220 bytes Fixed Size 453452 bytes Variable Size 109051904 bytes Database Buffers 16777216 bytes Redo Buffers 667648 bytes 数据库装载完毕。 ORA-01157: 无法标识/锁定数据文件 1 - 请参阅 DBWR 跟踪文件 ORA-01110: 数据文件 1: 'D:\ORACLE\ORADATA\TESTHH\SYSTEM01.DBF'
    4.使用RMAN进行还原与恢复       
  1. D:\>rman target /      -->连接到缺省的目标数据库                                             
  2.                                                                                             
  3. 恢复管理器: 版本9.2.0.8.0 - Production                                                      
  4. Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.                         
  5. 连接到目标数据库: TESTHH (DBID=3955637780)                                                  
  6.                                                                                             
  7. RMAN> restore database;   -->还原数据库                                                      
  8.                                                                                             
  9. 启动 restore 于 25-7月 -11                                                                  
  10. 正在使用目标数据库控制文件替代恢复目录                                                      
  11. 分配的通道: ORA_DISK_1                                                                      
  12. 通道 ORA_DISK_1: sid=14 devtype=DISK                                                        
  13. 通道 ORA_DISK_1: 正在开始恢复数据文件备份集                                                 
  14. 通道 ORA_DISK_1: 正在指定从备份集恢复的数据文件                                             
  15. 正将数据文件00002恢复到D:\ORACLE\ORADATA\TESTHH\UNDOTBS01.DBF                               
  16. 正将数据文件00003恢复到D:\ORACLE\ORADATA\TESTHH\CWMLITE01.DBF                               
  17. 正将数据文件00005恢复到D:\ORACLE\ORADATA\TESTHH\EXAMPLE01.DBF                               
  18. 正将数据文件00006恢复到D:\ORACLE\ORADATA\TESTHH\INDX01.DBF                                  
  19. 正将数据文件00010恢复到D:\ORACLE\ORADATA\TESTHH\XDB01.DBF                                   
  20. 通道 ORA_DISK_1: 已恢复备份段 1                                                             
  21. 段 handle=\\192.168.1.151\RMAN_SHARED\FULL_TESTHH_15MIBDKA_1_1 tag=FULL_BAK params=NULL     
  22. 通道 ORA_DISK_1: 恢复完成                                                                   
  23. 通道 ORA_DISK_1: 正在开始恢复数据文件备份集                                                 
  24. 通道 ORA_DISK_1: 正在指定从备份集恢复的数据文件                                             
  25. 正将数据文件00001恢复到D:\ORACLE\ORADATA\TESTHH\SYSTEM01.DBF                                
  26. 正将数据文件00004恢复到D:\ORACLE\ORADATA\TESTHH\DRSYS01.DBF                                 
  27. 正将数据文件00007恢复到D:\ORACLE\ORADATA\TESTHH\ODM01.DBF                                   
  28. 正将数据文件00008恢复到D:\ORACLE\ORADATA\TESTHH\TOOLS01.DBF                                 
  29. 正将数据文件00009恢复到D:\ORACLE\ORADATA\TESTHH\USERS01.DBF                                 
  30. 通道 ORA_DISK_1: 已恢复备份段 1                                                             
  31. 段 handle=\\192.168.1.151\RMAN_SHARED\FULL_TESTHH_16MIBDMB_1_1 tag=FULL_BAK params=NULL     
  32. 通道 ORA_DISK_1: 恢复完成                                                                   
  33. 完成 restore 于 25-7月 -11                                                                  
  34.                                                                                             
  35. RMAN> recover database;    -->恢复数据库                                                     
  36.                                                                                             
  37. 启动 recover 于 25-7月 -11                                                                  
  38. 使用通道 ORA_DISK_1                                                                         
  39. 正在开始介质的恢复                                                                          
  40. 完成介质的恢复                                                                              
  41. 完成 recover 于 25-7月 -11                                                                  
  42.                                                                                             
  43. SQL> alter database open;                                                                   
  44.                                                                                             
  45. SQL> select name,open_mode from v$database;                                                 
  46.                                                                                             
  47. NAME      OPEN_MODE                                                                         
  48. --------- ----------                                                                         
  49. TESTHH    READ WRITE                                                                        
D:\>rman target / -->连接到缺省的目标数据库 恢复管理器: 版本9.2.0.8.0 - Production Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved. 连接到目标数据库: TESTHH (DBID=3955637780) RMAN> restore database; -->还原数据库 启动 restore 于 25-7月 -11 正在使用目标数据库控制文件替代恢复目录 分配的通道: ORA_DISK_1 通道 ORA_DISK_1: sid=14 devtype=DISK 通道 ORA_DISK_1: 正在开始恢复数据文件备份集 通道 ORA_DISK_1: 正在指定从备份集恢复的数据文件 正将数据文件00002恢复到D:\ORACLE\ORADATA\TESTHH\UNDOTBS01.DBF 正将数据文件00003恢复到D:\ORACLE\ORADATA\TESTHH\CWMLITE01.DBF 正将数据文件00005恢复到D:\ORACLE\ORADATA\TESTHH\EXAMPLE01.DBF 正将数据文件00006恢复到D:\ORACLE\ORADATA\TESTHH\INDX01.DBF 正将数据文件00010恢复到D:\ORACLE\ORADATA\TESTHH\XDB01.DBF 通道 ORA_DISK_1: 已恢复备份段 1 段 handle=\\192.168.1.151\RMAN_SHARED\FULL_TESTHH_15MIBDKA_1_1 tag=FULL_BAK params=NULL 通道 ORA_DISK_1: 恢复完成 通道 ORA_DISK_1: 正在开始恢复数据文件备份集 通道 ORA_DISK_1: 正在指定从备份集恢复的数据文件 正将数据文件00001恢复到D:\ORACLE\ORADATA\TESTHH\SYSTEM01.DBF 正将数据文件00004恢复到D:\ORACLE\ORADATA\TESTHH\DRSYS01.DBF 正将数据文件00007恢复到D:\ORACLE\ORADATA\TESTHH\ODM01.DBF 正将数据文件00008恢复到D:\ORACLE\ORADATA\TESTHH\TOOLS01.DBF 正将数据文件00009恢复到D:\ORACLE\ORADATA\TESTHH\USERS01.DBF 通道 ORA_DISK_1: 已恢复备份段 1 段 handle=\\192.168.1.151\RMAN_SHARED\FULL_TESTHH_16MIBDMB_1_1 tag=FULL_BAK params=NULL 通道 ORA_DISK_1: 恢复完成 完成 restore 于 25-7月 -11 RMAN> recover database; -->恢复数据库 启动 recover 于 25-7月 -11 使用通道 ORA_DISK_1 正在开始介质的恢复 完成介质的恢复 完成 recover 于 25-7月 -11 SQL> alter database open; SQL> select name,open_mode from v$database; NAME OPEN_MODE --------- ---------- TESTHH READ WRITE
    5.结论
            从上面的备份与恢复来看,使用异机备份与恢复与使用本地服务器备份与恢复操作方式并无太多差异,但数据库的性能则受到一定
        的影响。即备份到异机其备份与恢复速度低于备份恢复在本地服务器。在大型生产环境中且实时性要求特高的情形,尽可能的避免异机
        备份与恢复。尽管如此,备份到异机与从异机恢复仍然不失为一种可选方案。

五、RMAN 备份脚本   
  1. run{                                                                                                                      
  2. allocate channel ch1 device type disk;                                                                                    
  3. allocate channel ch2 device type disk;                                                                                    
  4. backup database format='\\192.168.1.151\RMAN_Shared\full_%d_%U'  -->注意格式的写法\\IP\Shared_folder\                      
  5. tag='full_bak';                                                                                                           
  6. sql "alter system archive log current";                                                                                   
  7. crosscheck archivelog all;                                                                                                
  8. delete noprompt expired archivelog all;                                                                                   
  9. backup archivelog all format='\\192.168.1.151\RMAN_Shared\log_%d_%U' delete input  -->注意格式的写法\\IP\Shared_folder\    
  10. tag='log_bak';                                                                                                            
  11. release channel ch1;                                                                                                      
  12. release channel ch2;}  

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

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

注册时间:2010-05-18

  • 博文量
    192
  • 访问量
    455758