用 RMAN 備份異機恢復 遷移資料

murkey發表於2013-12-18

先假設一種情況,假設有一個資料庫,資料量是2T。 如果要對這個資料庫進行遷移,在不考慮磁碟空間的前提下,要求在最短的時間內完成切換操作。

在不考慮磁碟空間前提下,備份時間,網路傳輸時間,恢復時間。 這個時間對於7*24*365的系統來說,肯定是沒辦法承受的。

如果在考慮下備份空間+遷移後的空間。 這個對磁碟的開銷也是非常大。

在我的前一篇Blog裡,提到了RMAN的異機恢復,這種方法可以縮短我們DB的遷移時間。 但是空間問題還沒有解決。在這一篇,我們主要從遷移時間的角度來考慮這個問題。

RMAN 備份異機恢復 並建立新DBID

http://blog.csdn.net/tianlesoftware/archive/2011/03/11/6240983.aspx

在異機恢復中,我們最後對db 是用open resetlogs的方式開啟的。

我們先看open resetlogs的影響:

(1)如果current online redo可以訪問,那麼對其進行歸檔操作。 然後清空所有online redo 的內容,並將日誌的序列設定為1.

(2)如果online redo 不存在,就建立online redo。 這個位置是在控制檔案裡記錄的。 我們在做RMAN 異機恢復的時候,驗證過這點。

(3)開始一個新的incarnation,初始化redo thread和 online redo 在控制檔案中的記錄。

比如:將redo thread 的狀態設定為closed,在redo thread的記錄中設定當前的log sequence 為1. 設定每個redo thread 的checkpoint 到log sequence 1。

從每個thread 選擇一個redo log,並設定其sequence 為1.

(4)在控制檔案中更新當前所有的datafile 和online redo logs,及以後的歸檔檔案用新的resetlog SCN 和 time stamp。

注意: open resetlogs 不會充值SCN.

一般用open resetlogs 開啟資料庫之後,建議立即對資料庫進行一次備份。

下面是一個遷移的測試:

1. 在Target 庫rman 備份資料庫,並將備份copy到Auxiliary庫的相同位置

RMAN 的恢復對備份位置有講究,對於nocatalog模式下,這些備份的位置是寫在控制檔案裡的。所以目錄結構要相同。

關於RMAN 的shell 備份指令碼,參考:

Nocatalog 下的RMAN 增量備份 shell指令碼

http://blog.csdn.net/tianlesoftware/archive/2011/01/26/6164931.aspx

[oracle@qs-dmm-rh1 backup]$ scp * 192.168.2.43:/u01/backup

oracle@192.168.2.43's password:

arch_23m709vi_1_1_20110312 100% 6431KB 6.3MB/s 00:00

ctl_file_24m709vn_1_1_20110312 100% 9568KB 9.3MB/s 00:01

dave_lev0_1rm709u9_1_1_20110312 100% 610MB 12.0MB/s 00:51

dave_lev0_1sm709u9_1_1_20110312 100% 399MB 11.7MB/s 00:34

dave_lev0_1tm709u9_1_1_20110312 100% 4728KB 4.6MB/s 00:00

dave_lev0_1vm709uk_1_1_20110312 100% 1344KB 1.3MB/s 00:01

dave_spfile_25m709vp_1_1_20110312 100% 96KB 96.0KB/s 00:00

2. 在Auxiliary庫建立相關的目錄,口令檔案,和初始化檔案。

初始化檔案可以直接從Target copy過來。如果目錄結構相同的話,都不用修改引數。

3. 用初始化檔案將資料庫啟動到noumout狀態。

SQL> startup nomount pfile=?/dbs/initdave.ora

ORACLE instance started.

Total System Global Area 196681728 bytes

Fixed Size 1335444 bytes

Variable Size 83890028 bytes

Database Buffers 109051904 bytes

Redo Buffers 2404352 bytes

4. 恢復控制檔案

RMAN> restore controlfile from '/u01/backup/ctl_file_2qm72jcf_1_1_20110312';

Starting restore at 12-MAR-11

using channel ORA_DISK_1

channel ORA_DISK_1: restoring control file

channel ORA_DISK_1: restore complete, elapsed time: 00:00:02

output file name=/u01/oradata/control01.ctl

output file name=/u01/oradata/control02.ctl

output file name=/u01/oradata/control03.ctl

Finished restore at 12-MAR-11

5. 將資料庫啟動到mout狀態

SQL> alter database mount;

Database altered.

6. restore 資料庫

RMAN> restore database;

Starting restore at 12-MAR-11

released channel: ORA_DISK_1

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=20 device type=DISK

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 00003 to /u01/app/oracle/oradata/dave/undotbs01.dbf

channel ORA_DISK_1: reading from backup piece /u01/backup/dave_lev0_28m70ar0_1_1_20110312

channel ORA_DISK_1: piece handle=/u01/backup/dave_lev0_28m70ar0_1_1_20110312 tag=DAVE_LEV0

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

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 00004 to /u01/app/oracle/oradata/dave/users01.dbf

