DG搭建方式区分

DG搭建三种方式:

一、异机恢复,restore database,recover database

二、 duplicate target database for standby from active database;

三、 duplicate target database for standby

区别:

对主库的影响:

异机恢复,使用主库传输过来的备份,手工搭建物理DG,影响最小,安全系数最高,三种方式对比操作复杂   --手动挡

duplicate from active database 使用主库在线backup as copy 在线对主库数据文件进行操作系统拷贝备份,影响最大,安全系数最低,操作最简单  --自动驾驶

duplicate  fro standby 使用主库传输的备份进行恢复,与异机恢复在于,当主备文件路径不同时,可以使用参数,自动转换,而异机恢复 RMAN SET指定  ,影响也小,安全--半自动

#根据恢复应用及参数调整做出说明:

一、异机恢复方式:

1.1控制文件

#主库备份控制文件

RMAN> backup format ‘/u01/app/rman/control%U‘ current controlfile for standby;

#备库restore控制文件,从备份片中还原

RMAN> restore standby controlfile from ‘/picclife/app/rman/control1rsvlvau_1_1‘;

1.2日志文件目录修改 命令 ,执行修改--备库Mount状态下

# set linesize 200

set heading off

set feedback off

spool /home/oracle/rename.sql

select ‘alter database rename file ‘‘‘||member||‘‘‘ to ‘||‘‘‘/picclife/app/oracle/oradata/ENV/‘||substr(member,instr(member,‘/‘,‘-1‘)+1)||‘‘‘‘||‘;‘ from v$logfile;

spool off

1.3数据文件修改路径--两种情况:

date_file_1可以在数据库Mount状态直接alter database rename修改成功

data_file_2 rename不成功,,在RMANrestore 还原数据文件,set指定路径

1.3.1 data_file_1=>

#执行,输出修改sql,执行操作

select ‘alter database rename file ‘‘‘||name||‘‘‘ to  ‘||‘‘‘/picclife/app/oracle/oradata/ENV/‘||substr(name,instr(name,‘/‘,‘-1‘)+1)||‘‘‘‘ ||‘;‘ from v$datafile;

1.3.2data_file_2=>

#如果上述操作:数据文件无法rename,则执行如下命令:输出SQL,不执行

>spool /home/oracle/newname.sql

select ‘set newname for datafile ‘||file#||‘ to "/picclife/app/oracle/oradata/ENV/‘||substr(name,instr(name,‘/‘,‘-1‘)+1)||‘";‘ from v$datafile;

1.4 restore搭建备库

#可以使用RMAN中的newname,临时性:将restore还原的路径,修改为指定

#  switch datafile all;      ---永久性的,直接修改控制文件中记录的数据文件目录

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 "/picclife/app/oracle/oradata/ENV/system01.dbf";

set newname for datafile 2 to "/picclife/app/oracle/oradata/ENV/sysaux01.dbf";

set newname for datafile 3 to "/picclife/app/oracle/oradata/ENV/undotbs01.dbf";

set newname for datafile 4 to "/picclife/app/oracle/oradata/ENV/users01.dbf";

set newname for datafile 5 to "/picclife/app/oracle/oradata/ENV/example01.dbf";

set newname for datafile 6 to "/picclife/app/oracle/oradata/ENV/test1";

set newname for datafile 7 to "/picclife/app/oracle/oradata/ENV/lin_tbs";

set newname for datafile 8 to "/picclife/app/oracle/oradata/ENV/undo_tb12.dbf";

set newname for datafile 9 to "/picclife/app/oracle/oradata/ENV/sink_tbs";

set newname for datafile 10 to "/picclife/app/oracle/oradata/ENV/index01.dbf";

set newname for datafile 11 to "/picclife/app/oracle/oradata/ENV/lmtbsb01.dbf";

set newname for datafile 12 to "/picclife/app/oracle/oradata/ENV/lmtbsb02.dbf";

set newname for datafile 13 to "/picclife/app/oracle/oradata/ENV/lmtbsb03.dbf";

set newname for datafile 14 to "/picclife/app/oracle/oradata/ENV/lmtbsb04.dbf";

