使用RMAN備份集搭建Oracle Dataguard Step by Step(一)

煙花丶易冷發表於2014-05-28

 

Data Guard作為Oracle MAA(最大可用性框架)的重要組成部分,已經成為很多成熟運維繫統的標準配置。藉助Data Guard提供的物理standby和邏輯standby,我們可以保證系統資料庫執行在一個較高的可用性環境裡。並且,switchoverfailover策略,可以最大限度的保證日常運維和故障恢復場景。

從最早的9i11gOracle DG搭建過程經歷了很多階段。大致可以分為三種策略方法:

 

ü  Backup and Restore策略:藉助RMAN備份集合(backupset),遠端傳遞到standby伺服器。再利用RMAN還原策略進行還原操作;

ü  RMAN Duplicate策略:同樣是藉助RMAN的機制,提供了duplicate語句可以實現直接的standby搭建,不需要備份集合傳遞過程;

ü  RMAN Duplicate from active database:這個是目前最新的搭建方法。在原有duplicate基礎上,可以實現Primary不停機執行情況下搭建standby

 

在實際中,三種策略各有利弊和使用的場景。Backup and Restore策略和Duplicate方法需要單獨停機過程。而from active database方法對頻寬要求較高。根據實際的部署環境,設計不同的安裝策略,進行多次的測試過程才是確保平穩的關鍵方法。

在之前的文章中,已經介紹過使用duplicate from active database方法搭建Data Guard的步驟。本篇介紹Backup and Restore方法,權當記錄,留待需要朋友參考。

 

1、環境介紹

 

筆者選擇Red Hat6.5版本進行實驗,由於是虛擬機器環境,策劃在相同物理伺服器上搭建PrimaryStandby

 

[root@SimpleLinux ~]# uname -r

2.6.32-431.el6.i686

 

記憶體和儲存空間充足(相對而言)。

 

[root@SimpleLinux ~]# free -m

             total       used       free     shared    buffers     cached

Mem:          1893        129       1763          0         14         54

-/+ buffers/cache:         60       1832

Swap:         1999          0       1999

