BACKUP的基本觀念
- OPEN Backup: (備份時資料庫是開啟的): 資料庫必須是 ARCHIVE MODE
- CLOSE Backup: (備份時資料庫是關閉的): 資料庫是 NONARCHIVE MODE
- Offline Backup: (備份時資料庫是關閉的): 資料庫是 NONARCHIVE MODE
- Partial Backup: (備份部分檔案): 資料庫必須是 ARCHIVE MODE
- Datafiles
- Controlfile
- Archive redo log files
- SPFILE
- Backup set pieces
- Tempfiles
- Online redo log files
- Password file
- Static PFILE
- Oracle Net Configuration files
RMAN有三種備份型態
- Backup Set: 可採用漸進式備份
- Compressed Backup Set: 同上,但經過壓縮
- Image Copy: 較占空間,不可採用漸進式備份,也不可備份SPFILE檔案。但是在還原時速度較快
BACKUP SETS 是最小的備份單位,比原始檔或是IMAGE COPIES(另一種備份格式) 都來得小。
開始漸進式備份,首先須建立備份基線
backup as backupset incremental level 0 database;
接下來有兩種漸進式備份方式
Differential 備份
backup as backupset incremental level 1 database;
RMAN> backup as backupset incremental level 1 database; Starting backup at 2017-08-21 13:19:13 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=42 device type=DISK channel ORA_DISK_1: starting incremental level 1 datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00001 name=/oracle/app/oracle/oradata/sedb/system01.dbf input datafile file number=00003 name=/oracle/app/oracle/oradata/sedb/undotbs01.dbf input datafile file number=00002 name=/oracle/app/oracle/oradata/sedb/sysaux01.dbf input datafile file number=00006 name=/oracle/app/oracle/oradata/sedb/TBS_PRETORIA_01.dbf input datafile file number=00007 name=/oracle/app/oracle/oradata/sedb/TBS_NOVATEKTEST_01.dbf input datafile file number=00008 name=/oracle/app/oracle/oradata/sedb/TBS_REPAIR_01.dbf input datafile file number=00010 name=/oracle/app/oracle/oradata/sedb/STORETABS_01.dbf input datafile file number=00011 name=/oracle/app/oracle/oradata/sedb/STORETABS_02.dbf input datafile file number=00005 name=/oracle/app/oracle/oradata/sedb/TBS_PROCHUB_01.dbf input datafile file number=00009 name=/oracle/app/oracle/oradata/sedb/TBS_PRE_IND_01.dbf input datafile file number=00013 name=/oracle/app/oracle/oradata/sedb/vpd_admin.dbf input datafile file number=00012 name=/oracle/app/oracle/oradata/sedb/TBS_NEWTBS_01.dbf input datafile file number=00004 name=/oracle/app/oracle/oradata/sedb/users01.dbf channel ORA_DISK_1: starting piece 1 at 2017-08-21 13:19:14 channel ORA_DISK_1: finished piece 1 at 2017-08-21 13:21:00 piece handle=/oracle/app/oracle/flash_recovery_area/PRISEDB/backupset/2017_08_21/o1_mf_nnnd1_TAG20170821T131914_dspj23nb_.bkp tag=TAG20170821T131914 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:01:46 Finished backup at 2017-08-21 13:21:00 Starting Control File and SPFILE Autobackup at 2017-08-21 13:21:00 piece handle=/oracle/app/oracle/flash_recovery_area/PRISEDB/autobackup/2017_08_21/o1_mf_s_952608060_dspj5gc3_.bkp comment=NONE Finished Control File and SPFILE Autobackup at 2017-08-21 13:21:03
Cumulative 備份
backup as backupset incremental level 1 cumulative database;
RMAN> backup as backupset incremental level 1 cumulative database; Starting backup at 2017-08-21 13:21:51 using channel ORA_DISK_1 channel ORA_DISK_1: starting incremental level 1 datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00001 name=/oracle/app/oracle/oradata/sedb/system01.dbf input datafile file number=00003 name=/oracle/app/oracle/oradata/sedb/undotbs01.dbf input datafile file number=00002 name=/oracle/app/oracle/oradata/sedb/sysaux01.dbf input datafile file number=00006 name=/oracle/app/oracle/oradata/sedb/TBS_PRETORIA_01.dbf input datafile file number=00007 name=/oracle/app/oracle/oradata/sedb/TBS_NOVATEKTEST_01.dbf input datafile file number=00008 name=/oracle/app/oracle/oradata/sedb/TBS_REPAIR_01.dbf input datafile file number=00010 name=/oracle/app/oracle/oradata/sedb/STORETABS_01.dbf input datafile file number=00011 name=/oracle/app/oracle/oradata/sedb/STORETABS_02.dbf input datafile file number=00005 name=/oracle/app/oracle/oradata/sedb/TBS_PROCHUB_01.dbf input datafile file number=00009 name=/oracle/app/oracle/oradata/sedb/TBS_PRE_IND_01.dbf input datafile file number=00013 name=/oracle/app/oracle/oradata/sedb/vpd_admin.dbf input datafile file number=00012 name=/oracle/app/oracle/oradata/sedb/TBS_NEWTBS_01.dbf input datafile file number=00004 name=/oracle/app/oracle/oradata/sedb/users01.dbf channel ORA_DISK_1: starting piece 1 at 2017-08-21 13:21:52 channel ORA_DISK_1: finished piece 1 at 2017-08-21 13:23:47 piece handle=/oracle/app/oracle/flash_recovery_area/PRISEDB/backupset/2017_08_21/o1_mf_nnnd1_TAG20170821T132151_dspj70kr_.bkp tag=TAG20170821T132151 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:01:55 Finished backup at 2017-08-21 13:23:47 Starting Control File and SPFILE Autobackup at 2017-08-21 13:23:47 piece handle=/oracle/app/oracle/flash_recovery_area/PRISEDB/autobackup/2017_08_21/o1_mf_s_952608228_dspjbntn_.bkp comment=NONE Finished Control File and SPFILE Autobackup at 2017-08-21 13:23:51不管哪種方式都會產生兩個BACKUPSET,第一個是所有的DATAFILES,第二個是CONTROL FILE 及 SPFILE
當進行第二次的漸進式備份時,出現下列錯誤
channel ORA_DISK_1: starting piece 1 at 2017-08-21 16:27:41 RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03009: failure of backup command on ORA_DISK_1 channel at 08/21/2017 16:32:07 ORA-19809: limit exceeded for recovery files ORA-19804: cannot reclaim 52428800 bytes disk space from 5218762752 limit透過TOAD發現 FLASH_RECOVERY_FILE_DEST_SIZE 的大小太小了
其大小原為
修正後為
alter system set db_recovery_file_dest_size=5G;
修正完畢後可以存放兩組漸進式的備份
Backupset 備份
backup as compressed backupset filesperset 4 database; -- 將BACKUPSET 分為四個檔案儲存 backup as compressed backupset archivelog all delete all input; -- 將ARCHIVELOG 壓縮儲存 backup as backupset format '/backup/orcl/df_%d_%s_%p' tablespace g1_tabs; -- 備份表格空間 gl_tabs backup as compressed backupset datafile 4; -- 以編號命名 Datafile ,並壓縮後儲存 backup as backupset archivelog like '/u01/archivel/arch_1%'; -- 搜尋目錄內符合PATTERN的ARCHIVE LOG,並加以備份漸進式備份雖然可產生較小的備份檔案,但是備份較花時間,原因是它必須花時間掃描全部的DATAFILE。
BLOCK CHANGE TRACKING 技術,在背景執行一支程序,稱為 Change Tracking Writing (CTW), 它將每個BLOCK更動的紀錄,紀載在一個稱之為 change tracking file 的 DBF 檔案上
以下命令開啟 CTW 程序,並將BLOCK變動紀錄紀載到所指定到的DBF檔案
以下參考文章 或是 OCA OCP Oracle Database 11g All-in-One Exam Guide Chapter 15
alter database enable block change tracking using file '/oracle/app/oracle/oradata/sedb/change_tracking.dbf';
CTW 狀態和紀錄檔可由 V$BLOCK_CHANGE_TRACKING 來檢視
select * from v$block_change_tracking;
下列SQL查詢是否 CTW 已經啟動
select program from v$process where program like '%CTWR%';
啟動 CTW 程序以後,漸進式備份所需的時間降低了。 BLOCKS_READ 與 DATAFILE_BLOCKS 的比例由 1 降到 1 以下
以下SQL可以驗證,開啟CTW以後,資料庫SCAN讀取DATAFILE的比例降低到 1 以下
select file#, datafile_blocks, (blocks_read / datafile_blocks) * 100 as pct_read_for_backup from v$backup_datafile where used_change_tracking='YES' and incremental_level > 0關閉 CTW 則透過以下指令
SQL> alter database disable block change tracking;
建立保留長期的備份 ARCHIVAL BACKUPS
長期備份,例如,建立一個保留90天的備份檔,該備份不受 DELETE OBSOLETE,也不受 RETENTION POLICY 的影響
語法如下:
backup database as compressed backup set keep until time 'sysdate + 90' restore point quarterly_backup;
RMAN 備份的管理
可以運用LIST及REPORT,配合DELETE指令處理
list backup; list copy; list backup of database; list backup of datafile 1; list backup of tablespace users; list backup of archivelog all; list copy of archivelog from time='sysdate - 7'; list backup of archivelog from sequence 1000 until sequence 1050; list backup of spfile; list backup of controlfile; report schema report need backup; report need backup days 3; report need backup redundancy 3; report obsolete; delete obsolete; report obsolete redundancy 2; delete obsolete redundancy 2; delete backupset 4; delete copy of datafile 6 file6_extra;
RMAN 相關的 DYNAMIC VIEW
下列的 DYNAMIC VIEW 提供比LIST/REPORT命令更多的資訊,來管理備份
select * from v$backup_files ; select * from v$backup_set ; select * from v$backup_piece ; select * from v$backup_redolog ; select * from v$backup_spfile ; select * from v$backup_datafile ; select * from v$backup_device ; select * from v$rman_configuration ;備份的空間使用狀況可由 V$FLASH_RECOVERY_AREA_USAGE 來顯示,例如
select * from v$flash_recovery_area_usage;