set newname for datafile 15 to "/picclife/app/oracle/oradata/ENV/sm_a.dbf";

set newname for datafile 16 to "/picclife/app/oracle/oradata/ENV/bigts.big";

set newname for datafile 17 to "/picclife/app/oracle/oradata/ENV/rm_a.dbf";

set newname for datafile 18 to "/picclife/app/oracle/oradata/ENV/lmt.dbf";

set newname for datafile 19 to "/picclife/app/oracle/oradata/ENV/undo_tb14.db";

set newname for datafile 20 to "/picclife/app/oracle/oradata/ENV/compress.dbf";

set newname for datafile 21 to "/picclife/app/oracle/oradata/ENV/compressb.dbf";

set newname for datafile 22 to "/picclife/app/oracle/oradata/ENV/compressc.dbf";

set newname for datafile 23 to "/picclife/app/oracle/oradata/ENV/tbs_01.dbf";

set newname for datafile 24 to "/picclife/app/oracle/oradata/ENV/tbs_02.dbf";

set newname for datafile 25 to "/picclife/app/oracle/oradata/ENV/ceshi.dbf";

restore database;

switch datafile all;

release channel c4;

release channel c3;

release channel c2;

release channel c1;

}

二、使用RMAN,backup as copy操作更简单,但是对主库可能有影响,无需主库备份,无需人工操作:

2.1备库参数设置:

#主备直接,路径转换参数:前主库文件路径,后备库文件路径

db_file_name_convert

/u01/app/oracle/oradata/ENMO/,/picclife/app/oracle/oradata/dage/

log_file_name_convert

/u01/app/oracle/oradata/ENMO/,/picclife/app/oracle/oradata/dage/

2.2直接在主库begin backup表空间,as copy tablespace传输至备库,end backup

duplicate target database for standby from active database;

2.3RMAN日志截取:

#操作系统密码文件自动拷贝

contents of Memory Script:
{   backup as copy reuse
   targetfile  ‘/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwENMO‘ auxiliary format
 ‘/picclife/app/oracle/product/11.2.0/dbhome_1/dbs/orapwdage‘   ;}

#控制文件自动拷贝standby 至备库参数文件指定的控制文件名称及路径

contents of Memory Script:
{ backup as copy current controlfile for standby auxiliary format  ‘/picclife/app/oracle/oradata/dage/control01.ctl‘;}

#生成控制文件启动脚本,执行将备库启动到Mount状态

contents of Memory Script:
{ sql clone ‘alter database mount standby database‘;}
executing Memory Script

sql statement: alter database mount standby database

#根据参数文件db_file_name_convent参数指定转换,set newname指定新的路径

contents of Memory Script:
   set newname for tempfile  1 to
 "/picclife/app/oracle/oradata/dage/temp001.dbf";
   switch clone tempfile all;
   set newname for datafile  1 to
 "/picclife/app/oracle/oradata/dage/system01.dbf";
   set newname for datafile  2 to
 "/picclife/app/oracle/oradata/dage/sysaux01.dbf";
   set newname for datafile  3 to
 "/picclife/app/oracle/oradata/dage/undotbs01.dbf";
   set newname for datafile  4 to
 "/picclife/app/oracle/oradata/dage/users01.dbf";
   set newname for datafile  5 to
 "/picclife/app/oracle/oradata/dage/example01.dbf";

#对主库数据文件进行Backup as copy 操作系统拷贝备份,传输至备库指定路径
   backup as copy reuse
   datafile  1 auxiliary format
 "/picclife/app/oracle/oradata/dage/system01.dbf"   datafile
 2 auxiliary format
 "/picclife/app/oracle/oradata/dage/sysaux01.dbf"   datafile
 3 auxiliary format
 "/picclife/app/oracle/oradata/dage/undotbs01.dbf"   datafile
 4 auxiliary format
 "/picclife/app/oracle/oradata/dage/users01.dbf"   datafile
 5 auxiliary format
 "/picclife/app/oracle/oradata/dage/example01.dbf"   ;
   sql ‘alter system archive log current‘;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /picclife/app/oracle/oradata/dage/temp001.dbf in control file

executing command: SET NEWNAME

#省略部分日志,重复

