通过RMAN备份搭建单节点ADG(oracle11g)

1、修改/etc/hosts  建议:生产端和DG端保持一致

生产端:

[root@primary ~]# more /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

 

192.168.186.87 primary

192.168.186.88 standby

DG端:

[root@standby ~]# more /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

 

192.168.186.88 standby

192.168.186.87 primary

2、修改数据库为归档日志模式、强制日志模式

[oracle@primary ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Tue Aug 4 22:15:54 2015

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

Connected to an idle instance.

SQL> startup mount;

ORACLE instance started.

Total System Global Area  409194496 bytes

Fixed Size                  2228864 bytes

Variable Size             276827520 bytes

Database Buffers          125829120 bytes

Redo Buffers                4308992 bytes

Database mounted.

SQL> archive log list

Database log mode              No Archive Mode

Automatic archival             Disabled

Archive destination            /u01/app/base/product/11.2.0/db_1/dbs/arch

Oldest online log sequence     4

Current log sequence           6

SQL> alter database archivelog;

Database altered.

SQL> select force_logging from v$database;

FOR

---

NO

SQL> alter database force logging;

Database altered.

3在生产端修改参数文件

SQL> alter system set log_archive_dest_1 = 'LOCATION=/archive/orcl' scope=both;

System altered.

SQL> alter system set log_archive_dest_2 = 'SERVICE=standby arch ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl' scope=both;

System altered.

SQL> alter system set log_archive_dest_state_1 = ENABLE scope=both;

System altered.

SQL> alter system set log_archive_dest_state_2 = ENABLE scope=both;

System altered.

SQL> alter system set db_file_name_convert = '/oradata/orcl/ ','/oradata/orcl_standby ' scope = spfile;

System altered.

SQL> alter system set log_file_name_convert = '/oradata/orcl/ ','/oradata/orcl_standby ' scope = spfile;

System altered.

4配置生产端和DG端网络服务名tnsnames.ora 建议:保持一致 验证:tnsping

生产端:

[oracle@primary admin]$ more tnsnames.ora

# tnsnames.ora Network Configuration File: /u01/app/base/product/11.2.0/db_1/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.

 

STANDBY =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = standby)(PORT = 1521))

    )

    (CONNECT_DATA =

      (SERVICE_NAME = orcl)

    )

  )

 

ORCL =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = primary)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = orcl)

    )

  )

DG端:

[oracle@standby admin]$ more tnsnames.ora

# tnsnames.ora Network Configuration File: /u01/app/base/product/11.2.0/db_1/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.

 

STANDBY =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = standby)(PORT = 1521))

    )

    (CONNECT_DATA =

      (SERVICE_NAME = orcl)

    )

  )

 

ORCL =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = primary)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = orcl)

    )

  )

Tnsping service_names验证

5、将生产端$ORACLE_HOME/dbs/下的密码文件orapwORACLE_SID传至备机,可以用ssh/ftp

orapwd file=orapworcl password=oracle(建议拷贝,不然报ORA-16191)

6、创建生产端的pfile并传至DG

生产端:

[oracle@primary ~]$ scp initorcl.ora [email protected]:/u01/app/base/product/11.2.0/db_1/dbs

[email protected]'s password:

initorcl.ora                                                                                                                      100%  769     0.8KB/s   00:00

 

DG端:

[oracle@standby dbs]$ ls -rlt

total 8

-rw-r-----. 1 oracle oinstall 1536 Aug  4 23:53 orapworcl

-rw-r--r--. 1 oracle oinstall  769 Aug  4 23:55 initorcl.ora

7、创建standby控制文件、数据文件、归档日志,并传至DG端的相同路径下

[oracle@primary ~]$ rman target /

 

Recovery Manager: Release 11.2.0.3.0 - Production on Tue Aug 4 23:26:09 2015

 

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

 

connected to target database: ORCL (DBID=1414669689)

 

RMAN> backup database format '/home/oracle/temp/%U';

 

