oracle rman异地备份,rman异地备份与恢复测试
一.分析:RMAN并不支持客戶端連接服務(wù)器進(jìn)行備份,所以仍然需要在服務(wù)器上使用RMAN備份,客戶要求備份至異地;
二.環(huán)境:
1.兩臺win2003 Enterprise edition:主機(jī)名si_vm_w2k3,ip:192.168.2.204;備機(jī)名PC2 ip:192.168.2.205
2.在si_vm_w2k3上和PC2上同時安裝oracle 10.2.0.1.0;
3.ORACLE_HOME=C:\oracle\product\10.2.0\db_1.ORADATA=C:\oracle\product\10.2.0\oradata\lichao;
三.操作步驟:
1,在PC2上創(chuàng)建共享目錄RMAN,在RMAN目錄里建子目錄logs,并授予administrator權(quán)限,保證administrator具備口令為Root1!口令不能為空;
2,在si_vm_w2k3確保administrator的口令與PC2的administrator口令相同且為Root1!;
3,在si_vm_w2k3映射目錄為Z盤,并明確登錄用戶為administrator及口令;
4,在si_vm_w2k3機(jī)器修改ORACLE的兩個服務(wù)OracleTNSListerner和OracleServiceLICHAO為賬戶登錄:用戶名為administrator,口令為Root1!;
5,重啟si_vm_w2k3機(jī)器的兩個服務(wù);
備份可以備份在本地,有必要時再傳到PC2上。
創(chuàng)建復(fù)制數(shù)據(jù)庫:
1,創(chuàng)建口令文件orapwd file=c:\oracle\product\10.2.0\db_1\database\pwdlichao.ora password=admin entries=10
2,創(chuàng)建輔助數(shù)據(jù)庫實(shí)例:
Oradim –new –sid test
4.配置監(jiān)聽程序
在這里我們需要配置的監(jiān)聽有兩個分別是原數(shù)據(jù)庫和復(fù)制數(shù)據(jù)庫的監(jiān)聽
TEST實(shí)例的監(jiān)聽
Listener.ora:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = test)
(ORACLE_HOME = C:\oracle\product\10.2.0\db_1)
(SID_NAME = test))
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.205)(PORT = 1521))
)
)
Tnsname.ora:
lichao =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.204)(PORT = 1521))
)
(CONNECT_DATA =
(SID = lichao))
)
test =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.205)(PORT = 1521))
)
(CONNECT_DATA =
(SID = test))
)
lichao實(shí)例監(jiān)聽配置:
Listener.ora:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = test)
(ORACLE_HOME = C:\oracle\product\10.2.0\db_1)
(SID_NAME = lichao))
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.204)(PORT = 1521))
)
)
Tnsname.ora:
lichao =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.204)(PORT = 1521))
)
(CONNECT_DATA =
(SID = lichao))
)
test =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.205)(PORT = 1521))
)
(CONNECT_DATA =
(SID = test))
)
配置完監(jiān)聽記得重新啟動監(jiān)聽的服務(wù)進(jìn)程,并使用lsnrctl stop、lsnrctl start來重新啟動監(jiān)聽
5,創(chuàng)建輔助(復(fù)制)數(shù)據(jù)庫的目錄
6,創(chuàng)建輔助(復(fù)制)數(shù)據(jù)庫的參數(shù)文件
主庫執(zhí)行Create pfile from spfile
復(fù)制pfile到復(fù)制數(shù)據(jù)庫,修改相關(guān)參數(shù):
Adump、bdump、cdump、udump、ddump、db_name和控制文件路徑。
還需要添加兩個參數(shù):
db_file_name_convert=(¨c:\oracle\product\10.2.0\oradata\lichao¨,¨c:\oracle\product\10.2.0\oradata\lichao¨)
log_file_name_convert=(¨c:\oracle\product\10.2.0\oradata\lichao¨,¨c:\oracle\product\10.2.0\oradata\lichao¨)
完成以上步驟后我們可以開始創(chuàng)建我們真正想要的參數(shù)文件:
7,SQL>create spfile=’c:\oracle\product\10.2.0\db_1\database\spfilelichao.ora’ from pfile=’c:\abc.ora
使用RMAN完全備份原數(shù)據(jù)庫
導(dǎo)入數(shù)據(jù):
創(chuàng)建表空間lnxh_v2:Create tablespace lnxh_v2 datafile’ C:\oracle\product\10.2.0\oradata\tom\lnxh_v2.dbf’ size 30000m;
創(chuàng)建用戶:lnxh_v2:create user lnxh_v2 identified by lnxh_v2 default tablespace
Lnxh_v2;
導(dǎo)入數(shù)據(jù)imp userid=lnxh_v2/lnxh_v2 file=c.\xx\lnxh.dmp log=imp.log fromuser=lnxh_v2 touser=lnxh_v2
查看lnxh_v2用戶表:
SQL> select count(table_name) from dba_tables where wner='LNXH_V2';
COUNT(TABLE_NAME)
-----------------
858
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
820841
Run{
Backup full database format ‘\\192.168.2.205/rman /%U.bak';
Backup archivelog all format ‘\\192.168.2.205/rman /arc_%U.bak’;
Copy current controlfile to ‘\\192.168.2.205/rman /control_bak.ctl’;
}
8復(fù)制庫處于nomount狀態(tài)。
9.創(chuàng)建備份
Rman target /
Run{
Backup full database format ‘\\192.168.2.205/rman /%U.bak';
Backup archivelog all format ‘\\192.168.2.205/rman /arc_%U.bak’;
Copy current controlfile to ‘\\192.168.2.205/rman /control_bak.ctl’;
}
10.使用rman復(fù)制數(shù)據(jù)庫
rman target /? AUXILIARY sys/admin@test
DUPLICATE TARGET DATABASE TO “test” nofilenamecheck
查看復(fù)制庫lnxh_v2用戶表:
SQL> select count(table_name) from dba_tables where wner='LNXH_V2';
COUNT(TABLE_NAME)
-----------------
858
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
820859
啟用主庫塊跟蹤:alter database enable block change tracking;
建立0級備份
Run{
Allocate channel d1 device type disk format ‘\\192.168.2.205/rman/DB_LV_0_%T_%t.rbf’;
Backup
Incremental level 0 database tag ‘LV_0’;
SQL ‘ALTER SYSTEM ARCHIVE LOG CURRENT’;
Release channel d1;
}
建立一個1級備份
Run{
Allocate channel d1 type disk;
Backup
Incremental level 1
Format ‘\\192.168.2.205/rman/%U’
(database);
Release channel d1;
}
主庫:restore database preview;
還原恢復(fù)數(shù)據(jù)庫
Rman target /
Startup nomount
Restore controlfile from ‘\\192.168.2.205/rman/auto_sp_%F.rbf’;
Restore database;
Recover database until sequence xx;
Alter database open resetlogs;
復(fù)制庫上創(chuàng)建恢復(fù)目錄數(shù)據(jù)庫
Create tablespace rman datafile‘C:\oracle\product\10.2.0\oradata\tom\rman.dbf’ size 50m;
Create user rman_user identified by rman_user default tablespace rman temporary tablespace temp;
Rman>connect catalog rman_user/rman_user
Rman>create catalog tablespace rman;
Rman>register database;
登記備份文件和歸檔日志到RMAN倉庫
Rman>catalog start with’c:\rman’(如果復(fù)制過來的備份文件的路徑和主庫不同,要讓RMAN知道這些文件在哪里。
Rman> restore database;
Recovery database until scn ****;
經(jīng)測試恢復(fù)后數(shù)據(jù)正常;
遷移業(yè)務(wù)數(shù)據(jù)到metarnet表空間;
Create tablespace metarnet datafile’Y:\oracle\oradata\metarnet.dbf’ size 4000m;
遷移腳本見lnxh.sql
Conn lnxh_v2/lnxh_v2
Start lnxh.sql
altertable CONF_NE_IP2PORT_Pmovetablespacemetarnet;
altertable CONF_NE_IP2PORT_Vmovetablespacemetarnet;
altertable CONF_NE_IPMACTABLEmovetablespacemetarnet;
altertable CONF_NE_Pmovetablespacemetarnet;
altertable CONF_NE_PORTmovetablespacemetarnet;
altertable CONF_NE_PORT_Pmovetablespacemetarnet;
altertable CONF_NE_PORT_Vmovetablespacemetarnet;
altertable CONF_NE_PROBEmovetablespacemetarnet;
………………………………
遷移完后驗證:
Lnxh_v2用戶登錄查詢:select distinct(tablespace_name) from user_tables;
SQL> select distinct(tablespace_name) from user_tables;
TABLESPACE_NAME
------------------------------
LNXH_V2
METARNET
(由于表空間大小受限,所以部分表遷移未成功,但此操作可以實(shí)現(xiàn)業(yè)務(wù)表從lnxh_v2遷移到metarnet表空間)
再次復(fù)制數(shù)據(jù)庫到異地機(jī);建立測試數(shù)據(jù):主庫做一個基于業(yè)務(wù)表空間metarnet的備份:
Run{
Backup tablesapce metarnet format’\\192.168.2.205/rman/metarnet_%U.bak’;
}
復(fù)制庫上執(zhí)行:
Catalog start with‘c:\rman’;
報錯了無法在目錄表空間注冊備份文件如下:
為做嘗試,我在復(fù)制庫nomount狀態(tài)下還原控制文件:啟動到mount狀態(tài):
Restore tablespace metarnet;
這里提示redolog不同。
再次注冊備份文件:
Catalog start with ‘c:\rman’;
注冊成功
試著恢復(fù)metarnet表空間用備份再次還原;
Restore controlfile from’c:\rman\AUTO_SP_C-18308577735-20110120-03.RBF基于表空間的恢復(fù)還有問題,有待于進(jìn)一步確定;
繼續(xù)測試:
Run{
Backup tablesapce metarnet format’\\192.168.2.205/rman/tablespace_metarnet_%U.bak’;
Run{
Allocate channel d1 device type disk format’\\192.168.2.205/rman/archive_%U.bak’;
Backup archivelog all;
Release channel d1;
}
Catalog start with‘c:/rman’;
Sql‘a(chǎn)lter tablespae metarnet offlien’;
這屬于介質(zhì)恢復(fù),如果原表空間存在并且正常時無法進(jìn)行介質(zhì)恢復(fù)的,系統(tǒng)會報錯。以下是刪除metarnet數(shù)據(jù)文件后進(jìn)行的還原。其實(shí)這個是失敗的,為啥呢,因為抽取的歸檔文件是復(fù)制庫本身的歸檔文件,并不是主庫備份過來的歸檔文件。
所以恢復(fù)表面成功,其實(shí)是數(shù)據(jù)沒有恢復(fù)過來。所以不還原控制文件,這個即使在恢復(fù)目錄中注冊了備份的歸檔,也是無法使用的,因為兩個庫的線程是不一致的。那如果為了還原和恢復(fù)一個表空間,需要還原控制文件了,顯然這樣是行不通的,整個數(shù)據(jù)庫的狀態(tài)就會處于不一致,無法打開。
綜合所做實(shí)驗:如果要使用rman來做方案,那么就要還原控制文件,還原整個數(shù)據(jù)庫,然后再恢復(fù)才會有效果。不能夠還原和恢復(fù)某個表空間。
總結(jié)
以上是生活随笔為你收集整理的oracle rman异地备份,rman异地备份与恢复测试的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 个人发卡系统 - 个人发卡网_忆当站长经
- 下一篇: 航空三字代码表_国际国内城市三字代码查询