1 / 36

Backup and Recovery ( 備份與回復 )

Backup and Recovery ( 備份與回復 ). Oracle 系統架構. Background Knowledge. Redo log 顧慮到執行效率 , 並不是所有資料變更馬上寫到磁碟中 Redo log 會紀錄哪些東西 購成交易的紀錄 System change number (SCN) 變更時間 Archived redo log 讓交易可以倒轉到之前任何時候 因為 online redo log 是循環式 , 會覆寫 , archived redo log 覆寫前會記錄下來 有 archived redo log 可以復原 , 反之只能重置.

gamada
Download Presentation

Backup and Recovery ( 備份與回復 )

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Backup and Recovery(備份與回復)

  2. Oracle 系統架構

  3. Background Knowledge • Redo log • 顧慮到執行效率,並不是所有資料變更馬上寫到磁碟中 • Redo log會紀錄哪些東西 • 購成交易的紀錄 • System change number (SCN) • 變更時間 • Archived redo log讓交易可以倒轉到之前任何時候 • 因為online redo log是循環式,會覆寫, archived redo log覆寫前會記錄下來 • 有archived redo log可以復原,反之只能重置

  4. 應該要備份哪些檔案? • Datafiles • Tablespaces • Control file • 封存日誌的歷史紀錄,目前的redo log, check point • 有文字版跟binary版本 • Server parameter file (SPFILE) • Init.ora • If in Archivelog mode • Archived redo log files • On-line redo log (不建議) • Alter log • Oracle password file

  5. Oracle備份機制 • Recovery Manager (RMAN) • Online (hot) backup (熱備份) • 熱備份時資料庫可以運作 • 必須在Archivelog mode • 可回復至系統最新狀況 • Offline (cold) backup (冷備份) • 冷備份時資料庫停止運作 • Noarchivelog mode • 可回復至停止運作時的狀況

  6. Online Backup (熱備份) • 除了回復database files之外,還會利用redo log回覆已經committed的交易,以及取消uncommitted的交易 • 因為要利用archived redo log回復交易,因此要將oracle設定成archivelog mode

  7. 如何設定Archivedlog mode

  8. 利用SQL Command Line登入 • Sqlplus /nolog • Conn id/pwd@ip as sysdba • Shutdown immediate

  9. STARTUP MOUNT • Alter Database archivelog

  10. Alter database open • 建議更改Flash Recovery Area超過15G • Alter system set db_recovery_file_dest_size = 15g

  11. 備份表格空間 • Alter tablespace <tablespace_name> begin backup; • Alter tablespace <tablespace_name> end backup; • 可利用archive log current來封存所有redo log

  12. 備份方式

  13. Offline Backup (冷備份) • 冷備份需停止資料庫以方便備份

  14. 警告:冷備份只能回復至備份點

  15. 錯誤訊息 • 告知錯誤訊息放置地點 • C:\oraclexe\app\oracle\product\10.2.0\server\database\oxe_backup_current.log

  16. 備份成功 • 可以至Flash Recovery Area的目錄下,找到Autobackup目錄,裡面即有備份檔案

  17. 定期備份 • 使用任何定期執行程式,執行下列備份程式 • C:\oraclexe\app\oracle\product\10.2.0\server\BIN\backup.bat

  18. 備份控制檔案 • Alter database backup controlfile to trace • 備份文字控制檔案 • Alter database backup controlfile to ‘/directory/file’ • 備份binary控制檔案

  19. 回復資料庫 (冷/熱備份) • 換硬體 • 重灌OS • 重灌XE • 將未受損的檔案複製回原位 • 包含datafile • C:\oraclexe\oradata\XE • Starup nomount • Control file and SPFILE, init.ora • Startup mount • Redo log (要注意) • C:\oraclexe\app\oracle\flash_recovery_area\XE • startup open

  20. 熱備份不完整復原 • Recover database until cancel; • Recover database until change 1234567; • Recover database until time ‘2004-04-15:14:33:00’;

  21. 更改Flash Recovery File位置 • Alter system set db_recovery_file_dest = ‘e:\FRA’ • 利用命令將log file搬移到新地點 • @?/sqlplus/admin/movelogs • @:開始命令 • ?:資料庫目錄

  22. 資源回收筒

  23. 可回復物件類型

  24. 回復物件

  25. Starting Up The Database(啟動資料庫) • Login to host as a ORA_DBA group • Open a terminal session or command window • SQLPLUS / AS SYSDBA • STARTUP

  26. Startup Advance • Startup基本上經歷三個階段 • Nomount phase • 讀取spfile, init.ora,參數檔案 • 這個階段可以重建控制檔案 • Startup nomount • Mount phase • 把資料庫掛上oracle • 利用參數檔案找出redo log,但未啟動 • 使用者還不能存取資料 • Startup mount • Alter database mount • Open phase • 啟動redo log跟資料檔 • Resetlogs參數用來設定新的redo log所在位置 • Startup {open} {resetlogs} • Alter database open

  27. 開啟唯讀模式(方便升級) • Alter database open read only • 開啟限制模式(進行日常維護) • 只有create session, restricted session權限的人可以使用資料庫 • Startup restrict • 強制啟動 • Startup force

  28. 為什麼備份會失敗 • RMAN備份失敗的錯誤訊息 • Ora-01801: The date format is to long • 原因是寫入rman的日期型態不對 • 中文跟英文型態的日期寫法不同 • 可觀察control file內的設定為AL32UTF8 • Oracle預設的備份包含下列步驟 • Dismount 資料庫檔案 • 讀取NLS_LANG環境變數 • NLS_LANG會影響NLS_Language與NLS_Territary兩個變數 • 預設的環境變數為繁體中文,與control file內設定不同 • 介面的語系設定可以與實際資料庫設定不同,但是對於RMAN備份時,會因為所需求格式不同,錯誤的原因在此發生 • 解決方式 • 開始regeditHKEY_LOCAL_MACHINESOFTWAREORACLE\KEY_XE • 把NLS_LANG屬性的值改成American DATAFILE 'C:\ORACLEXE\ORADATA\XE\SYSTEM.DBF', 'C:\ORACLEXE\ORADATA\XE\UNDO.DBF', 'C:\ORACLEXE\ORADATA\XE\SYSAUX.DBF', 'C:\ORACLEXE\ORADATA\XE\USERS.DBF' CHARACTER SET AL32UTF8 ; AL32UTF8是American的編碼

  29. 備份失敗的處理方式 • 冷備份失敗由於已經把database close,所以必須重新開啟database • 用sqlplus介面登入 • Connect / as sysdba • Alter database open;

  30. Dual 表格 • 永遠只有一筆資料的預設表格 • Select to_date(sysdate,”YYYYMMDD HH.Mi.SS”) • Mi是為了用來區分MM

  31. 找出目前的NLS_Language設定 • select name,value from v$parameter where name='nls_language‘ • Alter system set NLS_Language=‘TRADITIONAL CHINESE_TAIWAN.ZHT16MSWIN950’

  32. Dump control file • alter database backup controlfile to trace as ‘c:\1.txt'

More Related