Starting backup at 04-AUG-15

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=37 device type=DISK

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00001 name=/oradata/orcl/system01.dbf

input datafile file number=00002 name=/oradata/orcl/sysaux01.dbf

input datafile file number=00005 name=/oradata/orcl/example01.dbf

input datafile file number=00003 name=/oradata/orcl/undotbs01.dbf

input datafile file number=00004 name=/oradata/orcl/users01.dbf

channel ORA_DISK_1: starting piece 1 at 04-AUG-15

channel ORA_DISK_1: finished piece 1 at 04-AUG-15

piece handle=/home/oracle/temp/02qdpreh_1_1 tag=TAG20150804T232713 comment=NONE

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

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

including current control file in backup set

including current SPFILE in backup set

channel ORA_DISK_1: starting piece 1 at 04-AUG-15

channel ORA_DISK_1: finished piece 1 at 04-AUG-15

piece handle=/home/oracle/temp/03qdprgt_1_1 tag=TAG20150804T232713 comment=NONE

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

Finished backup at 04-AUG-15

 

RMAN> backup archivelog all format '/home/oracle/temp/%U';

 

Starting backup at 04-AUG-15

current log archived

using channel ORA_DISK_1

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=6 RECID=1 STAMP=886894834

input archived log thread=1 sequence=7 RECID=2 STAMP=886894835

input archived log thread=1 sequence=8 RECID=3 STAMP=886894838

input archived log thread=1 sequence=9 RECID=4 STAMP=886894846

input archived log thread=1 sequence=10 RECID=5 STAMP=886894847

input archived log thread=1 sequence=11 RECID=6 STAMP=886894848

input archived log thread=1 sequence=12 RECID=7 STAMP=886894849

input archived log thread=1 sequence=13 RECID=8 STAMP=886894947

channel ORA_DISK_1: starting piece 1 at 04-AUG-15

channel ORA_DISK_1: finished piece 1 at 04-AUG-15

piece handle=/home/oracle/temp/04qdpsb3_1_1 tag=TAG20150804T234227 comment=NONE

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

Finished backup at 04-AUG-15

 

RMAN> backup current controlfile for standby format '/home/oracle/temp/%U';

 

Starting backup at 04-AUG-15

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 04-AUG-15

channel ORA_DISK_1: finished piece 1 at 04-AUG-15

piece handle=/home/oracle/temp/05qdpsdq_1_1 tag=TAG20150804T234354 comment=NONE

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

Finished backup at 04-AUG-15

 

RMAN>

 

[oracle@primary temp]$ scp * [email protected]:/home/oracle/temp/

[email protected]'s password:

02qdpreh_1_1                                                                                                                      100% 1156MB  32.1MB/s   00:36   

03qdprgt_1_1                                                                                                                      100% 9600KB   9.4MB/s   00:01   

04qdpsb3_1_1                                                                                                                      100% 4332KB   4.2MB/s   00:00   

05qdpsdq_1_1                                                                                                                      100% 9568KB   9.3MB/s   00:00   

 

[oracle@standby temp]$ ls -rlt

total 1207040

-rw-r-----. 1 oracle oinstall 1211940864 Aug  5 00:22 02qdpreh_1_1

-rw-r-----. 1 oracle oinstall    9830400 Aug  5 00:22 03qdprgt_1_1

-rw-r-----. 1 oracle oinstall    4435968 Aug  5 00:22 04qdpsb3_1_1

-rw-r-----. 1 oracle oinstall    9797632 Aug  5 00:22 05qdpsdq_1_1

8、在DG端修改pfile,并启动实例到NOMOUNT状态

[oracle@standby dbs]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.3.0 Production on Wed Aug 5 16:56:13 2015

 

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

 

Connected to an idle instance.

 

SQL> startup nomount;

ORACLE instance started.

 

Total System Global Area  242208768 bytes

Fixed Size                  2227176 bytes

Variable Size             184550424 bytes

Database Buffers           50331648 bytes

