您好,登錄后才能下訂單哦!
數據備份當然是為數據恢復準備,新環境的oracle一直在進行備份,但都沒有測試驗證備份的有效性,所以本次測試的重要性不言而喻了!以下為WIN平臺下RMAN異機恢復實例。
源庫 | 目標庫 | |
操作系統 | WIN SVR 2008 R2 | WIN SVR 2008 R2 |
主機名 | Ora | ORATEST |
IP | 192.168.18.20 | 192.168.18.25 |
數據庫版本 | 11.2.0.1.0 | 11.2.0.1.0 |
存儲方式 | 單實例 | 單實例 |
ORACLE_HOME | D:\app\Administrator\product\11.2.0\dbhome_1 | D:\app\Administrator\product\11.2.0\dbhome_1 |
ORACLE_SID | HWPROD | HWPROD |
源庫備份操作:
相關備份配置及腳本如下:
RMAN> show all;
db_unique_name 為 HWPROD 的數據庫的 RMAN 配置參數為:
CONFIGURE RETENTION POLICY TO RECOVERYWINDOW OF 3 DAYS; #保留備份為3天
CONFIGURE BACKUP OPTIMIZATION OFF; #default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; #default
CONFIGURE CONTROLFILE AUTOBACKUP ON; #需要打開自動備份
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FORDEVICE TYPE DISK TO 'e:\data_backup\
ctl_%F.bak'; #指定備份控制文件及參數文件備份路徑格式
CONFIGURE DEVICE TYPE DISK PARALLELISM 1BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICETYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FORDEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; #default
CONFIGURE ENCRYPTION FOR DATABASE OFF; #default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; #default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' ASOF RELEASE 'DEFAULT' OPTIMIZE FOR LOA
D TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TONONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO'D:\APP\ADMINISTRATOR\PRODUCT\11.2.0\DBHO
ME_1\DATABASE\SNCFHWPROD.ORA'; # default
full_backup.sql
run{ allocate channel d1 type disk; allocate channel d2 type disk; backup as compressed backupset fulldatabase format 'e:\data_backup\full_%d_%s_%p_%u_%t.bak'; sql 'alter system archive logcurrent'; backup archivelog all format'e:\data_backup\log_%d_%s_%p_%u_%t.bak' delete all input; release channel d1; release channel d2; report obsolete; crosscheck backup; delete noprompt expired backup; delete noprompt obsolete; }
full_backup.bat
set oracle_sid=hwprod set d=%date:~,4%%date:~5,2%%date:~8,2% echo=>e:\rman_script\log\full_backup_%d%.log rman target /cmdfile=e:\rman_script\full_backup.sqlmsglog=e:\rman_script\log\full_backup_%d%.log
RMAN恢復思路步驟:
初始化數據庫,安裝相同環境;
恢復參數文件;
恢復控制文件;
啟動數據庫到MOUNT狀態,利用控制文件進行數據恢復;
查看歸檔日志備份sequence;
Restore –recover—alter database open ressetlogs;
驗證;
設置監聽
1、 系統安裝完成后,安裝ORACLE軟件,選擇只安裝軟件,并安裝與源庫相同路徑,然后把相關備份文件拷貝到原備份路徑,為避免不必要的麻煩,建議設置與源庫一致。
2、建立相關的密碼文件,服務,監聽器,否則無法連接DB
C:\Users\Administrator>D: D:\>cd D:\app\Administrator\product\11.2.0\dbhome_1\BIN D:\app\Administrator\product\11.2.0\dbhome_1\BIN>orapwd file=D:\app\Administrator\product\11.2.0\dbhome_1\database\pwdhwprod.ora password=oracle entries=5; D:\app\Administrator\product\11.2.0\dbhome_1\BIN>oradim -new -sid HWPROD -startmode m 實例已創建。 D:\app\Administrator\product\11.2.0\dbhome_1\BIN>set ORACLE_SID=HWPROD
D:\app\Administrator\product\11.2.0\dbhome_1\BIN>
D:\app\Administrator\product\11.2.0\dbhome_1\BIN>sqlplus/ as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on 星期五 4月 21 14:19:482017
Copyright (c) 1982, 2010, Oracle. All rights reserved.
已連接到空閑例程。
SQL>
此時可以連接到DB了。
3、手動建立一個pfile文件(目的是使用數據庫啟動到nomount狀態),放到D:\app\Administrator\product\11.2.0\dbhome_1\database目錄下,inithwprod.ora內容如下:
db_name=HWPROD
java_pool_size=4194304
large_pool_size=4194304
shared_pool_size=96468992
以此pfile啟動數據庫到nomount狀態:
SQL> startuppfile='D:\app\Administrator\product\11.2.0\dbhome_1\database\inithwprod.ora' nomount;
ORACLE 例程已經啟動。
Total System Global Area 162873344 bytes
Fixed Size 2173800 bytes
Variable Size 104858776 bytes
Database Buffers 50331648 bytes
Redo Buffers 5509120 bytes
4、切換到RMAN下,并SETDBID=3279461817(源庫DBID):
5、創建flash_recovery_area、ORADATA目錄,否則恢復數據時會報錯ORA-01263: Name given for file destination directory is invalid 。
建立相關目錄:
6、恢復spfile文件:
Restore SPfile文件,找到源spfile備份相關文件進行恢復:
RMAN> restore spfile from'e:\data_backup\CTL_C-3279461817-20180116-00.BAK';
恢復參數文件完成后,shutdown 數據庫,退出RMAN,找到恢復的參數文件把相關參數copy并修改到inithwprod.ora文件里(這里應該注意,源庫可能空間較大,如果設置不當,啟動數據庫到nomount時會報ORA-27102 out of memory 等錯誤,所以關于sga,pga等酌情根據目標庫修改)
以下為修改后的inithwprod.ora文件內容:
hwprod.__java_pool_size=33554432 hwprod.__large_pool_size=33554432 hwprod.__oracle_base='d:\app\Administrator'#ORACLE_BASE set from environment hwprod.__pga_aggregate_target=536870912 hwprod.__sga_target=536870912 hwprod.__shared_io_pool_size=0 hwprod.__shared_pool_size=536870912 hwprod.__streams_pool_size=16777216 *.audit_file_dest='d:\app\Administrator\admin\hwprod\adump' *.audit_trail='db' *.compatible='11.2.0.0.0' *.control_files='d:\app\Administrator\oradata\hwprod\control01.ctl','d:\app\Administrator\flash_recovery_area\hwprod\control02.ctl' *.db_block_size=8192 *.db_domain='hwprod_test' *.db_name='hwprod' *.db_recovery_file_dest='d:\app\Administrator\flash_recovery_area' *.db_recovery_file_dest_size=2147483648 *.diagnostic_dest='d:\app\Administrator' *.dispatchers='(PROTOCOL=TCP) (SERVICE=hwprodXDB)' *.log_archive_format='ARC%S_%R.%T' *.memory_target=1073741824 *.nls_language='SIMPLIFIED CHINESE' *.nls_territory='CHINA' *.open_cursors=100 *.processes=500 *.remote_login_passwordfile='EXCLUSIVE' *.undo_tablespace='UNDOTBS1'
修改完成后再進入RMAN,并把數據庫startup nomount 狀態
SQL> startup nomount pfile='D:\app\Administrator\product\11.2.0\dbhome_1\database\inithwprod.ora' ;
7、此時可以進行恢復控制文件,找到源控制文件備份相關文件進行恢復:
RMAN> restore controlfile from'E:\data_backup\CTL_C-3279461817-20170427-01';
控制文件恢復完成后,接下來把數據庫修改為MOUNT狀態:
8、查看歸檔日志備份的狀態,其最大sequence為18437
RMAN> list backup of archivelog all;
9、進行數據文件恢復:
RMAN> run { 2> set until sequence 18437; 3> restore database; 4> }
RMAN> run { 2> set until sequence 18437; 3> recover database; 4> }
10、resetlogs 打開數據庫:
RMAN> alter database open resetlogs;
11、查看數據庫狀態:
12、添加注冊表SID:
HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraDb11g_home1 "ORACLE_SID"="HWPROD"
13、創建SPfile參數文件
SQL> create spfile from pfile;
可以看到相關路徑已經創建新的參數文件:
14、重啟數據庫,是否以SPFILE啟動:
SQL> select decode(count(*),1,'spfile','pfile') from v$spparameter where rownum=1 and isspecified = 'TRUE';
15、修改listener.ora,tnsnames.ora
listener.ora
# listener.ora Network Configuration File:D:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN\listener.ora # Generated by Oracle configuration tools. SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = HWPROD) (ORACLE_HOME = D:\app\Administrator\product\11.2.0\dbhome_1) (SID_NAME = HWPROD) ) ) LISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = ORATEST)(PORT = 1521)) ) ADR_BASE_LISTENER =D:\app\Administrator\product\11.2.0\dbhome_1\log
tnsnames.ora
# tnsnames.ora Network Configuration File:D:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN\tnsnames.ora # Generated by Oracle configuration tools. HWPROD = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.18.25)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = HWPROD) ) )
查看監聽狀態:
驗證數據,OK!
2018-01-16更新
參考:http://blog.itpub.net/29119536/viewspace-1171894/
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。