executing command: SET NEWNAME

Starting backup at 15-JAN-18
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/ENMO/undotbs01.dbf
output file name=/picclife/app/oracle/oradata/dage/undotbs01.dbf tag=TAG20180408T020947
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:46

#省略部分日志,重复

sql statement: alter system archive log current

#执行修改控制文件中数据文件的路径:提交修改

contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=965518459 file name=/picclife/app/oracle/oradata/dage/system01.dbf
datafile 2 switched to datafile copy

#省略部分日志,重复

三、使用RMAN,restore backup 使用备份集搭建物理DG,对主库影响小:

3.1主库全备

run{ sql ‘alter system archive log current‘;
backup database format ‘/tmp/full/full_back_%U.bak‘;
backup format ‘/tmp/full/arch_%U.log‘ archivelog all delete input;
backup current controlfile for standby format=‘/tmp/full/contr_standby%U‘;}

3.2直接执行duplicate target database for standby报错:需要将主库的备份,传输至备库

#主库备份:且备份文件,备库能读取

$ scp full/* [email protected]:/tmp/full

#修改权限:

# chown oracle.oinstall *

#再次执行 OK

$ rman target sys/[email protected] auxiliary sys/[email protected]

duplicate target database for standby;

3.3日志

#使用备份的standby 控制文件
{restore clone standby controlfile;}
#从备份文件中提取备份信息

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 /tmp/full/contr_standby2osvpprb_1_1
channel ORA_AUX_DISK_1: piece handle=/tmp/full/contr_standby2osvpprb_1_1 tag=TAG20180408T031347
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output file name=/picclife/app/oracle/oradata/dage/control01.ctl
Finished restore at 16-JAN-18

#启动到mount状态
{  sql clone ‘alter database mount standby database‘;}
executing Memory Script

sql statement: alter database mount standby database

#根据参数文件,自动set newname restore还原目录

contents of Memory Script:
{
   set newname for tempfile  1 to
 "/picclife/app/oracle/oradata/dage/temp001.dbf";
   switch clone tempfile all;
   set newname for datafile  1 to
 "/picclife/app/oracle/oradata/dage/system01.dbf";
   set newname for datafile  2 to
 "/picclife/app/oracle/oradata/dage/sysaux01.dbf";
   set newname for datafile  3 to
 "/picclife/app/oracle/oradata/dage/undotbs01.dbf";
   set newname for datafile  4 to
 "/picclife/app/oracle/oradata/dage/users01.dbf";
   set newname for datafile  5 to
 "/picclife/app/oracle/oradata/dage/example01.dbf";
   restore
   clone database
   ;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /picclife/app/oracle/oradata/dage/temp001.dbf in control file

executing command: SET NEWNAME

#执行restore还原操作:从备份集中获取数据!!!

executing command: SET NEWNAME

Starting restore at 16-JAN-18
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 /picclife/app/oracle/oradata/dage/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /picclife/app/oracle/oradata/dage/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /picclife/app/oracle/oradata/dage/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /picclife/app/oracle/oradata/dage/users01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /picclife/app/oracle/oradata/dage/example01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /tmp/full/full_back_2lsvppp2_1_1.bak

#确认修改控制文件记录的数据文件目录及名称

contents of Memory Script:
{  switch clone datafile all;}
executing Memory Script

#还原操作完成

datafile 1 switched to datafile copy
input datafile copy RECID=2 STAMP=965685533 file name=/picclife/app/oracle/oradata/dage/system01.dbf
datafile 2 switched to datafile copy

*格式恶心。。。

原文地址:https://www.cnblogs.com/lvcha001/p/9081600.html

时间: 2024-10-16 14:48:40

DG搭建方式区分的相关文章

linux下oracle11G DG搭建(二):围绕主库搭建操作

环境 名称 主库 备库 主机名 bjsrv shsrv 软件版本 RedHat Enterprise5.5.Oracle 11g 11.2.0.1 RedHat Enterprise5.5.Oracle 11g 11.2.0.1 二.围绕主库操作: 1.主库-修改初始化参数 SQL> show parameter spfile; NAME                 TYPE        VALUE ------------------------------------ --------

linux下oracle11G DG搭建(四):后续验证操作

环境 名称 主库 备库 主机名 bjsrv shsrv 软件版本 RedHat Enterprise5.5.Oracle 11g 11.2.0.1 RedHat Enterprise5.5.Oracle 11g 11.2.0.1 主库下 $ tail -f /u01/app/oracle/diag/rdbms/bjdb/TestDB12/trace/alert_TestDB12.log 对于DG,一定要打开告警日志. 备库下 $ tail -f/u01/app/oracle/diag/rdbms

linux下oracle11G DG搭建(三):围绕备库搭建操作

环境 名称 主库 备库 主机名 bjsrv shsrv 软件版本 RedHat Enterprise5.5.Oracle 11g 11.2.0.1 RedHat Enterprise5.5.Oracle 11g 11.2.0.1 三.围绕备库操作: 1.备库-修改初始化参数文件 $cd$ORACLE_HOME/dbs $df -h $vi initshdb.ora 修改简要说明: *.audit_file_dest='/u01/app/oracle/admin/sh/adump' //审计文件存

linux下oracle11G DG搭建(一):环境准备

linux下oracle11G  DG搭建(一):环境准备 环境 名称 主库 备库 主机名 bjsrv shsrv 软件版本 RedHat Enterprise5.5.Oracle 11g 11.2.0.1 RedHat Enterprise5.5.Oracle 11g 11.2.0.1 一.环境准备: 1.vbox 导入虚拟机镜像(已安装oracle.已建库) 1.导入虚拟机(主库-北京,以下简称bj) 2.导入虚拟机(备库-上海,以下简称sh) 3.主库.备库分别添加一块磁盘 为主库和备库分

linux下oracle11G DG搭建(四):兴许验证操作

环境 名称 主库 备库 主机名 bjsrv shsrv 软件版本号 RedHat Enterprise5.5.Oracle 11g 11.2.0.1 RedHat Enterprise5.5.Oracle 11g 11.2.0.1 主库下 $ tail -f /u01/app/oracle/diag/rdbms/bjdb/TestDB12/trace/alert_TestDB12.log 对于DG.一定要打开告警日志. 备库下 $ tail -f/u01/app/oracle/diag/rdbm

kubernetes (K8S) 集群的搭建方式

kubernetes (K8S) 集群的搭建方式有两种: 守护进程模式和容器模式 (请注意看图,不一样的) 容器的编排管理工具,当然推荐使用容器来部署了.不过容器镜像是在 Google 云上的,需要各位各显神通了. container部署: systemd模式部署: 原文地址:https://www.cnblogs.com/liuxgcn/p/11154259.html

oracle DG搭建

Oracle DG 搭建1. 环境 OS IP hostname db_name DB_UNIQUE_NAME主库 RHEL 5.4 192.168.12.20 edgzrip1.oracle.com PROD1 PROD1备库 RHEL 5.4 192.168.12.30 edgzrip2.oracle.com PROD1 DG 2. 设置主库开启归档SQL> alter database archivelog;Database altered.3. 设置主库开启强制记录日志SQL> alt

DG搭建内容和步骤

DATA guard 搭建内容 主库通过网络把日志文件传输到副库 实现原理:主库是好的,副库安装数据库软件 oracle软件目录 /u01/app/oraI 查看环境变量 env|grep ORACLE ps -ef|grep smon v$database 反应的是控制文件信息 搭建DG必须开归档模式 开启快速恢复区: 默认路径db_recovery_file_dest           /u01/app/oracle/fast_recovery_area 大小      db_recove

Oracle11g RAC+DG搭建

项目环境准备 3.1虚拟机配置 版本选择 注意Linux操作系统.此次项目我选择的版本是Oracle Enterprise Linux 5.4 内存的设置 本人电脑物理内存8G,由于此次实验要开三台虚拟机,基于集群两台机需要的内存较大,故每台给2G,单实例做standby的给1.5G. 添加选择网卡类型 使用桥接方式容易引发IP冲突,所以我选择的是Host Only方式,避免IP冲突. 两个网卡使用分配: NAT:作Public IP Host Only:作Private IP 注意主机和虚拟机