1. 程式人生 > >RMAN備份策略

RMAN備份策略

fault alloc app red 復數 恢復數據 存儲空間 include channel

前言

對Oracle數據庫制定一個有效的備份策略,使用RMAN做增量備份,減少每次都全備所帶來的時間、系統資源和存儲空間的占用,同時也盡量地減少恢復數據庫的時間。

一、備份規劃

技術分享圖片

二、RMAN配置

RMAN> show all;

RMAN configuration parameters for database with db_unique_name ORCL are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default CONFIGURE CONTROLFILE AUTOBACKUP ON; CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO /home/backup/controlfile/%F; CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET; 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 /home/backup/backup_%U; CONFIGURE MAXSETSIZE TO UNLIMITED; # default CONFIGURE ENCRYPTION FOR DATABASE OFF; # default CONFIGURE ENCRYPTION ALGORITHM AES128; # default
CONFIGURE COMPRESSION ALGORITHM BASIC AS OF RELEASE DEFAULT OPTIMIZE FOR LOAD TRUE ; # default CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default CONFIGURE SNAPSHOT CONTROLFILE NAME TO /u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_orcl.f; # default

三、備份腳本

3.1、0級備份腳本

#!/usr/bin/bash
export ORACLE_SID=orcl 
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
DATE=`date +%y-%m-%d`
$ORACLE_HOME/bin/rman target / log=/home/scripts/rman/log/${DATE}_L0.log <<EOF
run
{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
sql alter system archive log current;
backup filesperset 2 incremental level 0 tag level0 format /home/backup/level0/lvl0_%d_%T_%U database include current controlfile;
sql alter system archive log current;
backup  filesperset 2 archivelog all tag arch_level0 format /home/backup/arch/arch_lvl0_%d_%T_%U delete all input;
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired backup;
delete noprompt expired archivelog all;
delete noprompt obsolete;
release channel c1;
release channel c2;
}
EOF

3.2、1級備份腳本

#!/usr/bin/bash
export ORACLE_SID=orcl 
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
DATE=`date +%y-%m-%d`
$ORACLE_HOME/bin/rman target / log=/home/scripts/rman/log/${DATE}_L1.log <<EOF
run
{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
sql alter system archive log current;
backup filesperset 2 incremental level 1 tag level1 format /home/backup/level1/lvl1_%d_%T_%U database include current controlfile;
sql alter system archive log current;
backup filesperset 2 archivelog all tag arch_level1 format /home/backup/arch/arch_lvl1_%d_%T_%U delete all input;
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired backup;
delete noprompt expired archivelog all;
delete noprompt obsolete;
release channel c1;
release channel c2;
}
EOF

3.3、2級備份腳本

#!/usr/bin/bash
export ORACLE_SID=orcl 
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
DATE=`date +%y-%m-%d`
$ORACLE_HOME/bin/rman target / log=/home/scripts/rman/log/${DATE}_L2.log <<EOF
run
{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
sql alter system archive log current;
backup filesperset 2 incremental level 2 tag level2 format /home/backup/level2/lvl2_%d_%T_%U database include current controlfile;
sql alter system archive log current;
backup filesperset 2 archivelog all tag arch_level2 format /home/backup/arch/arch_lvl2_%d_%T_%U delete all input;
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired backup;
delete noprompt expired archivelog all;
delete noprompt obsolete;
release channel c1;
release channel c2;
}
EOF

四、添加腳本到定時任務

0 2 * * 0 nohup sh /home/scripts/rman/bak/rman0.sh >/dev/null 2>&1 &
0 2 * * 1 nohup sh /home/scripts/rman/bak/rman2.sh >/dev/null 2>&1 &
0 2 * * 2 nohup sh /home/scripts/rman/bak/rman2.sh >/dev/null 2>&1 &
0 2 * * 3 nohup sh /home/scripts/rman/bak/rman1.sh >/dev/null 2>&1 &
0 2 * * 4 nohup sh /home/scripts/rman/bak/rman2.sh >/dev/null 2>&1 &
0 2 * * 5 nohup sh /home/scripts/rman/bak/rman2.sh >/dev/null 2>&1 &
0 2 * * 6 nohup sh /home/scripts/rman/bak/rman2.sh >/dev/null 2>&1 &

RMAN備份策略