備份策略:
星期天 0 級(jí)
星期一,二,四,五,六 2 級(jí)
星期三 1 級(jí)
--創(chuàng)建本地管理路徑
mkdir -p /dinglp/ora_managed/backup
mkdir -p /dinglp/ora_managed/backup
mkdir -p /dinglp/ora_managed/backup/export-
mkdir -p /dinglp/ora_managed/backup/log
mkdir -p /dinglp/ora_managed/backup/rman_backup
mkdir -p /dinglp/ora_managed/scripts
--創(chuàng)建rman表空間和rman用戶
create tablespace rman_tbs datafile '/oradata/luke/rman_tbs01.dbf' size 1024M;
create user rman_dlp identified by dlp default tablespace rman_tbs temporary tablespace temp;
grant connect,resource ,recovery_catalog_owner to rman;
--注冊(cè)catalog 數(shù)據(jù)庫(kù)
rman catalog rman_dlp/dlp
create catalog tablespace rman_tbs;
connect target sys/dg@priamry
register database;
report schema;
--設(shè)置備份參數(shù)
configure retention policy to redundancy 2;
configure retention policy to recovery window of 7 days;
--以下是備份腳本(可以通過(guò)vi進(jìn)行編輯)
dlp-> touch exp_rman.par
dlp-> touch exp_rman.sh
dlp-> touch rman_bk_LEVEL0.rcv (數(shù)據(jù)庫(kù)0級(jí)備份)
dlp-> touch rman_bk_LEVEL0.sh
dlp-> touch rman_bk_LEVEL1.rcv (數(shù)據(jù)庫(kù)1級(jí)備份)
dlp-> touch rman_bk_LEVEL1.sh
dlp-> touch rman_bk_LEVEL2.rcv (數(shù)據(jù)庫(kù)2級(jí)備份www.linuxidc.com)
dlp-> touch rman_bk_LEVEL2.sh
--倒出RMAN用戶數(shù)據(jù)腳本exp_rman.par
##################################################
### exp_rman.par ###
##################################################
userid=rman_dlp/dlp
file=/dinglp/ora_managed/backup/export/rman.dmp
log=/dinglp/ora_managed/backup/log/rman.log
--倒出RMAN數(shù)據(jù)SHELL腳本exp_rman.sh
##################################################
### exp_rman.sh ###
##################################################
#!/bin/bash
source /home/Oracle/.bash_profile
cd /dinglp/ora_managed/scripts
exp parfile=exp_rman.par
--零級(jí)備份RMAN腳本rman_bk_LEVEL0.rcv
connect catalog rman_dlp/dlp
connect target sys/dg@primary
run {
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 0 database format '/dinglp/ora_managed/backup/rman_backup/level0_%d_%s_%p_%u.bak'
tag='level 0' include current controlfile;
sql 'alter system archive log current';
backup archivelog all format '/dinglp/ora_managed/backup/rman_backup/log_%d_%s_%p_%u.bak' delete all input;
release channel d2;
release channel d1;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
resync catalog;
exit;
--零級(jí)備份SHELL腳本的rman_bk_LEVEL0.sh
#####################################################################
### rman_bk_LEVEL0.sh ###
#####################################################################
#!/bin/bash
source /home/Oracle/.bash_profile
cd /dinglp/ora_managed/scripts
rman cmdfile=rman_bk_LEVEL0.rcv msglog=$HOME/backup/log/rman_bk_LEVEL0.log
./dinglp/ora_managed/script/exp_rman.sh
--一級(jí)差異增量備份RMAN腳本rman_bk_LEVEL1.rcv
connect catalog rman_dlp/dlp
connect target sys/dg@primary
run {
allocate channel d1 type disk;
backup incremental level 1 format '/dinglp/ora_managed/backup/rman_backup/level1_%d_%s_%p_%u.bak' tag = 'level 1' database;
sql 'alter system archive log current';
backup archivelog all format '/dinglp/ora_managed/backup/rman_backup/log_%d_%s_%p_%u.bak' delete all input;
release channel d1;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
resync catalog;
exit;
--一級(jí)差異增量備份SHELL腳本rman_bk_LEVEL1.sh
#####################################################################
### rman_bk_LEVEL1.sh ###
#####################################################################
#!/bin/bash
source /home/Oracle/.bash_profile
cd /dinglp/ora_managed/scripts
rman cmdfile=rman_bk_LEVEL1.rcv msglog=/dinglp/ora_managed/backup/log/rman_bk_LEVEL1.log
. /dinglp/ora_managed/scripts/exp_rman.sh
--二級(jí)差異增量備份RMAN腳本rman_bk_LEVEL2.rcv
connect catalog rman_dlp/dlp
connect target sys/dg@primary
run {
allocate channel d1 type disk;
backup incremental level 2 format '/dinglp/ora_managed/backup/rman_backup/level2_%d_%s_%p_%u.bak' tag = 'level 2' database;
sql 'alter system archive log current';
backup archivelog all format '/dinglp/ora_managed/backup/rman_backup/log_%d_%s_%p_%u.bak' delete all input;
release channel d1;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
resync catalog;
exit;
--二級(jí)差異增量備份SHELL腳本rman_bk_LEVEL2.sh
#####################################################################
### rman_bk_LEVEL2.sh ###
#####################################################################
#!/bin/bash
source /home/Oracle/.bash_profile
cd /dinglp/ora_managed/scripts
rman cmdfile=rman_bk_LEVEL2.rcv msglog=/dinglp/ora_managed/backup/log/rman_bk_LEVEL2.log
. /dinglp/ora_managed/scripts/exp_rman.sh
--提高RMAN增量備份性能
alter database enable block change tracking using file '/u01/app/Oracle/admin/devdb/bdump/luke.log';
desc v$block_change_tracking;
--RMAN 動(dòng)態(tài)視圖
V$ARCHIVED_LOG 顯示在數(shù)據(jù)庫(kù)中已經(jīng)創(chuàng)建、備份或清除的歸檔文件。
V$BACKUP_CORRUPTION 顯示在備份集的備份過(guò)程中找到的損壞塊。
V$COPY_CORRUPTION 顯示映像復(fù)制過(guò)程中找到的損壞塊。
V$BACKUP_DATAFILE 用于通過(guò)確定各數(shù)據(jù)文件中的塊數(shù)來(lái)創(chuàng)建大小相同的備份集。通過(guò)它也可以找出數(shù)據(jù)文件中已損壞的塊數(shù)。 V$BACKUP_REDOLOG 顯示在備份集中存儲(chǔ)的歸檔日志。
V$BACKUP_SET 顯示已經(jīng)創(chuàng)建的備份集。
V$BACKUP_PIECE 顯示為備份集創(chuàng)建的備份片。
--如何監(jiān)視復(fù)制進(jìn)程
使用 SET COMMAND ID 命令可將服務(wù)器會(huì)話與通道聯(lián)系起來(lái)。
查詢 V$PROCESS 和 V$SESSION,可以確定會(huì)話與哪些 RMAN 通道對(duì)應(yīng)。
查詢 V$SESSION_LONGOPS,可以監(jiān)視備份和復(fù)制的進(jìn)度。
--linux下自動(dòng)運(yùn)行備份腳本
crontab格式簡(jiǎn)介
第1列分鐘1~59
第2列小時(shí)1~23(0表示子夜)
第3列日1~31
第4列月1~12
第5列星期0~6(0表示星期天)
第6列要運(yùn)行的命令
[root@dlp ~]# vi /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
00 22 * * 0 root /dinglp/ora_managed/scripts/rman_bk_LEVEL0.sh
00 22 * * 3 root /dinglp/ora_managed/scripts/rman_bk_LEVEL1.sh
00 22 * * 1,2,4,5,6 root /dinglp/ora_managed/scripts/rman_bk_LEVEL2.sh
--完畢,RYOHEI,2010-08-04。
本文出自:億恩科技【mszdt.com】
服務(wù)器租用/服務(wù)器托管中國(guó)五強(qiáng)!虛擬主機(jī)域名注冊(cè)頂級(jí)提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]
|