Redo Buffers                5099520 bytes

SQL> create spfile from pfile;

 

File created.

 

SQL> startup nomount force;

ORACLE instance started.

 

Total System Global Area  242208768 bytes

Fixed Size                  2227176 bytes

Variable Size             184550424 bytes

Database Buffers           50331648 bytes

Redo Buffers                5099520 bytes

SQL> exit

9、在DG端,通过RMAN连接到生产库和auxiliary数据库,结束后备库自动启到MOUNT状态

[oracle@standby dbs]$ rman target sys/oracle@orcl auxiliary sys/oracle

 

Recovery Manager: Release 11.2.0.3.0 - Production on Wed Aug 5 16:57:14 2015

 

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

 

connected to target database: ORCL (DBID=1414669689)

connected to auxiliary database: ORCL (not mounted)

 

RMAN> duplicate target database for standby dorecover;

 

Starting Duplicate Db at 05-AUG-15

using target database control file instead of recovery catalog

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=19 device type=DISK

 

contents of Memory Script:

{

   set until scn  1099341;

   restore clone standby controlfile;

}

executing Memory Script

 

executing command: SET until clause

 

Starting restore at 05-AUG-15

using channel ORA_AUX_DISK_1

 

channel ORA_AUX_DISK_1: starting datafile backup set restore

channel ORA_AUX_DISK_1: restoring control file

channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/temp/03qdprgt_1_1

channel ORA_AUX_DISK_1: piece handle=/home/oracle/temp/03qdprgt_1_1 tag=TAG20150804T232713

channel ORA_AUX_DISK_1: restored backup piece 1

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

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

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

Finished restore at 05-AUG-15

 

contents of Memory Script:

{

   sql clone 'alter database mount standby database';

}

executing Memory Script

 

sql statement: alter database mount standby database

 

contents of Memory Script:

{

   set until scn  1099341;

   set newname for tempfile  1 to

 "/oradata/standby/temp01.dbf";

   switch clone tempfile all;

   set newname for datafile  1 to

 "/oradata/standby/system01.dbf";

   set newname for datafile  2 to

 "/oradata/standby/sysaux01.dbf";

   set newname for datafile  3 to

 "/oradata/standby/undotbs01.dbf";

   set newname for datafile  4 to

 "/oradata/standby/users01.dbf";

   set newname for datafile  5 to

 "/oradata/standby/example01.dbf";

   restore

   clone database

   ;

}

executing Memory Script

 

executing command: SET until clause

 

executing command: SET NEWNAME

 

renamed tempfile 1 to /oradata/standby/temp01.dbf in control file

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

Starting restore at 05-AUG-15

using channel ORA_AUX_DISK_1

 

channel ORA_AUX_DISK_1: starting datafile backup set restore

channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set

channel ORA_AUX_DISK_1: restoring datafile 00001 to /oradata/standby/system01.dbf

channel ORA_AUX_DISK_1: restoring datafile 00002 to /oradata/standby/sysaux01.dbf

channel ORA_AUX_DISK_1: restoring datafile 00003 to /oradata/standby/undotbs01.dbf

channel ORA_AUX_DISK_1: restoring datafile 00004 to /oradata/standby/users01.dbf

channel ORA_AUX_DISK_1: restoring datafile 00005 to /oradata/standby/example01.dbf

channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/temp/02qdpreh_1_1

channel ORA_AUX_DISK_1: piece handle=/home/oracle/temp/02qdpreh_1_1 tag=TAG20150804T232713

channel ORA_AUX_DISK_1: restored backup piece 1

channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:46

Finished restore at 05-AUG-15

 

contents of Memory Script:

{

   switch clone datafile all;

}

executing Memory Script

 

datafile 1 switched to datafile copy

input datafile copy RECID=2 STAMP=886957114 file name=/oradata/standby/system01.dbf

datafile 2 switched to datafile copy