[root@SimpleLinux ~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda2        48G   16G   31G  34% /

tmpfs           947M     0  947M   0% /dev/shm

 

Primary端已經安裝完成,例項名為ora11g,當前處於非歸檔模式下。

 

 

[oracle@SimpleLinux ~]$ env | grep ORA

ORACLE_SID=ora11g

ORACLE_BASE=/u01/app

ORACLE_HOME=/u01/app/oracle

 

SQL> archive log list

Database log mode              No Archive Mode

Automatic archival             Disabled

Archive destination            USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence     4

Current log sequence           6

 

資料庫版本為11.2.0.4,對應控制檔案、資料檔案、日誌檔案保持預設狀態。

 

SQL> select * from v$version;

 

BANNER

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

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production

PL/SQL Release 11.2.0.4.0 - Production

CORE    11.2.0.4.0      Production

TNS for Linux: Version 11.2.0.4.0 - Production

NLSRTL Version 11.2.0.4.0 – Production

 

三大核心檔案情況如下:

 

SQL> select name from v$controlfile;

 

NAME

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

/u01/app/oradata/ORA11G/controlfile/o1_mf_9mnjwpko_.ctl

/u01/app/fast_recovery_area/ORA11G/controlfile/o1_mf_9mnjwpw2_.ctl

 

 

SQL> select group#, member from v$logfile;

 

    GROUP# MEMBER

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

         3 /u01/app/oradata/ORA11G/onlinelog/o1_mf_3_9mnjx4n0_.log

         3 /u01/app/fast_recovery_area/ORA11G/onlinelog/o1_mf_3_9mnjx54c_.log

         2 /u01/app/oradata/ORA11G/onlinelog/o1_mf_2_9mnjwzpq_.log

         2 /u01/app/fast_recovery_area/ORA11G/onlinelog/o1_mf_2_9mnjx15f_.log

         1 /u01/app/oradata/ORA11G/onlinelog/o1_mf_1_9mnjwtj9_.log

         1 /u01/app/fast_recovery_area/ORA11G/onlinelog/o1_mf_1_9mnjwvdm_.log

 

6 rows selected

 

 

SQL> select file_name, file_id from dba_data_files;

 

FILE_NAME                                                                           FILE_ID

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

/u01/app/oradata/ORA11G/datafile/o1_mf_users_9mnjs074_.dbf                                4

/u01/app/oradata/ORA11G/datafile/o1_mf_undotbs1_9mnjs068_.dbf                             3

/u01/app/oradata/ORA11G/datafile/o1_mf_sysaux_9mnjs04h_.dbf                               2

/u01/app/oradata/ORA11G/datafile/o1_mf_system_9mnjrzty_.dbf                               1

 

系統啟用recovery area dest目錄。

 

SQL> show parameter recovery

 

NAME                                 TYPE        VALUE

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

db_recovery_file_dest                string      /u01/app/fast_recovery_area

db_recovery_file_dest_size           big integer 10000M

recovery_parallelism                 integer     0

 

2Primary端配置

 

首先調整Primary設定,先開啟歸檔模式,選擇預設的recovery area作為歸檔目錄位置就可以了。

 

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup mount

ORACLE instance started.

 

Total System Global Area  372449280 bytes

Fixed Size                  1364732 bytes

Variable Size             293604612 bytes

Database Buffers           71303168 bytes

Redo Buffers                6176768 bytes

Database mounted.

 

SQL> alter database archivelog;

Database altered.

 

SQL> archive log list;

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence     4

Next log sequence to archive   6

Current log sequence           6

 

開啟強制日誌動作:

 

SQL> alter database force logging;

Database altered.

 

3Primary備份和處理

 

此時保持mount狀態,進行RMAN備份。

 

 

[oracle@SimpleLinux ~]$ rman nocatalog

 

Recovery Manager: Release 11.2.0.4.0 - Production on Sat May 24 20:41:50 2014

 

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

 

RMAN> connect target /

connected to target database: ORA11G (DBID=4239941846, not open)

using target database control file instead of recovery catalog

 

--簡單配置

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP on;

 

new RMAN configuration parameters:

CONFIGURE CONTROLFILE AUTOBACKUP ON;

new RMAN configuration parameters are successfully stored

 

備份資料庫檔案和日誌。

 

RMAN> backup database plus archivelog;

 

 

Starting backup at 24-MAY-14

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=19 device type=DISK

specification does not match any archived log in the repository

backup cancelled because there are no files to backup

Finished backup at 24-MAY-14

 

Starting backup at 24-MAY-14

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00001

(篇幅原因,有省略……)

Finished Control File and SPFILE Autobackup at 24-MAY-14

 

備份standby controlfile

 

RMAN> backup current controlfile for standby;

 

Starting backup at 24-MAY-14

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

including standby control file in backup set

channel ORA_DISK_1: starting piece 1 at 24-MAY-14

channel ORA_DISK_1: finished piece 1 at 24-MAY-14

piece handle=/u01/app/fast_recovery_area/ORA11G/backupset/2014_05_24/o1_mf_ncnnf_TAG20140524T204716_9r156r7j_.bkp tag=TAG20140524T204716 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

Finished backup at 24-MAY-14

 

Starting Control File and SPFILE Autobackup at 24-MAY-14

piece handle=/u01/app/fast_recovery_area/ORA11G/autobackup/2014_05_24/o1_mf_s_848435155_9r156vbz_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 24-MAY-14

 

備份集合情況:

 

RMAN> list backup;

 

List of Backup Sets

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

 

 

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

1       Full    1.05G      DISK        00:02:18     24-MAY-14     

        BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20140524T204320

        Piece Name: /u01/app/fast_recovery_area/ORA11G/backupset/2014_05_24/o1_mf_nnndf_TAG20140524T204320_9r14z9hn_.bkp

 (篇幅原因,有省略……

        Piece Name: /u01/app/fast_recovery_area/ORA11G/backupset/2014_05_24/o1_mf_ncnnf_TAG20140524T204716_9r156r7j_.bkp

  Standby Control File Included: Ckp SCN: 696037       Ckp time: 24-MAY-14

 

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

4       Full    9.36M      DISK        00:00:03     24-MAY-14     

        BP Key: 4   Status: AVAILABLE  Compressed: NO  Tag: TAG20140524T204721

        Piece Name: /u01/app/fast_recovery_area/ORA11G/autobackup/2014_05_24/o1_mf_s_848435155_9r156vbz_.bkp

  SPFILE Included: Modification time: 24-MAY-14

  SPFILE db_unique_name: ORA11G

  Control File Included: Ckp SCN: 696037       Ckp time: 24-MAY-14

 

將備份集合檔案複製到standby端伺服器,可以使用sftpscp等方法。這個過程傳輸往往是最快的方法。

 

--standby

[root@SimpleLinux ~]# cd /

[root@SimpleLinux /]# mkdir /standbybackup

[root@SimpleLinux /]# chown oracle:oinstall /standbybackup/

 

[oracle@SimpleLinux 2014_05_24]$ pwd

/u01/app/fast_recovery_area/ORA11G/backupset/2014_05_24

[oracle@SimpleLinux 2014_05_24]$ ls -l

total 1105740

-rw-r-----. 1 oracle oinstall    9797632 May 24 20:47 o1_mf_ncnnf_TAG20140524T204716_9r156r7j_.bkp

-rw-r-----. 1 oracle oinstall 1122476032 May 24 20:45 o1_mf_nnndf_TAG20140524T204320_9r14z9hn_.bkp

[oracle@SimpleLinux 2014_05_24]$ cp * /standbybackup/

 

 

[oracle@SimpleLinux 2014_05_24]$ cd /standbybackup/

[oracle@SimpleLinux standbybackup]$ ls -l

total 1105740

-rw-r-----. 1 oracle oinstall    9797632 May 24 20:50 o1_mf_ncnnf_TAG20140524T204716_9r156r7j_.bkp

-rw-r-----. 1 oracle oinstall 1122476032 May 24 20:52 o1_mf_nnndf_TAG20140524T204320_9r14z9hn_.bkp

 

4Primary端引數修改

 

修改primary端引數,加入歸檔日誌傳輸、檔案自動管理和命名轉換引數。

 

 

SQL> alter system set log_archive_dest_2='SERVICE=ora11gsy valid_for=(online_logfiles,primary_role) db_unique_name=ora11gsy' scope=spfile;

System altered.

 

SQL> alter system set standby_file_management=auto;

System altered.

 

SQL> alter system set db_file_name_convert='ORA11G','ORA11GSY' scope=spfile;

System altered.

 

SQL> alter system set log_file_name_convert='ORA11G','ORA11GSY' scope=spfile;

System altered.

 

建立文字引數檔案,加以修改。

 

--生成文字備份

SQL> create pfile from spfile;

File created.

 

 

SQL> shutdown immediate;

ORA-01109: database not open

 

Database dismounted.

ORACLE instance shut down.

SQL> startup mount;

ORACLE instance started.

 

Total System Global Area  372449280 bytes

Fixed Size                  1364732 bytes

Variable Size             293604612 bytes

Database Buffers           71303168 bytes

Redo Buffers                6176768 bytes

Database mounted.

 

引數檔案預設在$ORACLE_HOME/dbs目錄中。

 

[oracle@SimpleLinux standbybackup]$ cd /u01/app/oracle/dbs/

[oracle@SimpleLinux dbs]$ ls -l

total 9544

-rw-rw----. 1 oracle oinstall    1544 May 24 21:12 hc_ora11g.dat

-rw-r--r--. 1 oracle oinstall    2851 May 15  2009 init.ora

-rw-r--r--. 1 oracle oinstall    1190 May 24 21:12 initora11g.ora

-rw-r-----. 1 oracle oinstall      24 Apr  1 12:39 lkORA11G

-rw-r-----. 1 oracle oinstall    1536 Apr  1 12:45 orapwora11g

-rw-r-----. 1 oracle oinstall 9748480 May 24 20:47 snapcf_ora11g.f

-rw-r-----. 1 oracle oinstall    3584 May 24 21:13 spfileora11g.ora

 

對引數檔案進行修改,並且改名,作為新例項ora11gsypfile啟動檔案。

 

[oracle@SimpleLinux dbs]$ cat initora11g.ora

*.audit_file_dest='/u01/app/admin/ora11gsy/adump'

*.audit_trail='db'

*.compatible='11.2.0.4.0'

*.db_block_size=8192

*.db_create_file_dest='/u01/app/oradata'

*.db_domain=''

*.db_file_name_convert='ORA11G','ORA11GSY'

*.db_name='ora11g'

*.db_recovery_file_dest='/u01/app/fast_recovery_area'

*.db_recovery_file_dest_size=10485760000

*.diagnostic_dest='/u01/app'

*.dispatchers='(PROTOCOL=TCP) (SERVICE=ora11gsyXDB)'

*.log_archive_dest_2='SERVICE=ora11gsy valid_for=(online_logfiles,primary_role) db_unique_name=ora11gsy'

*.log_file_name_convert='ORA11G','ORA11GSY'

*.memory_target=373293056

*.open_cursors=300

*.processes=150

*.remote_login_passwordfile='EXCLUSIVE'

*.standby_file_management='AUTO'

*.undo_tablespace='UNDOTBS1'

db_unique_name='ora11gsy'

instance_name='ora11gsy'

 

[oracle@SimpleLinux dbs]$ cp initora11g.ora initora11gsy.ora

 

建立dump目錄。

 

--必須建立,否則會在啟動例項中報錯。

[root@SimpleLinux ~]# mkdir -p /u01/app/admin/ora11gsy/adump

[root@SimpleLinux ~]# chown -R oracle:oinstall /u01


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

相關文章