為了檢驗我開發(fā)的Oracle數(shù)據(jù)庫在線備份系統(tǒng),我根據(jù)“Oracle數(shù)據(jù)庫在線備份系統(tǒng)”產(chǎn)生的備份文件來重建和恢復Oracle數(shù)據(jù)庫。為了讓大家共享其方法和tb步驟(也適合于用其它方式對Oracle做的熱備份進行重建數(shù)據(jù)庫)現(xiàn)整理如下。
一、系統(tǒng)環(huán)境
本次測試所使用的系統(tǒng)環(huán)境如下:
1. 硬件環(huán)境
服務器:Dell PowerEdge 1300 (CPU:PⅢ 550MHz 內(nèi)存:128MB 硬盤:36GB)
2. 軟件環(huán)境
操作系統(tǒng):UnixWare 7.1
數(shù)據(jù)庫: Oracle 8.1.6 for Unix 企業(yè)版,SID:ora816
Oracle安裝路徑:/home/oracle
備份文件:所有數(shù)據(jù)庫文件、控制文件、初始化文件、數(shù)據(jù)庫備份以來的所有歸檔日志文件。
二、恢復步驟
下面根據(jù)從用戶處帶回來的備份數(shù)據(jù),在一臺新的服務器重建Oracle數(shù)據(jù)庫。其詳細步驟如下:
1. 創(chuàng)建數(shù)據(jù)庫恢復使用的環(huán)境
在新的Dell服務器上,安裝與原來的數(shù)據(jù)庫服務器相同的操作系統(tǒng)UnixWare 7.1;然后安裝與原數(shù)據(jù)庫相同版本的Oracle 8.1.6 for Unix 企業(yè)版。
2. 刪除新服務器上的Oracle實例
啟動新數(shù)據(jù)庫服務器上的Oracle,在sqlplus中,查找到數(shù)據(jù)庫文件的路徑,并保存在當前路徑下的文件file_name.txt中:
$ sqlplus system/manager
SQL> spool file_name.txt
SQL> select file_name from sys.dba_data_files;
SQL> spool end
SQL>exit
關閉新服務器的Oracle,然后根據(jù)文件file_name.txt中的路徑,刪除新裝的Oracle實例的所有數(shù)據(jù)庫文件。
注:從本步開始所有操作都是用Oracle用戶登錄操作系統(tǒng)(Unix)后進行。文中所有的黑色粗體5號字符(標題除外)的語句可以直接執(zhí)行,黑色傾斜粗體5號字符的語句需要修改后執(zhí)行。
3. 恢復數(shù)據(jù)庫文件
把備份的所有數(shù)據(jù)庫文件用Ftp上傳新的數(shù)據(jù)庫服務器中的相同路徑下。如果原來的路徑已不存在,可以拷貝到其他路徑下,恢復時詳細處理方法見步驟7中<2>。
4. 恢復初始化參數(shù)文件
把備份的initSID.ora文件用Ftbp上傳到新數(shù)據(jù)庫服務器中Oracle實例的initSID.ora文件位置,覆蓋之。其位置一般在$ORACLE_HOME/dbs目錄下。
5. 恢復控制文件
把備份的ControlFile.bak文件用Ftp上傳到新數(shù)據(jù)庫服務器中Oracle實例的各個鏡像路徑下,并按初始化參數(shù)文件initSID.ora中的該項的位置和名稱命名。
control_files = ("/home/oracle/app/oracle/oradata/ora816/control01.ctl", "/home/oracle/app/oracle/oradata/ora816/control02.ctl","/home/oracle/app/oracle/oradata/ora816/control03.ctl")
其路徑如有變動,在初始化參數(shù)文件initSID.ora中修改如上內(nèi)容的路徑和名稱,使其實際路徑與該參數(shù)的路徑一致。
6. 恢復歸檔日志文件
把數(shù)據(jù)庫備份后的歸檔日志用Ftp上傳到新數(shù)據(jù)庫服務器的相同路徑下。路徑如有變動可以根據(jù)初始化參數(shù)文件initSID.ora中如下位置進行修改,使其實際路徑與該參數(shù)的路徑一致。
log_archive_dest_1 = "location=/home/oracle/app/oracle/admin/ora816/arch"
7. 恢復數(shù)據(jù)庫
經(jīng)過以上6個步驟,把所有的備份文件已經(jīng)上傳到了新數(shù)據(jù)庫服務器中。下面開始根據(jù)這些文件恢復并啟動數(shù)據(jù)庫,先在操作系統(tǒng)的提示符下做如下操作:
$svrmgrl
SVRMGR>connect internal
SVRMGR>startup mount
<1> 創(chuàng)建口令文件
如果原來的數(shù)據(jù)庫配置了口令文件,并且在mount數(shù)據(jù)庫時報如下錯誤:
ORA-01990: error opening password file '/home/oracle/app/oracle/product/8.1.6/dbs/orapw'
可以到/home/oracle/app/oracle/product/8.1.6/dbs/路徑下,用以下命令創(chuàng)建口令文件:
orapwd
其用法如下:
Usage: orapwd file=<fname> password=<password> entries=<users>
where
file - name of password file (mand),(口令文件的命名方式為:orapwSID)
password - password for SYS and INTERNAL (mand),
entries - maximum number of distinct DBA and OPERs (opt),
There are no spaces around the equal-to (=) character.
例如: orapwd file=orapwora816 password=manager
然后重新執(zhí)行如下語句mount數(shù)據(jù)庫:
SVRMGR>startup mount。
<2> 修改數(shù)據(jù)庫文件的路徑
如果在上述的步驟3中修改了恢復的數(shù)據(jù)庫文件的路徑,可以用如下語句對數(shù)據(jù)庫文件重新命名 :
alter database rename file 'old_file' to 'new_file';
如把原來路徑/home/oracle/app/oracle/oradata/ora816下的文件system01.dbf改到了/u21/oracle/app/oracle/oradata/ora816下:
SVRMGR>alter database rename file
'/home/oracle/app/oracle/oradata/ora816/system01.dbf'
to '/u21/oracle/app/oracle/oradata/ora816/system01.dbf';
按照上面的方法把所有修改路徑的數(shù)據(jù)庫文件重新命名。
<3> 根據(jù)控制文件和歸檔日志文件恢復數(shù)據(jù)庫
下面開始用控制文件和歸檔日志文件恢復數(shù)據(jù)庫:
SVRMGR>recover database using backup controlfile until cancel;
出現(xiàn)如下提示:
ORA-00279: change 50971 generated at 08/23/2002 09:21:27 needed for thread 1
ORA-00289: suggestion: /home/oracle/app/oracle/admin/ora8/arch/arch_1_399.arc
ORA-00280: change 50971 for thread 1 is in sequence #399
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}輸入:
auto
如果有如下提示,則表示成功。
ORA-00279: change 51007 generated at 08/23/2002 11:23:13 needed for thread 1
ORA-00289: suggestion: /home/oracle/app/oracle/admin/ora8/arch/arch_1_400.arc
ORA-00280: change 51007 for thread 1 is in sequence #400
ORA-00278: log file '/home/oracle/app/oracle/admin/ora8/arch/arch_1_399.arc' noy
Log applied.
意外處理:如果其它提示可能是需要的日志文件不存在,檢查ORA-00289中該文件是否存在。
直到出現(xiàn)如下提示:
ORA-00279: change 51011 generated at 08/23/2002 11:23:45 needed for thread 1
ORA-00289: suggestion: /home/oracle/app/oracle/admin/ora8/arch/arch_1_401.arc
ORA-00280: change 51011 for thread 1 is in sequence #401
ORA-00278: log file '/home/oracle/app/oracle/admin/ora8/arch/arch_1_400.arc' noy
ORA-00308: cannot open archived log '/home/oracle/app/oracle/admin/ora8/arch
/arch_1_401.arc'
ORA-27037: unable to obtain file status
Intel SVR4 UNIX Error: 2: No such file or directory
Additional information: 3
<4> 重置日志
SVRMGR>alter database open resetlogs;
意外處理:如果提示創(chuàng)建日志的路徑不存在,按提示路徑創(chuàng)建目錄。然后再重置日志。
<5> 重啟數(shù)據(jù)庫,完成恢復
SVRMGR>shutdown immediate
SVRMGR>startup
ORACLE instance started.
Total System Global Area 123437040 bytes
Fixed Size 69616 bytes
Variable Size 106418176 bytes
Database Buffers 16777216 bytes
Redo Buffers 172032 bytes
Database mounted.
Database opened.
數(shù)據(jù)庫正常打開,數(shù)據(jù)庫重建恢復成功。