121231異機恢復oracle數據庫

異機恢復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目錄;

最終第一次嘗試恢復失敗,失敗原因是已經在targetdb目標數據庫中創建了數據庫,不是創建了就無法恢復,而是如果源和目標sid不一樣,如何修改尚不得而知;

 

使用deinstall反安裝數據庫;

 

創建fraflash_recovery_area目錄,oradata目錄等rman恢復需要的目錄;

 

對數據庫軟件重新進行安裝,在安裝時不創建數據庫,自然也不需要創建數據庫;只保留數據庫軟件即可;

 

        C:\Windows\system32>oradim-new-sid test

        Instance created.

    

重建數據庫instance,sid名稱需要與源數據庫source db的名稱一致;

 

C:\Windows\system32>orapwdfile=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 3110: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 ofspfile

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;

 

 

Listof Backup Sets

===================

 

 

BSKey  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 AUTOBACKUPD:\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';

 

Startingrestore at 31-DEC-12

usingchannel ORA_DISK_1

 

channelORA_DISK_1: restoring control file

channelORA_DISK_1: restore complete, elapsed time: 00:00:01

outputfile name=D:\ORACLE\PRODUCT\11.2.0\TEST\DATABASE\CTL1TEST.ORA

Finishedrestore 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';

 

Startingrestore at 31-DEC-12

allocatedchannel: ORA_DISK_1

channelORA_DISK_1: SID=134 device type=DISK

 

channelORA_DISK_1: restoring control file

channelORA_DISK_1: restore complete, elapsed time: 00:00:01

outputfile name=D:\ORACLE\ORADATA\TEST\CONTROL01.CTL

outputfile name=D:\ORACLE\FLASH_RECOVERY_AREA\TEST\CONTROL02.CTL

Finishedrestore at 31-DEC-12

 

Controlfile恢復成功;

 

RMAN>restore database;

 

Startingrestore at 31-DEC-12

Startingimplicit crosscheck backup at 31-DEC-12

allocatedchannel: ORA_DISK_1

channelORA_DISK_1: SID=134 device type=DISK

Crosschecked3 objects

Finishedimplicit crosscheck backup at 31-DEC-12

 

Startingimplicit crosscheck copy at 31-DEC-12

usingchannel ORA_DISK_1

Finishedimplicit crosscheck copy at 31-DEC-12

 

searchingfor all files in the recovery area

catalogingfiles...

catalogingdone

 

List ofCataloged Files

=======================

FileName: D:\ORACLE\FLASH_RECOVERY_AREA\TEST\AUTOBACKUP\2012_12_30\O1_MF_S_8034

12922_8G051TMY_.BKP

 

usingchannel ORA_DISK_1

 

channelORA_DISK_1: starting datafile backup set restore

channelORA_DISK_1: specifying datafile(s) to restore from backup set

channelORA_DISK_1: restoring datafile 00001 to D:\ORACLE\ORADATA\TEST\SYSTEM01.

DBF

channelORA_DISK_1: restoring datafile 00002 to D:\ORACLE\ORADATA\TEST\SYSAUX01.

DBF

channelORA_DISK_1: restoring datafile 00003 to D:\ORACLE\ORADATA\TEST\UNDOTBS01

.DBF

channelORA_DISK_1: restoring datafile 00004 to D:\ORACLE\ORADATA\TEST\USERS01.D

BF

channelORA_DISK_1: restoring datafile 00005 to D:\ORACLE\ORADATA\TEST\EXAMPLE01

.DBF

channelORA_DISK_1: restoring datafile 00006 to D:\ORACLE\ORADATA\TEST\NONCRIT.D

BF

channelORA_DISK_1: restoring datafile 00007 to D:\ORACLE\PRODUCT\11.2.0\TEST\DA

TABASE\UNDO_NG01.DBF

channelORA_DISK_1: restoring datafile 00008 to D:\ORACLE\PRODUCT\11.2.0\TEST\DA

TABASE\UNDO_G01.DBF

channelORA_DISK_1: restoring datafile 00009 to D:\ORACLE\ORADATA\TEST\TEST12121

7.DBF

channelORA_DISK_1: reading from backup piece D:\ORACLE\FLASH_RECOVERY_AREA\TEST

\BACKUPSET\2012_12_30\O1_MF_NNNDF_TAG20121230T170800_8G013JGD_.BKP

channelORA_DISK_1: piece handle=D:\ORACLE\FLASH_RECOVERY_AREA\TEST\BACKUPSET\20

12_12_30\O1_MF_NNNDF_TAG20121230T170800_8G013JGD_.BKPtag=TAG20121230T170800

channelORA_DISK_1: restored backup piece 1

channelORA_DISK_1: restore complete, elapsed time: 00:01:15

Finishedrestore at 31-DEC-12

 

 

 

RMAN>recover database;

 

Startingrecover at 31-DEC-12

usingchannel ORA_DISK_1

 

startingmedia recovery

 

archivedlog 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

archivedlog file name=D:\ORACLE\FLASH_RECOVERY_AREA\TEST\ARCHIVELOG\2012_12_30\

O1_MF_1_103_8G051RW2_.ARCthread=1 sequence=103

unableto find archived log

archivedlog 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

uence104 and starting SCN of 2798010

 

這裏出錯是因爲archivelog只有104個記錄號;所以只恢復104號記錄;

 

 

RMAN>run{

2>set until sequence 104;

3>recover database;}

 

executingcommand: SET until clause

 

Startingrecover at 31-DEC-12

usingchannel ORA_DISK_1

 

startingmedia recovery

mediarecovery complete, elapsed time: 00:00:00

 

Finishedrecover at 31-DEC-12

 

恢復成功;

 

但是打開數據庫後,修改temp臨時段表空間時系統報錯;

RMAN>alter tablespace temp add tempfile 'D:\oracle\oradata\test\temp01.dbf' siz

e 100Mreuse 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 100Mreuse 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

 

此處之前理解的有點問題,Resetlogs會重新生成redolog,如果之前的數據庫是正常關閉的,則所有的redolog中的數據都會寫入歸檔聯機日誌,恢復的時候在做recover的時候會應用到數據庫或者相應的表空間當中;

如果之前的數據庫使用abort進行的關閉,則redolog聯機日誌中還有數據沒有寫入到歸檔日誌當中,所以恢復的時候必須有聯機日誌纔可以進行完全恢復;否則,只能進行不完全恢復;

 

databaseopened

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

ORACLEerror 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 100Mreuse 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模式後,重新編譯數據庫對象;

Shutdownimmediate

 

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 rightsreserved.

 

 

Connectedto:

OracleDatabase 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

 

 

STARTUPUPGRADE

@@?/rdbms/admin/utlirp.sql

 

編譯後shutdown immediate

在startup open;

再重新執行@@?/rdbms/admin/utlirp.sql編譯oracle 對象;

 

打開數據庫修改表空間,成功;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章