跨平臺還原、恢復資料庫(Windows->Linux)

muxinqing發表於2014-03-27

        這篇文章討論剛在客戶現場完成的一個跨平臺的資料庫還原與恢復。生產環境是Windows平臺的11.2.0.3的單機資料庫,新裝了一套Linux平臺的11.2.0.3單機資料庫。由於資料庫版本是相同的,且用於測試,所以直接複製最新的資料庫RMAN備份及部分歸檔Redo日誌恢復到Linux平臺即可。下面是完成的還原與恢復步驟:

1.還原資料庫:
1).複製必要的控制檔案、資料檔案、歸檔Redo日誌檔案備份到Linux伺服器。

2).新建或複製引數檔案,啟動到nomount狀態。
        引數檔案跟資料庫的還原與恢復沒有太大關係。所以新建或者複製,確保引數檔案的內容符合Linux平臺即可。 

3).還原控制檔案:
RMAN > restore controlfile from '/u02/backup/CONTROL_C-1313645298-20120727-00';
RMAN > sql 'alter database mount';

4).編制備份檔案目錄:
a).刪除現有控制檔案中的備份目錄:
RMAN > delete noprompt backup;

b).新編控制檔案備份目錄:
RMAN> catalog start with '/u02/backup';

using target database control file instead of recovery catalog
searching for all files that match the pattern /u02/backup

List of Files Unknown to the Database
=====================================
File Name: /u02/backup/ARCH_ORCL_20120727_185
File Name: /u02/backup/CONTROL_C-1313645298-20120727-00
File Name: /u02/backup/ARCH_ORCL_20120727_183
File Name: /u02/backup/ORCL_20120727_184

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u02/backup/ARCH_ORCL_20120727_185
File Name: /u02/backup/CONTROL_C-1313645298-20120727-00
File Name: /u02/backup/ARCH_ORCL_20120727_183
File Name: /u02/backup/ORCL_20120727_184

5).還原資料庫:
執行類似下面的命令還原資料庫:
RMAN> run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
set newname for datafile 1   to '/u02/oradata/orcl/SYSTEM01.DBF';
set newname for datafile 2         to '/u02/oradata/orcl/SYSAUX01.DBF';
set newname for datafile 3        to '/u02/oradata/orcl/UNDOTBS01.DBF';
set newname for datafile 4         to '/u02/oradata/orcl/USERS01.DBF';
set newname for datafile 5         to '/u02/oradata/orcl/APACCT.DBF';
set newname for datafile 6         to '/u02/oradata/orcl/APAPPM.DBF';
set newname for datafile 7        to '/u02/oradata/orcl/APBLDBANK.DBF';
set newname for datafile 8         to '/u02/oradata/orcl/APCOMM.DBF';
......

restore database;

switch datafile all;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
}

6).恢復資料庫:
       由於這裡只有部分歸檔Redo日誌,只能執行不完全恢復,這裡使用RMAN工具完成資料庫的恢復操作。

a).檢視歸檔Redo日誌情況:
RMAN> list backup of archivelog all;



List of Backup Sets
===================



BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
184     2.32M      DISK        00:00:00     2012-07-27 02:01:07
        BP Key: 184   Status: AVAILABLE  Compressed: NO  Tag: TAG20120727T020106
        Piece Name: /u02/backup/ARCH_ORCL_20120727_185


  List of Archived Logs in backup set 184
  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time
  ---- ------- ---------- ------------------- ---------- ---------
  1    353     10145048   2012-07-27 02:00:03 10145836   2012-07-27 02:01:06


BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
185     556.91M    DISK        00:00:00     2012-07-27 02:00:03
        BP Key: 185   Status: AVAILABLE  Compressed: NO  Tag: TAG20120727T020003
        Piece Name: /u02/backup/ARCH_ORCL_20120727_183


  List of Archived Logs in backup set 185
  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time
  ---- ------- ---------- ------------------- ---------- ---------
  1    346     9918930    2012-07-26 02:01:06 9973935    2012-07-26 09:20:58
  1    347     9973935    2012-07-26 09:20:58 10024381   2012-07-26 12:48:10
  1    348     10024381   2012-07-26 12:48:10 10073180   2012-07-26 18:00:42
  1    349     10073180   2012-07-26 18:00:42 10100578   2012-07-26 22:00:11
  1    350     10100578   2012-07-26 22:00:11 10114265   2012-07-26 22:01:08
  1    351     10114265   2012-07-26 22:01:08 10136125   2012-07-27 00:18:45
  1    352     10136125   2012-07-27 00:18:45 10145048   2012-07-27 02:00:03


        歸檔Redo日誌中最大的序列號是353。