input datafile copy RECID=3 STAMP=886957114 file name=/oradata/standby/sysaux01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=4 STAMP=886957114 file name=/oradata/standby/undotbs01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=5 STAMP=886957114 file name=/oradata/standby/users01.dbf

datafile 5 switched to datafile copy

input datafile copy RECID=6 STAMP=886957114 file name=/oradata/standby/example01.dbf

 

contents of Memory Script:

{

   set until scn  1099341;

   recover

   standby

   clone database

    delete archivelog

   ;

}

executing Memory Script

 

executing command: SET until clause

 

Starting recover at 05-AUG-15

using channel ORA_AUX_DISK_1

 

starting media recovery

 

channel ORA_AUX_DISK_1: starting archived log restore to default destination

channel ORA_AUX_DISK_1: restoring archived log

archived log thread=1 sequence=6

channel ORA_AUX_DISK_1: restoring archived log

archived log thread=1 sequence=7

channel ORA_AUX_DISK_1: restoring archived log

archived log thread=1 sequence=8

channel ORA_AUX_DISK_1: restoring archived log

archived log thread=1 sequence=9

channel ORA_AUX_DISK_1: restoring archived log

archived log thread=1 sequence=10

channel ORA_AUX_DISK_1: restoring archived log

archived log thread=1 sequence=11

channel ORA_AUX_DISK_1: restoring archived log

archived log thread=1 sequence=12

channel ORA_AUX_DISK_1: restoring archived log

archived log thread=1 sequence=13

channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/temp/04qdpsb3_1_1

channel ORA_AUX_DISK_1: piece handle=/home/oracle/temp/04qdpsb3_1_1 tag=TAG20150804T234227

channel ORA_AUX_DISK_1: restored backup piece 1

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

archived log file name=/archive/orcl/1_6_886888956.dbf thread=1 sequence=6

channel clone_default: deleting archived log(s)

archived log file name=/archive/orcl/1_6_886888956.dbf RECID=8 STAMP=886957116

archived log file name=/archive/orcl/1_7_886888956.dbf thread=1 sequence=7

channel clone_default: deleting archived log(s)

archived log file name=/archive/orcl/1_7_886888956.dbf RECID=2 STAMP=886957116

archived log file name=/archive/orcl/1_8_886888956.dbf thread=1 sequence=8

channel clone_default: deleting archived log(s)

archived log file name=/archive/orcl/1_8_886888956.dbf RECID=1 STAMP=886957116

archived log file name=/archive/orcl/1_9_886888956.dbf thread=1 sequence=9

channel clone_default: deleting archived log(s)

archived log file name=/archive/orcl/1_9_886888956.dbf RECID=3 STAMP=886957116

archived log file name=/archive/orcl/1_10_886888956.dbf thread=1 sequence=10

channel clone_default: deleting archived log(s)

archived log file name=/archive/orcl/1_10_886888956.dbf RECID=4 STAMP=886957116

archived log file name=/archive/orcl/1_11_886888956.dbf thread=1 sequence=11

channel clone_default: deleting archived log(s)

archived log file name=/archive/orcl/1_11_886888956.dbf RECID=5 STAMP=886957116

archived log file name=/archive/orcl/1_12_886888956.dbf thread=1 sequence=12

channel clone_default: deleting archived log(s)

archived log file name=/archive/orcl/1_12_886888956.dbf RECID=6 STAMP=886957116

archived log file name=/archive/orcl/1_13_886888956.dbf thread=1 sequence=13

channel clone_default: deleting archived log(s)

archived log file name=/archive/orcl/1_13_886888956.dbf RECID=7 STAMP=886957116

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

Finished recover at 05-AUG-15

Finished Duplicate Db at 05-AUG-15

 

RMAN>

接下来就是检查生产端和DG端归档日志是否同步

Select max(sequence#) from v$archived_log;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30310891/viewspace-1762315/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/30310891/viewspace-1762315/

你可能感兴趣的:(通过RMAN备份搭建单节点ADG(oracle11g))