主頁(yè) > 知識(shí)庫(kù) > oracle備份之備份測(cè)試腳本的方法(冷備、熱備、rman)

oracle備份之備份測(cè)試腳本的方法(冷備、熱備、rman)

熱門(mén)標(biāo)簽:鶴壁電話機(jī)器人價(jià)格 網(wǎng)貸外呼系統(tǒng)合法嗎 地圖標(biāo)注坐標(biāo)圖標(biāo) 電銷(xiāo)套路機(jī)器人 杭州網(wǎng)絡(luò)外呼系統(tǒng)運(yùn)營(yíng)商 手機(jī)地圖標(biāo)注門(mén)店 地圖標(biāo)注效果的制作 安陽(yáng)企業(yè)電銷(xiāo)機(jī)器人供應(yīng)商 汽車(chē)4s店百度地圖標(biāo)注店

1、數(shù)據(jù)庫(kù)環(huán)境

數(shù)據(jù)庫(kù)DBID及打開(kāi)模式

SQL> select dbid,open_mode from v$database; 
DBID OPEN_MODE
---------- ----------
4106451204 READ WRITE

數(shù)據(jù)文件:

SQL> select file#,status,enabled,name from v$datafile;

FILE# STATUS ENABLED NAME
---------- ------- ---------- --------------------------------------------------------------------------------
1 SYSTEM READ WRITE /u01/app/oracle/oradata/ocmdb/dfile/system01.dbf
2 ONLINE READ WRITE /u01/app/oracle/oradata/ocmdb/undotbs01.dbf
3 ONLINE READ WRITE /u01/app/oracle/oradata/ocmdb/dfile/sysaux01.dbf
4 ONLINE READ WRITE /u01/app/oracle/oradata/ocmdb/dfile/tbs_1.dbf
5 ONLINE READ WRITE /u01/app/oracle/oradata/ocmdb/dfile/tbs3.dbf
6 ONLINE READ WRITE /u01/app/oracle/oradata/ocmdb/dfile/tbs_big01.dbf
7 ONLINE READ WRITE /u01/app/oracle/oradata/ocmdb/dfile/rman.dbf

控制文件:

SQL> select status,name from v$controlfile;

STATUS NAME
------- --------------------------------------------------------------------------------
/u01/app/oracle/ocmdb/cfile/ora_control1
/u01/app/oracle/ocmdb/cfile/ora_control2
/u01/app/oracle/ocmdb/cfile/control3

聯(lián)機(jī)日志:

SQL> select group#,status,type,member from v$logfile;

GROUP# STATUS TYPE MEMBER
---------- ------- ------- --------------------------------------------------------------------------------
1 ONLINE /u01/app/oracle/oradata/ocmdb/lfile/redo01.log
1 ONLINE /u01/app/oracle/oradata/ocmdb/lfile/redo11.log
3 ONLINE /u01/app/oracle/oradata/ocmdb/lfile/redo03.log
2 ONLINE /u01/app/oracle/oradata/ocmdb/lfile/redo02.log
5 ONLINE /u01/app/oracle/oradata/ocmdb/lfile/redo05.log
5 ONLINE /u01/app/oracle/oradata/ocmdb/lfile/redo55.log
4 ONLINE /u01/app/oracle/oradata/ocmdb/lfile/redo04.log
4 ONLINE /u01/app/oracle/oradata/ocmdb/lfile/redo44.log

2、數(shù)據(jù)庫(kù)備份腳本

冷備份腳本

#rem script:coldbak.sh
#rem creater:chon
#rem date:2011
#rem desc:offline full backup database

