異機恢復oracle數據庫;
找新的一臺虛機,安裝oracle數據庫,並創建默認數據庫。需要注意以下幾點:
1. 恢復目標機target db的instance name,sid以及數據庫名稱需與source db 恢復源db的名稱保持一致,在目標恢復機恢復時copy備份數據到fra flashrecoverarea且設置源的dbid;
2. 恢復目標機target db的數據庫字符集編碼需要與source db恢復源db的字符編碼保持一致;
SQL> select * from nls_database_parameters;
PARAMETER VALUE
------------------------------ --------------------------------------------------------------------------------
NLS_CSMIG_SCHEMA_VERSION 5
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CHARACTERSET ZHS16GBK
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
PARAMETER VALUE
------------------------------ --------------------------------------------------------------------------------
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
NLS_NCHAR_CHARACTERSET UTF8
NLS_RDBMS_VERSION 11.2.0.1.0
21 rows selected.
查出NLS_CHARACTERSET ZHS16GBK
Copy test.rar壓縮包中的源source db的flash_recovery_area目錄,到target db的flash_recovery_area目錄;
最終第一次嘗試恢復失敗,失敗原因是已經在target db目標數據庫中創建了數據庫,不是創建了就無法恢復,而是如果源和目標sid不一樣,如何修改尚不得而知;
使用deinstall反安裝數據庫;
創建fra flash_recovery_area目錄,oradata目錄等rman恢復需要的目錄;
對數據庫軟件重新進行安裝,在安裝時不創建數據庫,自然也不需要創建數據庫;只保留數據庫軟件即可;
C:\Windows\system32>oradim -new -sid test
Instance created.
重建數據庫instance,sid名稱需要與源數據庫source db的名稱一致;
C:\Windows\system32>orapwd file=c:\app\Azar\product\11.2.0\test\database\PWDTEST.ora password=Test123
重建密碼文件;
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Administrator>set oracle_sid=test
C:\Users\Administrator>rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Mon Dec 31 10:22:51 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database (not started)
RMAN> set dbid=2098104796;
executing command: SET DBID
Set dbid 數據庫唯一標識id,該id需要從源數據庫source DB中查詢:
SQL> select dbid from v$database;
DBID
----------
2098104796
RMAN> startup nomount;
tartup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file 'D:\ORACLE\PRODUCT\11.2.0\TEST\DATABASE
\INITTEST.ORA'
starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started
Total System Global Area 158662656 bytes
Fixed Size 2173840 bytes
Variable Size 88081520 bytes
Database Buffers 62914560 bytes
Redo Buffers 5492736 bytes
從數據庫文件中恢復spfile,需要知道spfile存在於哪個rman備份中;
查詢源sourceDB數據庫:
RMAN> list backup of spfile;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
33 Full 9.45M DISK 00:00:00 30-DEC-12
BP Key: 33 Status: AVAILABLE Compressed: NO Tag: TAG20121230T181522
Piece Name: D:\ORACLE\FLASH_RECOVERY_AREA\TEST\AUTOBACKUP\2012_12_30\O1_MF_S_803412922_8G051TMY_.BKP
SPFILE Included: Modification time: 30-DEC-12
SPFILE db_unique_name: TEST
備份集BS 33中文件就是spfile和controlfile的備份文件;
RMAN> restore spfile to pfile 'd:\pfile18.txt' from 'D:\oracle\flash_recovery_ar
ea\test\AUTOBACKUP\2012_12_30\O1_MF_S_803412922_8G051TMY_.BKP'
2> ;
Starting restore at 31-DEC-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=96 device type=DISK
channel ORA_DISK_1: restoring spfile from AUTOBACKUP D:\oracle\flash_recovery_ar
ea\test\AUTOBACKUP\2012_12_30\O1_MF_S_803412922_8G051TMY_.BKP
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 31-DEC-12
將該文件恢復到d盤pfile18.txt;
此處容易出錯,恢復完pfile後,需要使用該pfile startup nomount,如果不使用該pfile進行掛載,則後面恢復controlfile是隻能恢復到默認位置,並不是sourceDB源數據庫應該恢復的位置及數量;
RMAN> restore controlfile from 'D:\oracle\flash_recovery_area\test\AUTOBACKUP\20
12_12_30\O1_MF_S_803412922_8G051TMY_.BKP';
Starting restore at 31-DEC-12
using channel ORA_DISK_1
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=D:\ORACLE\PRODUCT\11.2.0\TEST\DATABASE\CTL1TEST.ORA
Finished restore at 31-DEC-12
這個位置和數量是錯的
先掛載恢復出來的pfile
Startup nomount pfile=‘d:\pfile18.txt’;
然後通過該pfile生成spfile;
Select spfile from pfile;
然後再恢復controlfile;
RMAN> restore controlfile from 'D:\oracle\flash_recovery_area\test\AUTOBACKUP\20
12_12_30\O1_MF_S_803412922_8G051TMY_.BKP';
Starting restore at 31-DEC-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=134 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=D:\ORACLE\ORADATA\TEST\CONTROL01.CTL
output file name=D:\ORACLE\FLASH_RECOVERY_AREA\TEST\CONTROL02.CTL
Finished restore at 31-DEC-12
Controlfile恢復成功;
RMAN> restore database;
Starting restore at 31-DEC-12
Starting implicit crosscheck backup at 31-DEC-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=134 device type=DISK
Crosschecked 3 objects
Finished implicit crosscheck backup at 31-DEC-12
Starting implicit crosscheck copy at 31-DEC-12
using channel ORA_DISK_1
Finished implicit crosscheck copy at 31-DEC-12
searching for all files in the recovery area
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: D:\ORACLE\FLASH_RECOVERY_AREA\TEST\AUTOBACKUP\2012_12_30\O1_MF_S_8034
12922_8G051TMY_.BKP
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to D:\ORACLE\ORADATA\TEST\SYSTEM01.
DBF
channel ORA_DISK_1: restoring datafile 00002 to D:\ORACLE\ORADATA\TEST\SYSAUX01.
DBF
channel ORA_DISK_1: restoring datafile 00003 to D:\ORACLE\ORADATA\TEST\UNDOTBS01
.DBF
channel ORA_DISK_1: restoring datafile 00004 to D:\ORACLE\ORADATA\TEST\USERS01.D
BF
channel ORA_DISK_1: restoring datafile 00005 to D:\ORACLE\ORADATA\TEST\EXAMPLE01
.DBF
channel ORA_DISK_1: restoring datafile 00006 to D:\ORACLE\ORADATA\TEST\NONCRIT.D
BF
channel ORA_DISK_1: restoring datafile 00007 to D:\ORACLE\PRODUCT\11.2.0\TEST\DA
TABASE\UNDO_NG01.DBF
channel ORA_DISK_1: restoring datafile 00008 to D:\ORACLE\PRODUCT\11.2.0\TEST\DA
TABASE\UNDO_G01.DBF
channel ORA_DISK_1: restoring datafile 00009 to D:\ORACLE\ORADATA\TEST\TEST12121
7.DBF
channel ORA_DISK_1: reading from backup piece D:\ORACLE\FLASH_RECOVERY_AREA\TEST
\BACKUPSET\2012_12_30\O1_MF_NNNDF_TAG20121230T170800_8G013JGD_.BKP
channel ORA_DISK_1: piece handle=D:\ORACLE\FLASH_RECOVERY_AREA\TEST\BACKUPSET\20
12_12_30\O1_MF_NNNDF_TAG20121230T170800_8G013JGD_.BKP tag=TAG20121230T170800
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:15
Finished restore at 31-DEC-12
RMAN> recover database;
Starting recover at 31-DEC-12
using channel ORA_DISK_1
starting media recovery
archived log for thread 1 with sequence 103 is already on disk as file D:\ORACLE
\FLASH_RECOVERY_AREA\TEST\ARCHIVELOG\2012_12_30\O1_MF_1_103_8G051RW2_.ARC
archived log file name=D:\ORACLE\FLASH_RECOVERY_AREA\TEST\ARCHIVELOG\2012_12_30\
O1_MF_1_103_8G051RW2_.ARC thread=1 sequence=103
unable to find archived log
archived log thread=1 sequence=104
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 12/31/2012 14:43:00
RMAN-06054: media recovery requesting unknown archived log for thread 1 with seq
uence 104 and starting SCN of 2798010
這裏出錯是因爲archivelog只有104個記錄號;所以只恢復104號記錄;
RMAN> run{
2> set until sequence 104;
3> recover database;}
executing command: SET until clause
Starting recover at 31-DEC-12
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 31-DEC-12
恢復成功;
但是打開數據庫後,修改temp臨時段表空間時系統報錯;
RMAN> alter tablespace temp add tempfile 'D:\oracle\oradata\test\temp01.dbf' siz
e 100M reuse autoextend on next 10M maxsize 1000M;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "tablespace": expecting one of: "database"
RMAN-01007: at line 2 column 7 file: standard input
RMAN> alter tablespace temp add tempfile 'D:\oracle\oradata\test\temp01.dbf' siz
e 100M reuse autoextend on next 10M maxsize 1000M;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "tablespace": expecting one of: "database"
RMAN-01007: at line 1 column 7 file: standard input
RMAN> alter database open resetlogs;
Resetlog,系統會根據controlfile中的定義,重新生成redolog組,因爲備份並不需要備份redolog,只備份redolog相關的archivelog;
database opened
RMAN-06900: WARNING: unable to generate V$RMAN_STATUS or V$RMAN_OUTPUT row
RMAN-06901: WARNING: disabling update of the V$RMAN_STATUS and V$RMAN_OUTPUT row
s
ORACLE error from target database:
ORA-00604: error occurred at recursive SQL level 1
ORA-06553: PLS-801: internal error [56327]
ORA-06553: PLS-801: internal error [56327]
RMAN> alter tablespace temp add tempfile 'D:\oracle\oradata\test\temp01.dbf' siz
e 100M reuse autoextend on next 10M maxsize 1000M;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "tablespace": expecting one of: "database"
RMAN-01007: at line 1 column 7 file: standard input
RMAN> shutdown immediate;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of shutdown command at 12/31/2012 14:46:26
ORA-00604: error occurred at recursive SQL level 1
ORA-06553: PLS-801: internal error [56327]
ORA-06553: PLS-801: internal error [56327]
RMAN> alter temporary tablespace temp add tempfile 'D:\oracle\oradata\test\temp0
1.dbf' size 100M reuse autoextend on next 10M maxsize 1000M;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "identifier": expecting one of: "database"
RMAN-01008: the bad identifier was: temporary
RMAN-01007: at line 1 column 7 file: standard input
RMAN> create temporary tablespace temp1 tempfile 'D:\oracle\oradata\test\temp02.
dbf' size 20M;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "identifier": expecting one of: "catalog, global
, restore, script, virtual"
RMAN-01008: the bad identifier was: temporary
RMAN-01007: at line 1 column 8 file: standard input
RMAN> exit
需要加載到upgrade模式後,重新編譯數據庫對象;
Shutdown immediate
C:\Users\Administrator>sqlplus / as sysdba;
SQL*Plus: Release 11.2.0.1.0 Production on Mon Dec 31 14:49:22 2012
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
STARTUP UPGRADE
@@ ?/rdbms/admin/utlirp.sql
編譯後shutdown immediate
在startup open;
後
再重新執行@@ ?/rdbms/admin/utlirp.sql編譯oracle 對象;
打開數據庫修改表空間,成功;