[Rman]Oracle Rman增量備份Level012指令碼
採用0221222增量備份策略,7天一個輪迴
也就是週日0級備份,周1 2 4 5 6 採用2級增量備份,周3採用1級增量備份
開啟控制檔案自動備份
CONFIGURE CONTROLFILE AUTOBACKUP ON;
配置控制檔案備份路徑
RMAN > CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/file/backup/rman/controlfile_%F';
將過期天數設為7天RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
資料備份目錄
$ mkdir -p /file/backup/rman/
指令碼解釋:
vim rman_bak_level0.sh #! /bin/bash export ORACLE_BASE=/u01/oracle export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 export PATH=$ORACLE_HOME/bin:$PATH export ORACLE_SID=neal --資料庫ORACLE_SID export NLS_LANG='AMERICAN_AMERICA.ZHS16GBK' --字符集 rman target / <<EOF run{ allocate channel d1 type disk; --分配通道d1,型別備份到磁碟 allocate channel d2 type disk; --分配通道d2,型別備份到磁碟 backup incremental level 0 database format '/file/backup/rman/level0_%d_%s_%p_%u.bkp'; --備份級別、輸出格式、路徑 sql 'alter system archive log current'; --對當前redo日誌進行歸檔 backup archivelog all delete input format '/file/backup/rman/archivelog_%d_%s_%p_%u.bkp'; --備份歸檔日誌並刪除 crosscheck backup; --檢查備份 delete noprompt obsolete; --靜默刪除過期備份 release channel d1; --釋放通道d1 release channel d2; --釋放通道d2 } EOF
下面開始建立0級 1級 2級備份指令碼
0級備份指令碼
vim rman_bak_level0.sh #! /bin/bash export ORACLE_BASE=/u01/oracle export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 export PATH=$ORACLE_HOME/bin:$PATH export ORACLE_SID=neal export NLS_LANG='AMERICAN_AMERICA.ZHS16GBK' rman target / <<EOF run{ allocate channel d1 type disk; allocate channel d2 type disk; backup incremental level 0 database format '/file/backup/rman/level0_%d_%s_%p_%u.bkp'; sql 'alter system archive log current'; backup archivelog all delete input format '/file/backup/rman/archivelog_%d_%s_%p_%u.bkp'; crosscheck backup; delete noprompt obsolete; release channel d1; release channel d2; } EOF
1級備份指令碼
vim rman_bak_level1.sh
#! /bin/bash
export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=neal
export NLS_LANG='AMERICAN_AMERICA.ZHS16GBK'
rman target / <<EOF
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 1 database format '/file/backup/rman/level1_%d_%s_%p_%u.bkp';
sql 'alter system archive log current';
backup archivelog all delete input format '/file/backup/rman/archivelog_%d_%s_%p_%u.bkp';
crosscheck backup;
delete noprompt obsolete;
release channel d1;
release channel d2;
}
EOF
2級備份指令碼vim rman_bak_level2.sh
#! /bin/bash
export ORACLE_SID=neal
export NLS_LANG='AMERICAN_AMERICA.ZHS16GBK'
/u01/oracle/product/11.2.0/db_1/bin/rman target / <<EOF
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 2 database format '/file/backup/rman/level2_%d_%s_%p_%u.bkp';
sql 'alter system archive log current';
backup archivelog all delete input format '/file/backup/rman/archivelog_%d_%s_%p_%u.bkp';
crosscheck backup;
delete noprompt obsolete;
release channel d1;
release channel d2;
}
EOF
加入到crontab中crontab -e
#週日0級備份
00 23 * * 0 /server/scripts/rman_bak_level0.sh
#週一、二、四、五、六2級增量備份
00 23 * * 1,2,4,5,6 /server/scripts/rman_bak_level2.sh
#週三1級增量備份
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.