#--connect database
sqlplus / as sysdba EOF
#--shutdown database
shutdown immediate;
#--Copy Data file
!cp /u01/app/oracle/oradata/ocmdb/dfile/*.dbf /backup
!cp /u01/app/oracle/oradata/ocmdb/undotbs01.dbf /backup
#--Copy Control file
!cp /u01/app/oracle/ocmdb/cfile/* /backup
#--Copy Log file
!cp /u01/app/oracle/oradata/ocmdb/lfile/*.log /backup
#--Copy archive log
!cp -R /u01/app/oracle/rmanbak/OCMDB/archivelog/* /backup
#--startup database
startup;

說(shuō)明:
1、以上腳本在數(shù)據(jù)庫(kù)關(guān)閉狀態(tài)下備份數(shù)據(jù)庫(kù)所有的數(shù)據(jù)文件,聯(lián)機(jī)日志,控制文件,歸檔日志(在一個(gè)目錄下),如果成功備份,所有文件是一致的。
2、沒(méi)有備份參數(shù)文件,參數(shù)文件可以另外備份,沒(méi)有必要每次都備份,只需要在改變?cè)O(shè)置后備份一次。
3、如果以上命令沒(méi)有成功依次執(zhí)行,那么備份將是無(wú)效的,如連接數(shù)據(jù)庫(kù)不成功,那么肯定關(guān)閉數(shù)據(jù)庫(kù)也不成功,那么備份則無(wú)效
4、冷備份建議下人工干預(yù)下執(zhí)行。

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

OS熱備份
查看表空間和數(shù)據(jù)文件對(duì)應(yīng)關(guān)系

SQL> select file_id,tablespace_name,file_name from dba_data_files;

FILE_ID TABLESPACE_NAME FILE_NAME
---------- ------------------------------ --------------------------------------------------------------------------------
7 RMAN_TS /u01/app/oracle/oradata/ocmdb/dfile/rman.dbf
6 BIG_TBS /u01/app/oracle/oradata/ocmdb/dfile/tbs_big01.dbf
5 TBS3 /u01/app/oracle/oradata/ocmdb/dfile/tbs3.dbf
4 TBS_1 /u01/app/oracle/oradata/ocmdb/dfile/tbs_1.dbf
3 SYSAUX /u01/app/oracle/oradata/ocmdb/dfile/sysaux01.dbf
2 UNDOTBS /u01/app/oracle/oradata/ocmdb/undotbs01.dbf
1 SYSTEM /u01/app/oracle/oradata/ocmdb/dfile/system01.dbf

數(shù)據(jù)庫(kù)OS熱全備份腳本

#rem script:hotbak.sh
#rem creater:chon
#rem date:2011
#rem desc:backup all database datafile in archive

#--connect database
sqlplus / as sysdba EOF

#--archive
alter system archive log current;

#--start hotbak
alter tablespace system begin backup;
!cp /u01/app/oracle/oradata/ocmdb/dfile/system01.dbf /backup
alter tablespace system end backup;

alter tablespace UNDOTBS begin backup;
!cp /u01/app/oracle/oradata/ocmdb/undotbs01.dbf /backup
alter tablespace UNDOTBS end backup;

alter tablespace SYSAUX begin backup;
!cp /u01/app/oracle/oradata/ocmdb/dfile/sysaux01.dbf /backup
alter tablespace SYSAUX end backup;

alter tablespace TBS_1 begin backup;
!cp /u01/app/oracle/oradata/ocmdb/dfile/tbs_1.dbf /backup
alter tablespace TBS_1 end backup;

alter tablespace TBS3 begin backup;
!cp /u01/app/oracle/oradata/ocmdb/dfile/tbs3.dbf /backup
alter tablespace TBS3 end backup;

alter tablespace BIG_TBS begin backup;
!cp /u01/app/oracle/oradata/ocmdb/dfile/tbs_big01.dbf /backup
alter tablespace BIG_TBS end backup;

alter tablespace RMAN_TS begin backup;
!cp /u01/app/oracle/oradata/ocmdb/dfile/rman.dbf /backup
alter tablespace RMAN_TS end backup;
#--end

#--bak control file
#--binary
alter database backup controlfile to '/backup/controlbinbak.000';
#--ascii
alter database backup controlfile to trace;

alter system archive log current;

說(shuō)明:
1、熱備份必須在數(shù)據(jù)庫(kù)歸檔方式下才可以運(yùn)行
2、以上腳本可以在數(shù)據(jù)庫(kù)運(yùn)行狀態(tài)下備份數(shù)據(jù)庫(kù)所有的數(shù)據(jù)文件(除了臨時(shí)數(shù)據(jù)文件),沒(méi)有必要備份聯(lián)機(jī)日志。
3、歸檔日志至少需要一次完整備份之后的所有日志。
4、如果以上命令沒(méi)有成功依次執(zhí)行,那么備份也是無(wú)效的,如連接數(shù)據(jù)庫(kù)不成功,那么備份則無(wú)效

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

RMAN備份腳本
--本地

創(chuàng)建文件夾

mkdir /home/oracle/backup
mkdir /home/oracle/backup/script
mkdir /home/oracle/backup/log
mkdir /home/oracle/backup/export

--備份目的地

mkdir /home/oracle/rman_backup

創(chuàng)建備份表空間

create tablespace rman_tbs datafile '/oradata/luke/rman_tbs01.dbf' size 1024M;

創(chuàng)建備份用戶

create user rman identified by rman default tablespace rman_tbs temporary tablespace temp;
grant connect,resource ,recovery_catalog_owner to rman;

rman catalog rman/rman
create catalog tablespace rman_tbs;
connect target sys/lukewhx@luke
register database;
report schema;

configure retention policy to redundancy 2;
configure retention policy to recovery window of 7 days;

--倒出RMAN用戶數(shù)據(jù)腳本exp_rman.par (即備份catalog庫(kù))
userid=rman/rman
file=/home/oracle/backup/export/rman.dmp
log=/home/oracle/backup/log/rman.log

-- 倒出RMAN數(shù)據(jù)SHELL腳本exp_rman.sh
#!/bin/bash
cd $HOME
. .bash_profile
cd $HOME/backup/script
exp parfile=exp_rman.par

-- 零級(jí)備份RMAN腳本level0_backup.rcv
connect catalog rman/rman
connect target sys/unumall@unu2
run {

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS; 
CONFIGURE CONTROLFILE AUTOBACKUP ON; 
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 0 database format '/home/oracle/rman_backup/level0_%d_%s_%p_%u.bak'
tag='level 0' include current controlfile;
sql 'alter system archive log current';
backup archivelog all format '/home/oracle/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;

--零級(jí)備份SHELL腳本的level0_backup.sh
#!/bin/bash
cd $HOME
. .bash_profile
cd $HOME/backup/script
rman cmdfile=level0_backup.rcv msglog=$HOME/backup/log/level0_backup.log
. /home/oracle/backup/script/exp_rman.sh


--一級(jí)差異增量備份RMAN腳本 level1_backup.rcv
connect catalog rman/rman
connect target sys/luke@luke
run {
allocate channel d1 type disk;
backup incremental level 1 format '/home/oracle/rman_backup/level1_%d_%s_%p_%u.bak' tag = 'level 1' database;
sql 'alter system archive log current';
backup archivelog all format '/home/oracle/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;


--一級(jí)差異增量備份SHELL腳本level1_backup.sh


#!/bin/bash
cd $HOME
. .bash_profile
cd /home/oracle/backup/script
rman cmdfile=level1_backup.rcv msglog=$HOME/backup/log/level1.log
. /home/oracle/backup/script/exp_rman.sh


--二級(jí)差異增量備份RMAN腳本 level2_backup.rcv
connect catalog rman/rman
connect target sys/luke@luke
run {
allocate channel d1 type disk;
backup incremental level 2 format '/home/oracle/rman_backup/level2_%d_%s_%p_%u.bak' tag = 'level 2' database;
sql 'alter system archive log current';
backup archivelog all format '/home/oracle/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;

--二級(jí)差異增量備份SHELL腳本level2_backup.sh

#!/bin/bash
cd $HOME
. .bash_profile
cd /home/oracle/backup/script
rman cmdfile=level2_backup.rcv msglog=$HOME/backup/log/level2.log
. /home/oracle/backup/script/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;

linux下定時(shí)執(zhí)行備份腳本

crontab -e -u oracle
SHELL=/bin/bash --以下腳本在bash下執(zhí)行
MAILTO=oracle --執(zhí)行日志以郵件形式郵給oracle用戶,可以/var/spool/mail/oracle下查收
10 1 * * 0 /home/oracle/backup/script/level0_backup.sh
10 1 * * 1 /home/oracle/backup/script/level2_backup.sh
10 1 * * 2 /home/oracle/backup/script/level2_backup.sh
10 1 * * 3 /home/oracle/backup/script/level1_backup.sh
10 1 * * 4 /home/oracle/backup/script/level2_backup.sh
10 1 * * 5 /home/oracle/backup/script/level2_backup.sh
10 1 * * 6 /home/oracle/backup/script/level2_backup.sh

一周差異備份策略:
備份目標(biāo)庫(kù)和catalog庫(kù)
周日0級(jí)全備,周一周二為2級(jí),周三為1級(jí),周四周五周六為2級(jí)。
每天凌晨1點(diǎn)10分開(kāi)始備份

零級(jí)備份

backup incremental level 0 database;

一級(jí)差異增量 差異增量是默認(rèn)增量備份方式

backup incremental level 1 database;

一級(jí)累計(jì)增量

backup incremental level 1 cumulative database;

總結(jié)

到此這篇關(guān)于oracle備份之備份測(cè)試腳本的方法(冷備、熱備、rman)的文章就介紹到這了,更多相關(guān)oracle備份測(cè)試腳本內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • mysql數(shù)據(jù)庫(kù)和oracle數(shù)據(jù)庫(kù)之間互相導(dǎo)入備份
  • Oracle數(shù)據(jù)庫(kù)自動(dòng)備份腳本分享(超實(shí)用)
  • Python讀寫(xiě)及備份oracle數(shù)據(jù)庫(kù)操作示例
  • Windows系統(tǒng)下Oracle數(shù)據(jù)庫(kù)每天自動(dòng)備份
  • Linux 自動(dòng)備份oracle數(shù)據(jù)庫(kù)詳解
  • PL/SQL遠(yuǎn)程備份和恢復(fù)Oracle數(shù)據(jù)庫(kù)
  • Oracle自動(dòng)備份及自動(dòng)備份步驟

標(biāo)簽:柳州 泰安 焦作 河源 梧州 南陽(yáng) 銀川 酒泉

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《oracle備份之備份測(cè)試腳本的方法(冷備、熱備、rman)》,本文關(guān)鍵詞  oracle,備份,之,測(cè)試,腳本,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《oracle備份之備份測(cè)試腳本的方法(冷備、熱備、rman)》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于oracle備份之備份測(cè)試腳本的方法(冷備、熱備、rman)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章