利用RMAN备份集手动建立Dataguard备库

利用RMAN备份集手动建立Dataguard备库

之前的帖子使用的都是duplicate在线传输方式搭建备库,现已通过实验验证可以通过手动的方式建立ADG备库。

1、主库全备

run
{
backup database format '/u01/rman/fulldb_%d_%U.bak' tag 'full_db';
backup archivelog all format '/u01/rman/fullarch_%d_%U.bak' tag 'full_arch';
backup current controlfile format '/u01/rman/control_%U_.bak' tag 'full_control';
}

2、在主库创建standby 控制文件

SQL> alter database create standby controlfile as '/u01/rman/control01.ctl';

3、主库的RMAN备份传送到备库

[oracle@pri ~]$ scp /u01/rman/*.bak  oracle@std:/u01/rman

[oracle@pri ~]$ scp /u01/rman/control01.ctl oracle@std:/u01/rman

4、备库创建对应的pfile

[oracle@std dbs]$ cat initorcl.ora 
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='NONE'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/oradata/orcl/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.db_unique_name='std'
*.diagnostic_dest='/u01/app/oracle'
*.log_archive_format='%t_%s_%r.arc'
*.open_cursors=300
*.pga_aggregate_target=300m
*.processes=1000
*.remote_login_passwordfile='exclusive'
*.sga_target=700m
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(std,orcl)'
*.LOG_ARCHIVE_DEST_1='LOCATION=/u01/arch/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=std'
*.LOG_ARCHIVE_DEST_2='SERVICE=orcl LGWR ASYNC  VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl'
*.log_archive_format='%t_%s_%r.arc'
*.FAL_SERVER='orcl'
*.fal_client='std'
*.DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/std/orcl/'
*.LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/std/orcl/'
*.standby_file_management=AUTO

5、启动到nomount注册rman备份目录

startup nomount;
RMAN> restore controlfile from '/u01/rman/control_0gtmlnai_1_1_.bak';

Starting restore at 2019/01/06 17:41:38
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/orcl/control01.ctl
output file name=/u01/app/oracle/oradata/orcl/control02.ctl
Finished restore at 2019/01/06 17:41:45

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN> catalog start with '/u01/rman';

searching for all files that match the pattern /u01/rman

List of Files Unknown to the Database
=====================================
File Name: /u01/rman/control_0gtmlnai_1_1_.bak

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

List of Cataloged Files
=======================
File Name: /u01/rman/control_0gtmlnai_1_1_.bak

6、还原数据文件到备库(指向相对应目录)
查询主库数据文件路径


SQL> select
  2  'set newname for datafile ' || file# || ' to ' || '''' || name || '''' || ';'
  3  from v$datafile;

'SETNEWNAMEFORDATAFILE'||FILE#||'TO'||''''||NAME||''''||';'
--------------------------------------------------------------------------------
set newname for datafile 1 to '/u01/app/oracle/oradata/orcl/system01.dbf';
set newname for datafile 2 to '/u01/app/oracle/oradata/orcl/sysaux01.dbf';
set newname for datafile 3 to '/u01/app/oracle/oradata/orcl/undotbs01.dbf';
set newname for datafile 4 to '/u01/app/oracle/oradata/orcl/users01.dbf';
set newname for datafile 5 to '/u01/app/oracle/oradata/orcl/admin.dbf';
run
{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
set newname for datafile 1 to '/u01/app/oracle/oradata/std/orcl/system01.dbf';
set newname for datafile 2 to '/u01/app/oracle/oradata/std/orcl/sysaux01.dbf';
set newname for datafile 3 to '/u01/app/oracle/oradata/std/orcl/undotbs01.dbf';
set newname for datafile 4 to '/u01/app/oracle/oradata/std/orcl/users01.dbf';
set newname for datafile 5 to '/u01/app/oracle/oradata/std/orcl/admin.dbf';
restore database;
switch datafile all;
release channel c1;
release channel c2;
release channel c3;
}

输出过程:

using target database control file instead of recovery catalog
allocated channel: c1
channel c1: SID=16 device type=DISK

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

allocated channel: c3
channel c3: SID=21 device type=DISK

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 2019/01/06 18:16:48

channel c1: starting datafile backup set restore
channel c1: specifying datafile(s) to restore from backup set
channel c1: restoring datafile 00001 to /u01/app/oracle/oradata/std/orcl/system01.dbf
channel c1: restoring datafile 00002 to /u01/app/oracle/oradata/std/orcl/sysaux01.dbf
channel c1: restoring datafile 00003 to /u01/app/oracle/oradata/std/orcl/undotbs01.dbf
channel c1: restoring datafile 00004 to /u01/app/oracle/oradata/std/orcl/users01.dbf
channel c1: restoring datafile 00005 to /u01/app/oracle/oradata/std/orcl/admin.dbf
channel c1: reading from backup piece /u01/rman/fulldb_ORCL_0dtmln3a_1_1.bak
channel c1: piece handle=/u01/rman/fulldb_ORCL_0dtmln3a_1_1.bak tag=FULL_DB
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:01:36
Finished restore at 2019/01/06 18:18:24

datafile 1 switched to datafile copy
input datafile copy RECID=8 STAMP=996862706 file name=/u01/app/oracle/oradata/std/orcl/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=9 STAMP=996862706 file name=/u01/app/oracle/oradata/std/orcl/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=10 STAMP=996862706 file name=/u01/app/oracle/oradata/std/orcl/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=11 STAMP=996862706 file name=/u01/app/oracle/oradata/std/orcl/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=12 STAMP=996862706 file name=/u01/app/oracle/oradata/std/orcl/admin.dbf

released channel: c1

released channel: c2

released channel: c3

7、使用standby控制文件替换原数据文件

RMAN> shutdown immediate;
[oracle@std orcl]$ cp /u01/rman/control01.ctl .
[oracle@std orcl]$ ll
total 9808
-rw-r----- 1 oracle oinstall 10043392 Jan  6 18:24 control01.ctl
[oracle@std orcl]$ cp control01.ctl control02.ctl 

8、打开备库的日志应用(开启MRP)

SQL> startup mount;

SQL> alter database recover managed standby database using current logfile disconnect; 

Database altered.

SQL> !ps -ef|grep mrp
oracle     4505      1  2 18:28 ?        00:00:00 ora_mrp0_orcl
oracle     4512   4433  0 18:28 pts/5    00:00:00 /bin/bash -c ps -ef|grep mrp
oracle     4514   4512  0 18:28 pts/5    00:00:00 grep mrp

观察MRP以及RFS进程
SQL> SELECT  PROCESS, STATUS,THREAD#,SEQUENCE#,BLOCK#,BLOCKS, DELAY_MINS FROM V$MANAGED_STANDBY;

PROCESS                     STATUS                                  THREAD#
--------------------------- ------------------------------------ ----------
 SEQUENCE#     BLOCK#     BLOCKS DELAY_MINS
---------- ---------- ---------- ----------
ARCH                        CONNECTED                                     0
         0          0          0          0

ARCH                        CLOSING                                       1
        99      26624       1186          0

ARCH                        CONNECTED                                     0
         0          0          0          0


PROCESS                     STATUS                                  THREAD#
--------------------------- ------------------------------------ ----------
 SEQUENCE#     BLOCK#     BLOCKS DELAY_MINS
---------- ---------- ---------- ----------
ARCH                        CONNECTED                                     0
         0          0          0          0

RFS                         IDLE                                          0
         0          0          0          0

RFS                         IDLE                                          1
       100        275          1          0


PROCESS                     STATUS                                  THREAD#
--------------------------- ------------------------------------ ----------
 SEQUENCE#     BLOCK#     BLOCKS DELAY_MINS
---------- ---------- ---------- ----------
RFS                         IDLE                                          0
         0          0          0          0

MRP0                        APPLYING_LOG                                  1
        99      19897      27809          0

RFS                         IDLE                                          0
         0          0          0          0


9 rows selected.

9、打开备库到open状态

SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-10456: cannot open standby database; media recovery session may be in
progress


SQL> alter database recover managed standby database cancel;

Database altered.

SQL> alter database open;

Database altered.

SQL> alter database recover managed standby database using current logfile disconnect;

Database altered.

10、检查备库日志以及应用情况

SQL> select thread#,sequence#,first_time,next_time,applied from v$archived_log where applied='NO';

no rows selected

SQL> SELECT  PROCESS, STATUS,THREAD#,SEQUENCE#,BLOCK#,BLOCKS, DELAY_MINS FROM V$MANAGED_STANDBY;

PROCESS                     STATUS                                  THREAD#
--------------------------- ------------------------------------ ----------
 SEQUENCE#     BLOCK#     BLOCKS DELAY_MINS
---------- ---------- ---------- ----------
ARCH                        CONNECTED                                     0
         0          0          0          0

ARCH                        CLOSING                                       1
        99      26624       1186          0

ARCH                        CONNECTED                                     0
         0          0          0          0


PROCESS                     STATUS                                  THREAD#
--------------------------- ------------------------------------ ----------
 SEQUENCE#     BLOCK#     BLOCKS DELAY_MINS
---------- ---------- ---------- ----------
ARCH                        CONNECTED                                     0
         0          0          0          0

RFS                         IDLE                                          0
         0          0          0          0

RFS                         IDLE                                          1
       100        396          1          0


PROCESS                     STATUS                                  THREAD#
--------------------------- ------------------------------------ ----------
 SEQUENCE#     BLOCK#     BLOCKS DELAY_MINS
---------- ---------- ---------- ----------
RFS                         IDLE                                          0
         0          0          0          0

MRP0                        APPLYING_LOG                                  1
       100        396     102400          0

RFS                         IDLE                                          0
         0          0          0          0
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值