備份策略:
星期天 0 級
星期一,二,四,五,六 2 級
星期三 1 級
--創(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;
--注冊catalog 數(shù)據(jù)庫
rman catalog rman_dlp/dlp
create catalog tablespace rman_tbs;
connect target sys/dg@priamry
register database;
report schema;
--設置備份參數(shù)
configure retention policy to redundancy 2;
configure retention policy to recovery window of 7 days;
--以下是備份腳本(可以通過vi進行編輯)
dlp-> touch exp_rman.par
dlp-> touch exp_rman.sh
dlp-> touch rman_bk_LEVEL0.rcv (數(shù)據(jù)庫0級備份)
dlp-> touch rman_bk_LEVEL0.sh
dlp-> touch rman_bk_LEVEL1.rcv (數(shù)據(jù)庫1級備份)
dlp-> touch rman_bk_LEVEL1.sh
dlp-> touch rman_bk_LEVEL2.rcv (數(shù)據(jù)庫2級備份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
--零級備份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;
--零級備份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
--一級差異增量備份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;
--一級差異增量備份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
--二級差異增量備份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;
--二級差異增量備份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 動態(tài)視圖
V$ARCHIVED_LOG 顯示在數(shù)據(jù)庫中已經(jīng)創(chuàng)建、備份或清除的歸檔文件。
V$BACKUP_CORRUPTION 顯示在備份集的備份過程中找到的損壞塊。
V$COPY_CORRUPTION 顯示映像復制過程中找到的損壞塊。
V$BACKUP_DATAFILE 用于通過確定各數(shù)據(jù)文件中的塊數(shù)來創(chuàng)建大小相同的備份集。通過它也可以找出數(shù)據(jù)文件中已損壞的塊數(shù)。 V$BACKUP_REDOLOG 顯示在備份集中存儲的歸檔日志。
V$BACKUP_SET 顯示已經(jīng)創(chuàng)建的備份集。
V$BACKUP_PIECE 顯示為備份集創(chuàng)建的備份片。
--如何監(jiān)視復制進程
使用 SET COMMAND ID 命令可將服務器會話與通道聯(lián)系起來。
查詢 V$PROCESS 和 V$SESSION,可以確定會話與哪些 RMAN 通道對應。
查詢 V$SESSION_LONGOPS,可以監(jiān)視備份和復制的進度。
--linux下自動運行備份腳本
crontab格式簡介
第1列分鐘1~59
第2列小時1~23(0表示子夜)
第3列日1~31
第4列月1~12
第5列星期0~6(0表示星期天)
第6列要運行的命令
[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。
本文出自:億恩科技【1tcdy.com】
服務器租用/服務器托管中國五強!虛擬主機域名注冊頂級提供商!15年品質保障!--億恩科技[ENKJ.COM]
|