1. 程式人生 > >oracle全量、增量備份

oracle全量、增量備份

conf dev form oba home targe let alloc script

采用0221222增量備份策略,7天一個輪回

也就是周日0級備份,周1 2 4 5 6 采用2級增量備份,周3采用1級增量備份

打開控制文件自動備份

CONFIGURE CONTROLFILE AUTOBACKUP ON;

配置控制文件備份路徑

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;

---全備

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級備份腳本

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

oracle全量、增量備份