1.備份資料庫
RMAN> show all;
RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/u01/app/oracle/rmanbak/df_%d_%U';
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/10g/dbs/snapcf_orcl.f'; # defaul
RMAN> backup database format '/u01/app/oracle/rmanbak/whole_%d_%U'; --備份整個資料庫
RMAN> backup as compressed backupset --備份整個資料庫并壓縮備份集
2> database format '/u01/app/oracle/rmanbak/whole_%d_%U';
RMAN> run{
2> allocate channel ch1 type disk --手動配置設定一個通道
3> maxpiecesize=2g; --指定備份片的大小為g
4> backup as compressed backupset --壓縮備份集
5> format '/u01/app/oracle/rmanbak/whole_%d_%U' filesperset=3--指定備份集中允許容納的檔案數為個
6> database;
7> release channel ch1;} --釋放通道
RMAN> configure device type disk parallelism 3; --将并行度改為
old RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 3 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters are successfully stored
RMAN> backup as compressed backupset --并行度改為之後,自動啟用了個通道
2> format '/u01/app/oracle/rmanbak/whole_%d_%U' filesperset=3
3> database;
Starting backup at 14-OCT-10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=148 devtype=DISK --sid值對應v$session視圖中的sid
allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=146 devtype=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: sid=144 devtype=DISK
2> allocate channel ch1 type disk
3> maxpiecesize=100m; --備份片大小設定為m,則一個備份集包含多個備份片,且每個備份片大小為m
4> backup
5> format '/u01/app/oracle/rmanbak/whole_%d_%U'
6> database;
7> release channel ch1;}
RMAN> list backupset tag=TAG20101014T171115;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
21 Full 690.30M DISK 00:01:39 14-OCT-10
List of Datafiles in backup set 21
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ---------- ----
1 Full 1648791 14-OCT-10 /u01/app/oracle/oradata/orcl/system01.dbf
2 Full 1648791 14-OCT-10 /u01/app/oracle/oradata/orcl/undotbs01.dbf
3 Full 1648791 14-OCT-10 /u01/app/oracle/oradata/orcl/sysaux01.dbf
4 Full 1648791 14-OCT-10 /u01/app/oracle/oradata/orcl/users01.dbf
5 Full 1648791 14-OCT-10 /u01/app/oracle/oradata/orcl/example01.dbf
6 Full 1648791 14-OCT-10 /u01/app/oracle/oradata/orcl/tbs1.dbf
Backup Set Copy #1 of backup set 21
Device Type Elapsed Time Completion Time Compressed Tag
----------- ------------ --------------- ---------- ---
DISK 00:01:39 14-OCT-10 NO TAG20101014T171115
List of Backup Pieces for backup set 21 Copy #1
BP Key Pc# Status Piece Name
------- --- ----------- ----------
21 1 AVAILABLE /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_1_1
22 2 AVAILABLE /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_2_1
23 3 AVAILABLE /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_3_1
24 4 AVAILABLE /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_4_1
25 5 AVAILABLE /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_5_1
26 6 AVAILABLE /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_6_1
27 7 AVAILABLE /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_7_1
22 Full 6.80M DISK 00:00:01 14-OCT-10
BP Key: 28 Status: AVAILABLE Compressed: NO Tag: TAG20101014T171115
Piece Name: /u01/app/oracle/rmanbak/whole_ORCL_0olqen0s_1_1
Control File Included: Ckp SCN: 1648817 Ckp time: 14-OCT-10
SPFILE Included: Modification time: 14-OCT-10
-----------------------------------------------------------------------------------------------------------------------
2.備份資料檔案
Oracle資料檔案及表空間的管理請參考:Oracle 表空間與資料檔案
RMAN> backup as copy datafile 4 --備份類型為鏡像備份
2> format '/u01/app/oracle/rmanbak/df_%d_%U';
RMAN> list copy;
RMAN> backup datafile 4,5,6 format '/u01/app/oracle/rmanbak/df_%d_%U'; --備份類型為備份集
3.備份表空間
RMAN> backup tablespace users,example format '/u01/app/oracle/rmanbak/tb_%d_%U';
RMAN> backup tablespace temp; --臨時表空間不需要備份
using channel ORA_DISK_1
using channel ORA_DISK_2
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-03002: failure of backup command at 10/14/2010 18:56:12
RMAN-20202: tablespace not found in the recovery catalog
RMAN-06019: could not translate tablespace name "TEMP"
4.備份控制檔案
Oracle 控制檔案的詳細介紹請參考:Oracle 控制檔案(CONTROLFILE)
RMAN> configure controlfile autobackup on;--自動備份控制檔案置為on狀态,将自動備份控制檔案和參數檔案
CONFIGURE CONTROLFILE AUTOBACKUP OFF;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
注:在備份system01.dbf或system表空間時将會自動備份控制檔案和參數檔案,即使自動備份控制檔案參數為off
--單獨備份控制檔案及參數檔案
RMAN> backup current controlfile;
--備份資料檔案時包含控制檔案
RMAN> backup datafile 4 include current controlfile;
RMAN> sql "alter database backup controlfile to ''/tmp/orclcontrol.bak''";
sql statement: alter database backup controlfile to ''/tmp/orclcontrol.bak''
RMAN> sql "alter database backup controlfile to trace as ''/tmp/orclcontrol.sql''";
sql statement: alter database backup controlfile to trace as ''/tmp/orclcontrol.sql''
--單獨備份spfile
RMAN> backup spfile format '/u01/app/oracle/rmanbak/sp_%d_%U';
RMAN> backup copies 2 device type disk spfile;
5.備份歸檔日志檔案
備份歸檔日志時僅僅備份歸檔過的資料檔案(不備份聯機重做日志檔案)
備份歸檔日志時總是對歸檔日志做完整備份
RMAN對歸檔日志備份前會自動做一次日志切換,且從一組歸檔日志中備份未損壞的歸檔日志
RMAN會自動判斷哪些歸檔日志需要進行備份
歸檔日志的備份集不能包含其它類型的檔案
關于Oracle日志檔案請參考:Oracle 聯機重做日志檔案(ONLINE LOG FILE)
關于Oracle歸檔日志請參考:Oracle 歸檔日志
RMAN> backup
2> format '/u01/app/oracle/rmanbak/lf_%d_%U'
3> archivelog all delete input; --delete input 删除所有已經備份過的歸檔日志
RMAN> backup --此種寫法實作了上述相同的功能
2> archivelog all delete input
3> format '/u01/app/oracle/rmanbak/lf_%d_%U';
RMAN> backup archivelog sequence between 50 and 120 thread 1 delete input;
RMAN> backup archivelog from time "sysdate-15" until time "sysdate-7";
RMAN> backup
3> archivelog from sequence=80
4> delete input;
使用plus archivelog時備份資料庫完成的動作(backup database plus archivelog)
1.首先執行alter system archive log current 指令(對目前日志歸檔)
2.執行backup archivelog all 指令(對所有歸檔日志進行備份)
3.執行backup database指令中指定的資料檔案、表空間等
4.再次執行alter system archive log current
5.備份在備份操作期間産生的新的歸檔日志
--執行下面的指令,并觀察備份列出的資訊,可以看到使用plus archivelog時使用了上面描述的步驟來進行備份
RMAN> backup database plus archivelog
2> format '/u01/app/oracle/rmanbak/lg_%d_%U' delete input;
6.備份閃回區
RMAN> backup recovery area;
使用backup recovery area時,将備份位于閃回區且未進行過備份的所有檔案,這些檔案包括完整、增量備份集、自動備份的
控制檔案(假定使用閃回區作為備份路徑時)、歸檔日志、資料檔案的鏡像副本等。閃回日志,目前的控制檔案。
聯機重做日志不會被備份
RMAN> backup recovery files;
使用backup recovery files時,将備份磁盤上未進行過備份的所有恢複檔案,而不論是否位于閃回區
注:使用上述兩條指令時,備份目的地必須是錄音帶
7.總結:
資料檔案的備份集對于未使用的塊可以執行增量備份,可以跳過未使用過的資料塊來進行壓縮備份
對于控制檔案、歸檔日志檔案、spfile檔案則是簡單的拷貝,并對其進行打包壓縮而已