b).檢視現有資料庫的狀態:

SQL> select checkpoint_change# from v$database;

CHECKPOINT_CHANGE#
------------------
          10145048

SQL> select checkpoint_change# from v$datafile;

CHECKPOINT_CHANGE#
------------------
          10145599
          10145599
          10145599
          10145599
          10145599
          10145599
          10145599
          10145599
......
36 rows selected.

SQL> select checkpoint_change# from v$database;

CHECKPOINT_CHANGE#
------------------
          10145048

SQL> select checkpoint_change# from v$datafile_header;

CHECKPOINT_CHANGE#
------------------
                 0
                 0
                 0
                 0
                 0
                 0
                 0
                 0
......
36 rows selected.

          該值是儲存在資料檔案頭中,由於控制檔案中保留的還是Windows環境的資料檔案位置,所以並不能讀取到資料檔案頭中儲存的checkpoint_change#值。

SQL> select checkpoint_change# from v$thread;

CHECKPOINT_CHANGE#
------------------
          10145048

c).恢復資料庫:
RMAN> run{
allocate channel c1 type disk;
allocate channel c2 type disk;
set until sequence 354;
recover database;
release channel c1;
release channel c2;
}
      這裡我們為了能恢復資料庫到一致性的狀態,選用sequence的方式,歸檔Redo日誌最大的sequence是353,所以set until sequence需要指定到353+1。

allocated channel: c1
channel c1: SID=1473 device type=DISK


allocated channel: c2
channel c2: SID=1 device type=DISK


executing command: SET until clause


Starting recover at 2012-07-27 18:27:40
released channel: c1
released channel: c2
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 07/27/2012 18:27:40
RMAN-06094: datafile 1 must be restored

        這是由於在控制檔案中的資料檔案的位置還是Windows環境的位置,所以我們要重建一下控制檔案。

d).重建控制檔案:
[oracle@dbser1 dbs]$ sql


SQL*Plus: Release 11.2.0.3.0 Production on Fri Jul 27 18:28:04 2012


Copyright (c) 1982, 2011, Oracle.  All rights reserved.



Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> select name from v$datafile;


NAME
--------------------------------------------------------------------------------
D:\DATA\ORCL\SYSTEM01.DBF
D:\DATA\ORCL\SYSAUX01.DBF
D:\DATA\ORCL\UNDOTBS01.DBF
D:\DATA\ORCL\USERS01.DBF
D:\DATA\ORCL\APACCT.DBF
D:\DATA\ORCL\APAPPM.DBF
D:\DATA\ORCL\APBLDBANK.DBF
D:\DATA\ORCL\APCOMM.DBF
......
36 rows selected.



SQL> alter database  backup controlfile to trace as '/u02/control.txt';


Database altered.


SQL> shutdown immediate
ORA-01109: database not open



Database dismounted.
ORACLE instance shut down.
SQL>
SQL> startup nomount
ORACLE instance started.


Total System Global Area 2.1379E+10 bytes
Fixed Size                  2237776 bytes
Variable Size            2080377520 bytes
Database Buffers         1.9260E+10 bytes
Redo Buffers               36098048 bytes
SQL> CREATE CONTROLFILE REUSE DATABASE "ORCL" RESETLOGS FORCE LOGGING ARCHIVELOG
  2      MAXLOGFILES 16
  3      MAXLOGMEMBERS 3
  4      MAXDATAFILES 1000
  5      MAXINSTANCES 8
  6      MAXLOGHISTORY 292
  7  LOGFILE
  8    GROUP 1 '/u02/oradata/orcl/REDO01.LOG'  SIZE 128M BLOCKSIZE 512,
  9    GROUP 2 '/u02/oradata/orcl/REDO02.LOG'  SIZE 128M BLOCKSIZE 512,
 10    GROUP 3 '/u02/oradata/orcl/REDO03.LOG'  SIZE 128M BLOCKSIZE 512
 11  -- STANDBY LOGFILE
 12  DATAFILE
 13    '/u02/oradata/orcl/SYSTEM01.DBF',
 14    '/u02/oradata/orcl/SYSAUX01.DBF',
 15    '/u02/oradata/orcl/UNDOTBS01.DBF',
 16    '/u02/oradata/orcl/USERS01.DBF',
  '/u02/oradata/orcl/APACCT.DBF',
 17    '/u02/oradata/orcl/APAPPM.DBF',
 18   19    '/u02/oradata/orcl/APBLDBANK.DBF',
 20    '/u02/oradata/orcl/APCOMM.DBF',
