[Rman]Oracle Rman增量備份Level012指令碼

梓沐發表於2016-02-15
Rman Level012備份實驗http://blog.itpub.net/29812844/viewspace-1988837/
採用0221222增量備份策略,7天一個輪迴
也就是週日0級備份,周1 2 4 5 6 採用2級增量備份,周3採用1級增量備份
開啟控制檔案自動備份
  1. CONFIGURE CONTROLFILE AUTOBACKUP ON
11g控制檔案自動備份新特性:http://blog.csdn.net/u011364306/article/details/50051303
配置控制檔案備份路徑
  1. RMAN > CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/file/backup/rman/controlfile_%F'
將過期天數設為7天
  1. RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS
建立資料備份目錄
  1. mkdir -p /file/backup/rman/
指令碼解釋:
  1. vim rman_bak_level0.sh
  2. #! /bin/bash
  3. export ORACLE_BASE=/u01/oracle
  4. export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
  5. export PATH=$ORACLE_HOME/bin:$PATH
  6. export ORACLE_SID=neal --資料庫ORACLE_SID
  7. export NLS_LANG='AMERICAN_AMERICA.ZHS16GBK' --字符集
  8. rman target / <<EOF
  9. run{
  10. allocate channel d1 type disk; --分配通道d1,型別備份到磁碟
  11. allocate channel d2 type disk; --分配通道d2,型別備份到磁碟
  12. backup incremental level 0 database format '/file/backup/rman/level0_%d_%s_%p_%u.bkp'; --備份級別、輸出格式、路徑
  13. sql 'alter system archive log current'; --對當前redo日誌進行歸檔
  14. backup archivelog all delete input format '/file/backup/rman/archivelog_%d_%s_%p_%u.bkp'; --備份歸檔日誌並刪除
  15. crosscheck backup; --檢查備份
  16. delete noprompt obsolete; --靜默刪除過期備份
  17. release channel d1; --釋放通道d1
  18. release channel d2; --釋放通道d2
  19. }
  20. EOF
下面開始建立0級 1級 2級備份指令碼
0級備份指令碼
  1. vim rman_bak_level0.sh
  2. #! /bin/bash
  3. export ORACLE_BASE=/u01/oracle
  4. export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
  5. export PATH=$ORACLE_HOME/bin:$PATH
  6. export ORACLE_SID=neal
  7. export NLS_LANG='AMERICAN_AMERICA.ZHS16GBK'
  8. rman target / <<EOF
  9. run{
  10. allocate channel d1 type disk;
  11. allocate channel d2 type disk;
  12. backup incremental level 0 database format '/file/backup/rman/level0_%d_%s_%p_%u.bkp';
  13. sql 'alter system archive log current';
  14. backup archivelog all delete input format '/file/backup/rman/archivelog_%d_%s_%p_%u.bkp';
  15. crosscheck backup;
  16. delete noprompt obsolete;
  17. release channel d1;
  18. release channel d2;
  19. }
  20. EOF
1級備份指令碼
  1. vim rman_bak_level1.sh
  2. #! /bin/bash
  3. export ORACLE_BASE=/u01/oracle
  4. export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
  5. export PATH=$ORACLE_HOME/bin:$PATH
  6. export ORACLE_SID=neal
  7. export NLS_LANG='AMERICAN_AMERICA.ZHS16GBK'
  8. rman target / <<EOF
  9. run{
  10. allocate channel d1 type disk;
  11. allocate channel d2 type disk;
  12. backup incremental level 1 database format '/file/backup/rman/level1_%d_%s_%p_%u.bkp';
  13. sql 'alter system archive log current';
  14. backup archivelog all delete input format '/file/backup/rman/archivelog_%d_%s_%p_%u.bkp';
  15. crosscheck backup;
  16. delete noprompt obsolete;
  17. release channel d1;
  18. release channel d2;
  19. }
  20. EOF
2級備份指令碼
  1. vim rman_bak_level2.sh
  2. #! /bin/bash
  3. export ORACLE_SID=neal
  4. export NLS_LANG='AMERICAN_AMERICA.ZHS16GBK'
  5. /u01/oracle/product/11.2.0/db_1/bin/rman target / <<EOF
  6. run{
  7. allocate channel d1 type disk;
  8. allocate channel d2 type disk;
  9. backup incremental level 2 database format '/file/backup/rman/level2_%d_%s_%p_%u.bkp';
  10. sql 'alter system archive log current';
  11. backup archivelog all delete input format '/file/backup/rman/archivelog_%d_%s_%p_%u.bkp';
  12. crosscheck backup;
  13. delete noprompt obsolete;
  14. release channel d1;
  15. release channel d2;
  16. }
  17. EOF
加入到crontab中
  1. crontab -e

  2. #週日0級備份
  3. 00 23 * * 0 /server/scripts/rman_bak_level0.sh
  4. #週一、二、四、五、六2級增量備份
  5. 00 23 * * 1,2,4,5,6 /server/scripts/rman_bak_level2.sh
  6. #週三1級增量備份
  7. 00 23 * * 3 /server/scripts/rman_bak_level1.sh
Rman備份中變數的含義

backup incremental level 0 database format='LEV0_%d_%t_%U_%s_%p'
format=string 檔案路徑和名稱的格式串,其中可包含宏變數:
%c copy ID
%p backup piece ID
%s backup set ID
%e log sequence
%h log thread ID
%d database name
%n database name(x填充到8個字元)
%I DBID
%f file ID
%F DBID, day, month, year, and sequencer的複合
%N tablespace name
%t timestamp
%M mh mm格式
%Y year yyyy格式
%u backup set+time((x填充到8個字元)
%U %u_%p_%c
%% %
The format specifier %U is replaced with unique filenames for the files when you take backups.
the %F element of the format string combines the DBID, day, month, year, and sequence number to generate a unique filename. %F must be included in any control file autobackup format.

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

相關文章