channel ORA_DISK_1: reading from backup piece /u01/backup/dave_lev0_2am70ara_1_1_20110312

channel ORA_DISK_1: piece handle=/u01/backup/dave_lev0_2am70ara_1_1_20110312 tag=DAVE_LEV0

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

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 00002 to /u01/app/oracle/oradata/dave/sysaux01.dbf

channel ORA_DISK_1: reading from backup piece /u01/backup/dave_lev0_27m70ar0_1_1_20110312

channel ORA_DISK_1: piece handle=/u01/backup/dave_lev0_27m70ar0_1_1_20110312 tag=DAVE_LEV0

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:25

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 /u01/app/oracle/oradata/dave/system01.dbf

channel ORA_DISK_1: reading from backup piece /u01/backup/dave_lev0_26m70ar0_1_1_20110312

channel ORA_DISK_1: piece handle=/u01/backup/dave_lev0_26m70ar0_1_1_20110312 tag=DAVE_LEV0

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:25

Finished restore at 12-MAR-11

7. recover 資料庫

RMAN> recover database;

Starting recover at 12-MAR-11

using channel ORA_DISK_1

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=24

channel ORA_DISK_1: reading from backup piece /u01/backup/arch_2cm70as8_1_1_20110312

channel ORA_DISK_1: piece handle=/u01/backup/arch_2cm70as8_1_1_20110312 tag=ARC_BAK

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_24_745352047.dbf thread=1 sequence=24

channel ORA_DISK_1: starting archived log restore to default destination

channel ORA_DISK_1: restoring archived log

archived log thread=1 sequence=25

channel ORA_DISK_1: reading from backup piece /u01/backup/arch_2dm70as8_1_1_20110312

channel ORA_DISK_1: piece handle=/u01/backup/arch_2dm70as8_1_1_20110312 tag=ARC_BAK

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_25_745352047.dbf thread=1 sequence=25

unable to find archived log

archived log thread=1 sequence=26

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of recover command at 03/12/2011 00:58:04

RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 26 and starting SCN of 1055401

8. 在主庫進行一些事務操作

SQL> create table anhui as select * from all_tables;

Table created.

SQL> commit;

Commit complete.

SQL> alter system switch logfile;

System altered.

9. 關閉主庫,迅速把主庫的歸檔檔案和online redo 複製到Auxiliary庫

[oracle@qs-dmm-rh1 archivelog]$ scp * 192.168.2.43:/u01/archivelog

oracle@192.168.2.43's password:

1_26_745352047.dbf 100% 1509KB 1.5MB/s 00:00

[oracle@qs-dmm-rh1 dave]$ scp redo* 192.168.2.43:/u01/app/oracle/oradata/dave/

oracle@192.168.2.43's password:

redo01.log 100% 50MB 16.7MB/s 00:03

redo02.log 100% 50MB 12.5MB/s 00:04

redo03.log 100% 50MB 12.5MB/s 00:04

[oracle@qs-dmm-rh1 dave]$

10. 再次recover database

RMAN> recover database;

Starting recover at 12-MAR-11

using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 26 is already on disk as file /u01/app/oracle/oradata/dave/redo02.log

archived log for thread 1 with sequence 27 is already on disk as file /u01/app/oracle/oradata/dave/redo03.log

archived log file name=/u01/app/oracle/oradata/dave/redo02.log thread=1 sequence=26

archived log file name=/u01/app/oracle/oradata/dave/redo03.log thread=1 sequence=27

media recovery complete, elapsed time: 00:00:05

Finished recover at 12-MAR-11

11. 開啟資料庫

SQL>alter database open resetlogs;

SQL> select count(*) from dave;

COUNT(*)

----------

71157

12. 重建Temp 表空間

在恢復的時候,會自動建立TEMP 表空間。但是和布豆聊到這個問題的時候,他說這個temp 檔案好像沒有起到作用。 尤其是資料量大的時候,所以他建議重建新增temp 資料檔案。

SQL> select name from v$tempfile;

NAME

--------------------------------------------------------------------------------

/u01/app/oracle/oradata/dave/temp01.dbf

SQL> alter tablespace temp add tempfile '/u01/app/oracle/oradata/dave/temp02.dbf ' size 8192M;

Tablespace altered.

SQL> select name from v$tempfile;

NAME

--------------------------------------------------------------------------------

/u01/app/oracle/oradata/dave/temp01.dbf

/u01/app/oracle/oradata/dave/temp02.dbf

SQL> alter database tempfile '/u01/app/oracle/oradata/dave/temp01.dbf' offline;

Database altered.

SQL> alter database tempfile '/u01/app/oracle/oradata/dave/temp01.dbf' drop including datafiles;

Database altered.

SQL> select name from v$tempfile;

NAME

--------------------------------------------------------------------------------

/u01/app/oracle/oradata/dave/temp02.dbf

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

相關文章