......
 49  CHARACTER SET ZHS16GBK
 50  ;


Control file created.


SQL>

e).重新編制控制檔案中的備份目錄:
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@dbser1 dbs]$ rman target /


Recovery Manager: Release 11.2.0.3.0 - Production on Fri Jul 27 18:32:11 2012


Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.


connected to target database: ORCL (DBID=1313645298, not open)


RMAN> catalog start with '/u02/backup';


using target database control file instead of recovery catalog
searching for all files that match the pattern /u02/backup


List of Files Unknown to the Database
=====================================
File Name: /u02/backup/ARCH_ORCL_20120727_185
File Name: /u02/backup/CONTROL_C-1313645298-20120727-00
File Name: /u02/backup/ARCH_ORCL_20120727_183
File Name: /u02/backup/ORCL_20120727_184


Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done


List of Cataloged Files
=======================
File Name: /u02/backup/ARCH_ORCL_20120727_185
File Name: /u02/backup/CONTROL_C-1313645298-20120727-00
File Name: /u02/backup/ARCH_ORCL_20120727_183
File Name: /u02/backup/ORCL_20120727_184

f).恢復資料庫:
RMAN> run{
2> set until sequence 354;
3> recover database;
4> }


executing command: SET until clause


Starting recover at 2012-07-27 18:32:51
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1473 device type=DISK


starting media recovery


channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=353
channel ORA_DISK_1: reading from backup piece /u02/backup/ARCH_ORCL_20120727_185
channel ORA_DISK_1: piece handle=/u02/backup/ARCH_ORCL_20120727_185 tag=TAG20120727T020106
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u02/fast_recovery_area/ORCL/archivelog/2012_07_27/o1_mf_1_353_814vlr4f_.arc thread=1 sequence=353
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 07/27/2012 18:33:03
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile '/u02/fast_recovery_area/ORCL/archivelog/2012_07_27/o1_mf_1_353_814vlr4f_.arc'
ORA-10562: Error occurred while applying redo to data block (file# 2, block# 124805)
ORA-10564: tablespace SYSAUX
ORA-01110: data file 2: '/u02/oradata/orcl/SYSAUX01.DBF'
ORA-10561: block type 'TRANSACTION MANAGED INDEX BLOCK', data object# 84284
ORA-00600: internal error code, arguments: [ktbair2_0], [154], [64], [], [], [], [], [], [], [], [], []


g).檢視恢復後的資料庫狀態:
SQL> select checkpoint_change# from v$datafile_header;


CHECKPOINT_CHANGE#
------------------
          10145603
          10145603
          10145603
          10145603
          10145603
          10145603
          10145603
          10145603
......
36 rows selected.

        序列號353的歸檔Redo日誌的SCN號在10145048~10145836之間,現在資料檔案頭中的資訊在此範圍內,說明資料檔案已經應用了353的歸檔Redo日誌。

SQL> select checkpoint_change# from v$database;


CHECKPOINT_CHANGE#
------------------
                 0


SQL> select last_change# from v$datafile;


LAST_CHANGE#
------------









........
36 rows selected.

        由於控制檔案被重建,儲存在其中的checkpoint_change#資訊全部都沒了。

h).開啟資料庫:
SQL> alter database open resetlogs;


Database altered.


SQL> select status from v$instance;


STATUS
------------
OPEN


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29065182/viewspace-1130630/,如需轉載,請註明出處,否則將追究法律責任。

相關文章