使用RMAN實現異機備份恢復(WIN平臺)

us_yunleiwang發表於2013-12-05
--=================================
-- 使用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;    --&gt控制檔案自動備份,建議開啟                                              
  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';                                   --&gt控制檔案備份位置                                                        
  11.                                                                                                                    
  12. RMAN> show SNAPSHOT CONTROLFILE NAME;                                                                              
  13.                                                                                                                    
  14. RMAN 配置引數為:                                                                                                   
  15. CONFIGURE SNAPSHOT CONTROLFILE NAME TO 'D:\ORACLE\ORA92\DATABASE\SNCFTESTHH.ORA'; # default   --&gt快照控制檔案位置  
  16.                                                                                                                    
  17. SQL> select * from v$version;    --&gt資料庫的版本,當前演示環境為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                                                            
三、備份資料庫並關閉資料庫,刪除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                                                                                  
四、從異機進行還原與恢復
    1.關閉資料庫        
  1. SQL> shutdown immediate;    
  2. 資料庫已經關閉。            
  3. 已經解除安裝資料庫。            
  4. ORACLE 例程已經關閉。       
    2.刪除system01.dbf資料檔案以便測試恢復        
  1. 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'  
    4.使用RMAN進行還原與恢復        
  1. D:\>rman target /      --&gt連線到預設的目標資料庫                                            
  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;   --&gt還原資料庫                                                     
  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;    --&gt恢復資料庫                                                    
  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                                                                        
    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'  --&gt注意格式的寫法\\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  --&gt注意格式的寫法\\IP\Shared_folder\   
  10. tag='log_bak';                                                                                                            
  11. release channel ch1;                                                                                                      
  12. release channel ch2;}                                                                 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23490154/viewspace-1062408/,如需轉載,請註明出處,否則將追究法律責任。

相關文章