设为首页收藏本站

Botang唐波's Oracle Station

【脚本共享2015】用PXE方法从裸机批量推Oracle 11gR2 RAC成套环境,并用Shell脚本在推出的RAC节点上批量部署32个Oracle11gR2 RAC备份恢复案例场景的方法

2015-5-9 06:14| 发布者: admin| 查看: 22547| 评论: 0

摘要: 本文前半段介绍:用PXE推送端主机,把原先处于裸机状态的三台一套 PXE被推送端主机批量推成Oracle 11gR2 RAC环境的方法。在每套推出的Oracle 11gR2 RAC环境中,都包含已自动安装并配置好的三台主机:一台共享磁盘主机和两台节点主机。每套推出的Oracle 11gR2 RAC环境中的两台节点主机都已自动挂接上该套环境内部的共享磁盘主机。两台节点主机各配备一个分布式虚拟磁带库,并且做好所有操作系统层面的配置:包括vip、scan-vip、ntp,各种rpm包和操作系统参数等。 本文后半段介绍:如何复用以上的PXE推送端主机作为部署平台,在每套推出的Oracle 11gR2 RAC环境中部署32个Oracle11gR2 RAC备份恢复案例场景脚本。脚本基于网络执行并批量部署;脚本同时支持下载到每一台Oracle11gR2 RAC节点主机本地运行。脚本能模拟和评测每一套环境每一个备份恢复场景的恢复结果。 本文中所提及的所有原创程序均提供下载和md5sum文件。 读者使用这些程序不应出于商业目的,作者对使用这些程序可能带来的一切后果不承担任何法律责任。

Botang唐波


摘要
 

本文前半段介绍:用PXE推送端主机,把原先处于裸机状态的三台一套 PXE被推送端主机批量推成Oracle 11gR2 RAC环境的方法。在每套推出的Oracle 11gR2 RAC环境中,都包含已自动安装并配置好的三台主机:一台共享磁盘主机和两台节点主机。每套推出的Oracle 11gR2 RAC环境中的两台节点主机都已自动挂接上该套环境内部的共享磁盘主机。两台节点主机各配备一个分布式虚拟磁带库,并且做好所有操作系统层面的配置:包括vipscan-vipntp,各种rpm包和操作系统参数等。

本文后半段介绍:如何复用以上的PXE推送端主机作为部署平台,在每套推出的Oracle 11gR2 RAC环境中部署32Oracle11gR2 RAC备份恢复案例场景脚本。脚本基于网络执行并批量部署;脚本同时支持下载到每一台Oracle11gR2 RAC节点主机本地运行。脚本能模拟和评测每一套环境每一个备份恢复场景的恢复结果。

本文中所提及的所有原创程序均提供下载和md5sum文件 读者使用这些程序不应出于商业目的,作者对使用这些程序可能带来的一切后果不承担任何法律责任。



目录
 

1. PXE概览

1.1 PXE概览

1.2 IP地址规划

2. PXE推送端主机的搭建

2.1 PXE推送端主机的搭建

2.2 下载将要用于推送的安装软件

2.3 PXE被推送端主机收集MAC地址

3. PXE被推送端主机:Oracle 11gR2 RAC环境共享磁盘主机

4. PXE被推送端主机:Oracle 11gR2 RAC环境节点主机

4.1共享存储

4.2 分布式虚拟磁带库

4.3 时间同步

4.4 grid用户和 oracle用户

4.5 ssh等价性脚本

4.6 其他

4.7 安装

5. Shell脚本在推出的节点上批量部署32Oracle11gR2 RAC备份恢复案例场景

5.1 备份恢复案例场景模拟脚本工作原理

5.2 PXE推送端主机上安装备份恢复案例场景模拟脚本

5.3 Oracle 11gR2 RAC环境节点主机部署备份恢复案例场景模拟脚本

5.3.1 PXE推送端主机上准备IP地址列表

5.3.2 PXE推送端主机上初始化实验脚本

6. Oracle11gR2 RAC环境“dd”和“rever”,在后续特定实验前通过“rever”初始化环境

7. Oracle11gR2 RAC备份恢复案例一:完全恢复类场景批量模拟以及恢复要点

7.1 1a_users表空间在线损坏

7.2 1b_下线user表空间损坏

7.3 1c_只读user表空间损坏

7.4 1d_users表空间热备

7.5 3_system表空间离线损坏

7.6 4_tbsocp05_test没有备份的表空间损坏

8. Oracle11gR2 RAC备份恢复案例二:不完全恢复类场景批量模拟以及恢复要点

8.1 5_基于时间的不完全恢复

8.2 6a_基于log序列号的不完全恢复

8.3 6b_基于cancel的不完全恢复

8.4 7a_当前控制文件和数据文件完好_日志文件全部损坏_正常关机不完全恢复_数据不丢_不需备份

8.5 7b_当前控制文件和数据文件完好_日志文件全部损坏_不正常关机不完全恢复

8.6 8a_当前控制文件损坏_不完全恢复_用控制文件二进制备份_数据不丢_不需备份

8.7 8b_当前控制文件损坏_完全恢复_用控制文件脚本_不需备份

8.8 9a_当前控制文件损坏_下线user表空间不完全恢复_用控制文件二进制备份_数据不丢_不需备份

8.9 9b_当前控制文件损坏_下线user表空间完全恢复_用控制文件脚本_不需备份

8.10 9c_当前控制文件损坏_只读user表空间不完全恢复_用控制文件二进制备份_数据不丢_不需备份

8.11 9d_当前控制文件损坏_只读user表空间完全恢复_用控制文件脚本_不需备份

8.12 10a_当前控制文件损坏_备份时下线user表空间不完全恢复_用控制文件二进制备份_数据不丢_不需备份

8.13 10b_当前控制文件损坏_备份时下线user表空间完全恢复_用控制文件脚本_不需备份

8.14 10c_当前控制文件损坏_备份时只读user表空间不完全恢复_用控制文件二进制备份_数据不丢_不需备份

8.15 10d_当前控制文件损坏_备份时只读user表空间完全恢复_用控制文件脚本_不需备份

9. Oracle11gR2 RAC备份恢复案例三:进阶不完全恢复类场景批量模拟以及恢复要点

9.1 11a_当前控制文件和日志文件全部损坏_不完全恢复_用控制文件二进制备份

9.2 11b_当前控制文件和日志文件全部损坏_不完全恢复_用控制文件脚本

9.3 12a_当前控制文件和日志文件全部损坏_备份时下线user表空间不完全恢复_用控制文件二进制备份

9.4 12b_当前控制文件和日志文件全部损坏_备份时下线user表空间不完全恢复_用控制文件脚本

9.5 12c_当前控制文件和日志文件全部损坏_备份时只读user表空间不完全恢复_用控制文件二进制备份

9.6 12d_当前控制文件和日志文件全部损坏_备份时只读user表空间不完全恢复_用控制文件脚本

9.7 13a_当前控制文件损坏_新建tbsocp05_test2表空间不完全恢复_用控制文件二进制备份_数据不丢_不需备份

9.8 13b_当前控制文件损坏_新建tbsocp05_test3表空间完全恢复_用控制文件脚本_不需备份

9.9 14_删除表空间不完全恢复

9.10 15_穿越incarnation不完全恢复

总结



正文
 

1. PXE概览

1.1 PXE概览

PXE(Pre-boot Execution Environment)是由Intel设计的协议,它可以使裸机通过网络启动,并被安装上操作系统。协议分为推送端和被推送端两端。

PXE推送端主机是一台协同运行着dhcpdtftpdnfsdnsvsftpdhttpd的标准Linux服务器。

PXE 被推送端程序从网卡的ROM中激活。当计算机引导时,BIOSPXE 被推送端程序调入内存执行,并显示出命令菜单。经用户选择后,PXE 被推送端将放置在PXE 推送端主机的操作系统通过网络下载到本地运行,继而实现kernel启动。启动后PXE被推送端实际上是主动从PXE 推送端主机下载安装程序和安装选项文件,完成后续安装步骤。


1.2 IP地址规划

为了能够把下文叙述清楚,我们设定在192.168.0.0/24网段工作。操作系统分别使用6RHEL5OEL。如果使用其他6Enterprise Linux5Enterprise Linux(如:CentOSRHELOEL,包括它们的32位或64位发行版)步骤大同小异,本文同样适用。


主机

操作系统

外网IP

内网IP

主机名

PXE推送端主机

RedHat Enterprise Linux 6.1 x86_64(或其他6Enterprise Linux5Enterprise Linux

192.168.0.254

server1.example.com

PXE被推送端主机之Oracle 11gR2 RAC环境共享磁盘主机

RedHat Enterprise Linux 6.1(或其他6Enterprise Linux

192.168.0.50+x

x取值范围139)

172.31.118.50+x

x取值范围139)

station50+x.example.com

x取值范围139)

PXE被推送端主机之Oracle 11gR2 RAC环境节点主机(第一台)

Oracle Enterprise Linux 5.4(或其他5Enterprise Linux

IP192.168.0.x

VIP192.168.0.200+x

SCAN-VIP1192.168.0.100+x

SCAN-VIP2192.168.0.150+x

x取值范围139)

172.31.118.x

x取值范围139)

stationx.example.com

x取值范围139)

PXE被推送端主机之Oracle 11gR2 RAC环境节点主机(第二台)

同上

IP192.168.0.1+x

VIP192.168.0.201+x

SCAN-VIP3192.168.0.101+x

x取值范围139)

172.31.118.1+x

x取值范围139)

station1+x.example.com

x取值范围139)


推送时以上IP规划通过PXE推送端主机上的 dhcpd配置文件里的MAC固定配置来实现。以上VIP规划通过PXE推送端主机上的Kickstart配置文件中%post编程来实现。而以上三个SCAN-VIP规划则通过PXE推送端主机的 dns服务器配置文件配合PXE推送端主机上的Kickstart配置文件中%post编程来实现。  

2. PXE推送端主机的搭建

2.1 PXE推送端主机的搭建

如上所述PXE推送端主机是一台协同运行着dhcpdtftpdnfsdnsvsftpdhttpd的标准Linux服务器 。由于本文立足于Oracle技术分享,所以并不打算详细介绍这些服务器的具体配置。 为了方便读者搭建PXE推送端主机,作者编写了一个一步到位的搭建程序bcp-install”

bcp-install”的功能只有一个:帮助你在3分钟之内配置好:一台协同运行着dhcpdtftpdnfsdnsvsftpdhttpd的标准Linux服务器。 此程序实际上是一个shell编程的自解压安装包,因此不论操作系统是32位和64位;也不论是在6Enterprise Linux还是在5Enterprise Linux上都能运行。

运行该搭建程序前,仅仅要求读者自行安装好一台Enterprise Linux 主机。 这台主机只需要配备一块网卡,其IP和主机名应根据1.2 IP地址规划里说明的设置好。安装这台主机过程中除了保证/usr”空间不小于20G/var”空间不小于15G(如果不分区安装,只要保证/”不小于45G)和挑包时装上ftp服务器以外没有特殊要求。为了使脚本bcp-install”能顺利运行成功,需要把安装这台主机操作系统时所用到的整张光盘包含的所有内容,保持完整目录结构直接拷贝至/var/ftp/pub/下。之后运行bcp-install”


[root@server1 ~]# ./bcp-install

...
SHOULD COPY CDROM/DVDROM of LINUX INSTALLATION into /var/ftp/pub:(y/n)


确认把安装这台主机操作系统时所用到的整张光盘包含的所有内容,保持完整目录结构直接拷贝至“/var/ftp/pub/”下,选y继续。

至此PXE推送端主机的搭建便完成了。如果需要了解bcp-install”具体做了哪些配置,请打开此机上的dhcpdtftpdnfsdnsvsftpdhttpd的相应配置文件,辅以Linux相关的知识阅读即可。


2.2 下载将要用于推送的安装软件

推送所需的操作系统 iso镜像和Oracle安装软件是不包含在bcp-install”中的,需要读者自行下载并放置在如下目录(/usr/sbin/botang-config-push.d/”目录已由bcp-install”创建):


所需软件

存放路径

Oracle Enterprise Linux 5.4 iso镜像文件

/usr/sbin/botang-config-push.d/softwarefiles/Lrhel5/IMAGES/issue.iso

RedHat Enterprise Linux 6.1iso 镜像文件

/usr/sbin/botang-config-push.d/softwarefiles/Lrhel6/IMAGES/issue.iso

linux_11gR2_database_1of2.zip

/usr/sbin/botang-config-push.d/softwarefiles/O11g/DATABASES/linux_11gR2_database_1of2.zip

linux_11gR2_database_2of2.zip

/usr/sbin/botang-config-push.d/softwarefiles/O11g/DATABASES/linux_11gR2_database_2of2.zip

linux_11gR2_grid.zip

/usr/sbin/botang-config-push.d/softwarefiles/O11g/DATABASES/linux_11gR2_grid.zip

osb-10.3.0.3.0_linux32.zip

/usr/sbin/botang-config-push.d/softwarefiles/O10g/TAPE/osb-10.3.0.3.0_linux32.zip


2.3 PXE被推送端主机收集MAC地址

推送时,1.2 IP地址规划里的IP规划是通过PXE推送端主机上的 dhcpd配置文件里的MAC固定配置来实现。因此需要编写/etc/dhcpd.conf”/etc/dhcp/dhcpd.conf”配置文件以固定MACIP对应关系。如果读者使用并运行过bcp-install”PXE推送端主机里已安装好一个文本处理工具:“botang-create-dhcpconf”。读者只需要编写/usr/sbin/workstation.list2”/usr/sbin/workstation.list” 两个文件。这两个配置文件前者是PXE被推送端主机两块网卡的MAC地址列表,后者是PXE被推送端主机第一块网卡的MAC地址列表。有了这两个文件后,运行 “botang-create-dhcpconf”程序,“/etc/dhcpd.conf”和“/etc/dhcp/dhcpd.conf”配置文件就创建好了。

举例如下:


文件名

内容

/usr/sbin/workstation.list2

3-00:07:E9:5C:44:1F

3-00:16:EC:06:6C:15

4-00:07:E9:0F:74:BC

4-00:16:EC:0B:EA:FE

...

53-00:1A:A0:09:28:62

53-00:E0:50:1A:00:37

...

/usr/sbin/workstation.list

3-00:07:E9:5C:44:1F

4-00:16:EC:0B:EA:FE

...

53-00:1A:A0:09:28:62

...

自动生成的:

/etc/dhcp/dhcpd.conf/etc/dhcpd.conf


# Stock gls /etc/dhcpd.conf for RH300 and other classes

# : dhcpd.conf,v 1.1.2.2 2007/11/19 03:08:34 mcurry Exp $

ddns-update-style none;

subnet 192.168.0.0 netmask 255.255.255.0 {

class "virtual" {

match if substring (hardware, 1, 3) = 00:16:3e;

}

# The following lines are standard all of the time.

option routers 192.168.0.254;

option subnet-mask 255.255.255.0;

option domain-name "example.com";

option domain-name-servers 192.168.0.254;

default-lease-time 21600;

max-lease-time 43200;

# Assign IPs 61-80 to Xen domUs

pool {

allow members of "virtual";

range 192.168.0.101 192.168.0.189;

}

# Assign IPs 1-20 for classroom systems unless

# static IPs are assigned below

pool {

deny members of "virtual";

range 192.168.0.1 192.168.0.89;

}

# The following lines are examples of kickstart

# directives.

filename "/var/ftp/pub/workstation.cfg";

# filename "/kickstart/virt_worstation.cfg";

# see /root/README.vcracker for details about virt_workstation.cfg

next-server server1.example.com;

# The following four lines provide an example of an IP

# address bound to a specific MAC.

#

#

#

# Workstation 192.168.0.1-192.168.0.50

host station3 {

hardware ethernet 00:07:E9:5C:44:1F;

fixed-address 192.168.0.3;

}

host station4 {

hardware ethernet 00:16:EC:0B:EA:FE;

fixed-address 192.168.0.4;

}

......

host station53 {

hardware ethernet 00:1A:A0:09:28:62;

fixed-address 192.168.0.53;

}

...

}

option space PXE;

class "PXE" {

match if substring(option vendor-class-identifier, 0, 9) = "PXEClient";

option vendor-encapsulated-options 01:04:00:00:00:00:ff;

option boot-size 0x1;

filename "pxelinux.0";

option tftp-server-name "server1.example.com";

option vendor-class-identifier "PXEClient";

vendor-option-space PXE;

}



3. PXE被推送端主机:Oracle 11gR2 RAC环境共享磁盘主机

现在开始推送Oracle 11gR2 RAC环境共享磁盘主机。

PXE推送端主机运行bcp”:


[root@server1 ~]#bcp

...

RAC11grhel5none

RAC11grhel6shareddisknone

Your Choice: RAC11grhel6shareddisknone

...

PUSH CLASSROM MACHINE(c) OR PUSH VIRTUAL MACHINE1(v1) OR PUSH VIRTUAL MACHINE2(v2): (c or v1 or v2) c

Input is: "c". Are you sure ?(y/n)y

Want rewrite MBR( for before rhel6 should answer "n" ): y


PXE被推送端主机(裸机,硬盘容量不低于60G),从网卡启动自动被推送。推送过程会在running post-install script”屏幕菜单处停留较久时间,只需等待,不需干预。推送后,PXE被推送端主机会自动重启,重启后进入第一个选项,就成为Oracle 11gR2 RAC环境共享磁盘主机。

bcp”程序的主要功能只有一个:在PXE推送端主机生成安装选项文件:/var/ftp/pub/workstation.cfg”。读者若需要了解细节请辅以Linux相关的知识阅读。


4. PXE被推送端主机:Oracle 11gR2 RAC环境节点主机

现在开始推送Oracle 11gR2 RAC环境节点主机。

PXE推送端主机运行bcp:


[root@server1 ~]#bcp

...

RAC11grhel5none

RAC11grhel6shareddisknone

Your Choice: RAC11grhel5none

...

PUSH CLASSROM MACHINE(c) OR PUSH VIRTUAL MACHINE1(v1) OR PUSH VIRTUAL MACHINE2(v2): (c or v1 or v2) c

Input is: "c". Are you sure ?(y/n)y

Want rewrite MBR( for before rhel6 should answer "n" ): y


PXE被推送端主机(裸机至少两台,每台硬盘容量不低于60G),从网卡启动自动被推送。推送过程会在running post-install script”屏幕菜单处停留较久时间,只需等待,不需干预。推送后,PXE被推送端主机会自动重启,重启后进入第一个选项,就成为Oracle 11gR2 RAC环境节点主机。

bcp”程序的主要功能只有一个:在PXE推送端主机生成安装选项文件:/var/ftp/pub/workstation.cfg”。读者若需要了解细节请辅以Linux相关的知识阅读。


4.1 共享存储

在每套推出的Oracle 11gR2 RAC环境中,都包含已自动安装并配置好的三台主机:一台共享磁盘主机和两台节点主机。每套推出的Oracle 11gR2 RAC环境中的两台节点主机都已自动挂接上该套环境内部的共享磁盘主机。该共享磁盘已经从/dev/sdb5”/dev/sdb15”分好11个等大的分区。读者接下来就可以使用oracleasm”命令(已自动安装)在Oracle 11gR2 RAC环境中的两台节点主机上设定asm磁盘。

建议/dev/sdb5”/dev/sdb12”用来创建normal冗余度的asm磁盘组+DATA”/dev/sdb13”/dev/sdb15”用来创建external冗余度的asm磁盘组+FRA”


4.2分布式虚拟磁带库

在每套推出的Oracle 11gR2 RAC环境中的两台节点主机上,各配备一个分布式虚拟磁带库。


[root@station34 ~]# cd /stage/mhvtl-1.2/kernel/

[root@station34 kernel]# make

make -C /lib/modules/2.6.18-164.el5/build SUBDIRS=/stage/mhvtl-1.2/kernel modules

make[1]: Entering directory `/usr/src/kernels/2.6.18-164.el5-i686'

Building modules, stage 2.

MODPOST

make[1]: Leaving directory `/usr/src/kernels/2.6.18-164.el5-i686'

[root@station34 kernel]# service mhvtl start

vtllibrary process PID is 21614

vtllibrary process PID is 21633

[root@station34 ~]# lsscsi -g

[1:0:0:0] mediumx STK L700 0102 - /dev/sg8

[1:0:1:0] tape IBM ULT3580-TD5 0102 /dev/st0 /dev/sg0

[1:0:2:0] tape IBM ULT3580-TD5 0102 /dev/st1 /dev/sg1

[1:0:3:0] tape IBM ULT3580-TD4 0102 /dev/st2 /dev/sg2

[1:0:4:0] tape IBM ULT3580-TD4 0102 /dev/st3 /dev/sg3

[1:0:8:0] mediumx STK L80 0102 - /dev/sg9

[1:0:9:0] tape STK T10000B 0102 /dev/st4 /dev/sg4

[1:0:10:0] tape STK T10000B 0102 /dev/st5 /dev/sg5

[1:0:11:0] tape STK T10000B 0102 /dev/st6 /dev/sg6

[1:0:12:0] tape STK T10000B 0102 /dev/st7 /dev/sg7


osb-10.3.0.3.0_linux32/stage目录下,读者需要自行安装。安装 osb后,利用/stage目录下的osb.sh脚本,在Oracle 11gR2 RAC环境中的两台节点主机上一步到位配置好磁带库:


[root@station34 stage]# ./osb.sh

/dev/sg8

/dev/sg9

/dev/sg0

/dev/sg1

/dev/sg2

/dev/sg3

/dev/sg4

/dev/sg5

/dev/sg6

/dev/sg7

Oracle Secure Backup 10.3.0.3.0

Warning: auto-login failed - login token has expired

login: admin

Password:

...

OSB-CATALOG-MF write 7 days keep 14 days

RMAN-DEFAULT content manages reuse

sexample content manages reuse

station34 content manages reuse


station33station34station83这一套环境为例:两台节点主机station33station34上的虚拟带库分别设置了media family”station33”station34”,还设置了一个基于RAC服务的公共media family”sexample”。装好Oracle 11gR2 RAC环境后,请在station33station34主机上,做rman设置,使我们既可以使用磁盘也可以使用分布式虚拟带库做后续备份恢复实验。


[oracle@station34 ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Tue Oct 29 10:20:18 2013

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

connected to target database: ORCL (DBID=1343950367)

RMAN> show all;

using target database control file instead of recovery catalog

RMAN configuration parameters for database with db_unique_name ORCL are:

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 1 DAYS;

CONFIGURE BACKUP OPTIMIZATION ON;

CONFIGURE DEFAULT DEVICE TYPE TO 'SBT_TAPE';

CONFIGURE CONTROLFILE AUTOBACKUP ON;

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE SBT_TAPE TO '%F'; # default

CONFIGURE DEVICE TYPE DISK PARALLELISM 8 BACKUP TYPE TO BACKUPSET;

CONFIGURE DEVICE TYPE 'SBT_TAPE' PARALLELISM 8 BACKUP TYPE TO BACKUPSET;

CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE SBT_TAPE TO 1; # default

CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE SBT_TAPE TO 1; # default

CONFIGURE CHANNEL 1 DEVICE TYPE 'SBT_TAPE' PARMS 'ENV=(OB_MEDIA_FAMILY=station33)' CONNECT 'sys/oracle_4U@rdbq1';

CONFIGURE CHANNEL 2 DEVICE TYPE 'SBT_TAPE' PARMS 'ENV=(OB_MEDIA_FAMILY=station34)' CONNECT 'sys/oracle_4U@rdbq2';

CONFIGURE CHANNEL 3 DEVICE TYPE 'SBT_TAPE' PARMS 'ENV=(OB_MEDIA_FAMILY=station33)' CONNECT 'sys/oracle_4U@rdbq1';

CONFIGURE CHANNEL 4 DEVICE TYPE 'SBT_TAPE' PARMS 'ENV=(OB_MEDIA_FAMILY=station34)' CONNECT 'sys/oracle_4U@rdbq2';

CONFIGURE CHANNEL 5 DEVICE TYPE 'SBT_TAPE' PARMS 'ENV=(OB_MEDIA_FAMILY=station33)' CONNECT 'sys/oracle_4U@rdbq1';

CONFIGURE CHANNEL 6 DEVICE TYPE 'SBT_TAPE' PARMS 'ENV=(OB_MEDIA_FAMILY=station34)' CONNECT 'sys/oracle_4U@rdbq2';

CONFIGURE CHANNEL 7 DEVICE TYPE 'SBT_TAPE' PARMS 'ENV=(OB_MEDIA_FAMILY=station33)' CONNECT 'sys/oracle_4U@rdbq1';

CONFIGURE CHANNEL 8 DEVICE TYPE 'SBT_TAPE' PARMS 'ENV=(OB_MEDIA_FAMILY=station34)' CONNECT 'sys/oracle_4U@rdbq2';

CONFIGURE MAXSETSIZE TO UNLIMITED; # default

CONFIGURE ENCRYPTION FOR DATABASE OFF; # default

CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default

CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default

CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default

CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_orcl.f'; # default


4.3 时间同步

每套推出的Oracle 11gR2 RAC环境中的两台节点主机都已自动时间同步到该套环境内部的共享磁盘主机上的ntpd时间服务器。


[root@station34 stage]# ntpq

ntpq> peer

remote refid st t when poll reach delay offset jitter

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

*station83.examp .INIT. 16 u - 1024 0 0.000 0.000 0.000

ntpq>


4.4 grid用户和 oracle用户

在每套推出的Oracle 11gR2 RAC环境中的两台节点主机上,用户已经被创建好了:grid”用于安装网格基础架构,oracle”用于安装数据库。

grid”用户的环境变量自动配置好了:


# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

# export ORACLE_BASE=/u01/app/grid

# export ORACLE_HOME=/u01/app/11.2.0/grid

# export ORACLE_SID=+ASM2

# export TNS_ADMIN=$ORACLE_HOME/network/admin

export NLS_LANG=american_america.AL32UTF8

export ORACLE_TERM=xterm

export EDITOR=vi

export PATH=$ORACLE_HOME/bin:$PATH

export LANG=en_US


oracle”用户的环境变量也自动配置好了:


# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

# export ORACLE_BASE=/u01/app/oracle

# export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1

# export ORACLE_SID=RDBQ2

# export ORACLE_UNQNAME=RDBQ

# export TNS_ADMIN=$ORACLE_HOME/network/admin

export NLS_LANG=american_america.AL32UTF8

export ORACLE_TERM=xterm

export EDITOR=vi

export PATH=$ORACLE_HOME/bin:$PATH

export LANG=en_US


这里有个基本安装常识:如果在两个用户、两套ORACLE_HOME”的环境下安装,安装过程中为避免listener注册出现故障,应该先注释掉ORACLE_BASE”ORACLE_HOME”TNS_ADMIN”等参数。安装后再释放注释。


4.5 ssh等价性脚本

每套推出的Oracle 11gR2 RAC环境中的两台节点主机上都已创建好了ssh等价性脚本:/usr/bin/rac-sshd.sh。安装开始前,在第一台节点上需要用grid身份和oracle身份各执行一次该脚本:


[oracle@station33 stage]$ cat /usr/bin/rac-sshd.sh

#!/bin/bash

# ssh-keygen, 192.168.0.33->, oracle@192.168.0.33->

echo "KEY GEN......"

sleep 1

echo

echo

ssh 192.168.0.33 ssh-keygen -t dsa

ssh 192.168.0.34 ssh-keygen -t dsa

echo

echo

# selfconnect, station33->, oracle@station33->

echo "SELF CONNECT......"

sleep 1

echo

echo

ssh station33 cat /home/$USER/.ssh/id_dsa.pub >> /home/$USER/.ssh/authorized_keys

echo

echo

# conterpartconnet, station33.example.com-> , oracle@station33.example.com->

echo "CONTERPART CONNECT......"

sleep 1

echo

echo

scp station34.example.com:/home/$USER/.ssh/id_dsa.pub /tmp/conterpartconnectoracle

ssh station33.example.com cat /tmp/conterpartconnectoracle >> /home/$USER/.ssh/authorized_keys

echo

echo

# TEST

echo "TEST......"

sleep 1

echo

echo

ssh station33 exit

ssh station34 exit

ssh station33.example.com exit

ssh station34.example.com exit

echo

echo

# 192.168.0.34->, oracle@192.168.0.34->

echo "SCP TO CONTERPART ......"

sleep 1

echo

echo

scp /home/$USER/.ssh/known_hosts $USER@192.168.0.34:/home/$USER/.ssh/known_hosts

scp /home/$USER/.ssh/authorized_keys $USER@192.168.0.34:/home/$USER/.ssh/authorized_keys

echo

echo

[oracle@station33 stage]$ rac-sshd.sh


4.6 其他

每套推出的Oracle 11gR2 RAC环境中的两台节点主机都已经做好所有操作系统层面的配置:包括vipscan-vipntp,各种rpm包和操作系统参数等。所有安装软件都已经下载到/stage”目录下。推送出的所有主机上的root用户和其他操作系统用户的密码都是oracle”


4.7 安装

使用以上环境安装各套Oracle 11gR2 RAC环境,系统自检是不会报告任何错误的。全局数据库名和实例名前缀应根据自动生成的.bash_profile文件的规定来建库。比如:

station33station34station83这一套的SID就是RDBQ1RDBQ2。注意所有PXE被推送端主机上生成的脚本和配置文件在推送过程中都是自动根据IP规划变量调整其内容中出现的主机名或SID名的。

如果要继续后面的备份恢复实验,syssystemsysmandbsnmp的密码都必须设置成:oracle_4U”。必需安装示例方案。

具体安装过程都是标准流程,这里略去。如有需要请参考上海Oracle用户组其他成员的相关共享文档。


[root@station33 ~]# crs_stat -t

Name Type Target State Host


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

ora.DATA.dg ora....up.type ONLINE ONLINE station33

ora.FRA.dg ora....up.type ONLINE ONLINE station33

ora....ER.lsnr ora....er.type ONLINE ONLINE station33

ora....N1.lsnr ora....er.type ONLINE ONLINE station34

ora....N2.lsnr ora....er.type ONLINE ONLINE station33

ora....N3.lsnr ora....er.type ONLINE ONLINE station33

ora.asm ora.asm.type ONLINE ONLINE station33

ora.eons ora.eons.type ONLINE ONLINE station33

ora.gsd ora.gsd.type ONLINE ONLINE station33

ora....network ora....rk.type ONLINE ONLINE station33

ora.oc4j ora.oc4j.type ONLINE ONLINE station33

ora.ons ora.ons.type ONLINE ONLINE station33

ora.rdbq.db ora....se.type ONLINE ONLINE station33

ora....ry.acfs ora....fs.type ONLINE ONLINE station33

ora.scan1.vip ora....ip.type ONLINE ONLINE station34

ora.scan2.vip ora....ip.type ONLINE ONLINE station33

ora.scan3.vip ora....ip.type ONLINE ONLINE station33

ora....SM1.asm application ONLINE ONLINE station33

ora....33.lsnr application ONLINE ONLINE station33

ora....n33.gsd application ONLINE ONLINE station33

ora....n33.ons application ONLINE ONLINE station33

ora....n33.vip ora....t1.type ONLINE ONLINE station33

ora....SM2.asm application ONLINE ONLINE station34

ora....34.lsnr application ONLINE ONLINE station34

ora....n34.gsd application ONLINE ONLINE station34

ora....n34.ons application ONLINE ONLINE station34

ora....n34.vip ora....t1.type ONLINE ONLINE station34


5. Shell脚本在推出的节点上批量部署32Oracle11gR2 RAC备份恢复案例场景

5.1 备份恢复案例场景模拟脚本工作原理

基本工作原理是:读者按照以上推送设置的要求安装好成套 Oracle11gR2 RAC环境后,复用以上的PXE推送端主机作为部署平台,在每套推出的Oracle 11gR2 RAC环境中部署32Oracle11gR2 RAC备份恢复案例场景脚本。脚本基于网络执行并批量部署;脚本同时支持下载到每一台Oracle11gR2 RAC节点主机本地运行。脚本能模拟和评测每一套环境每一个备份恢复场景的恢复结果。

32个备份恢复场景模拟脚本调用一个公共子程序库bclcustom-subprogram”。在该公共子程序库里面编写了各个备份恢复场景标准步骤。32个备份恢复场景模拟脚本实际上是根据场景模拟需要组合这些标准步骤来完成相应的场景模拟的。

公共子程序库bclcustom-subprogram”如下:


####

#### 0 Subprograms Begin

### 0.1 Normal Structure Begin

###


# sub_getting has $1 $2

sub_getting() {

echo " "

echo "---------------------------------------------- LAB $1 ----------------------------------------------"

echo " $2"

echo "---------------------------------------------- LAB $1 ----------------------------------------------"

echo " "

echo " "

echo "******************"

echo "你的主机信息如下:"

echo "******************"

ifconfig eth0 | head -n2 | tail -n1 | cut -f 2 -d : | cut -f 1 -d ' '

echo " "

hostname

echo " "

uname -a

echo " "

echo " "

}


sub_detecting() {

/u01/app/11.2.0/grid/bin/crs_stat -t

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "sqlplus /nolog" <

conn / as sysdba

set echo off

set feedback off

@/home/oracle/ptable.sql;

quit

!

fi

echo " "

}


sub_revealing() {

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "sqlplus /nolog" <

conn / as sysdba

set echo off

set feedback off

@/home/oracle/ttable.sql;

quit

!

fi

echo " "

}


sub_resultscoring() {

/u01/app/11.2.0/grid/bin/crs_stat -t

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "sqlplus /nolog" <

conn sys/oracle_4U@$v_dbname as sysdba

set echo off

set feedback off

@/home/oracle/rtable.sql;

quit

!

fi

echo " "

}


sub_clearing() {

rm -f /home/oracle/ptable.sql

rm -f /home/oracle/ctable.sql

rm -f /home/oracle/ttable.sql

rm -f /home/oracle/rtable.sql

rm -f /usr/bin/bclcustom.sh

rm -f /home/oracle/asm

rm -f /home/oracle/bclcustom-subprogram

}


sub_clearing_excludertable() {

rm -f /home/oracle/ptable.sql

rm -f /home/oracle/ctable.sql

rm -f /home/oracle/ttable.sql

rm -f /usr/bin/bclcustom.sh

rm -f /home/oracle/asm

rm -f /home/oracle/bclcustom-subprogram

}



###

### 0.1 Normal Structure End

### 0.2 Database Operation Begin

## 0.2.1 Database SRVCTl Operation Begin

##


sub_shutdowning_normal() {

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/srvctl stop database -d $v_dbname"

fi

echo " "

}

##

## 0.2.1 Database SRVCTl Operation End

## 0.2.2 Database ASM Operation Begin

##


# sub_destroying has $1

sub_destroying() {

# $1 : system*

# # undotbs1*

# # undotbs2*

# # sysaux*

# # example*

# # users*

# # group*

# # current*

#

su - grid -c "export ORACLE_SID=+ASM1 ; export ORACLE_HOME=/u01/app/11.2.0/grid ; asmcmd "< /home/oracle/asm

find / $1

exit

!

sleep 15

sync

v_path1=`cut -f 2 -d '+' /home/oracle/asm | tr -d [:blank:]`

for i in $v_path1

do

v_path2="+"$i

su - grid -c "export ORACLE_SID=+ASM1 ; export ORACLE_HOME=/u01/app/11.2.0/grid ; asmcmd "<

rm $v_path2

exit

!

done

echo " "

}


##

## 0.2.2 Database ASM Operation End

## 0.2.3 Database SQL Operation Begin

##


sub_startuping_node1mount() {

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "sqlplus /nolog" <

conn / as sysdba

startup mount exclusive

quit

!

fi

echo " "

}


sub_creating() {

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "sqlplus /nolog" <

conn sys/oracle_4U@$v_dbname as sysdba

set echo off

set feedback off

@/home/oracle/ctable.sql;

quit

!

fi

echo " "

}


sub_scripting_controlfile_nocatalog() {

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

echo "Next moment control script is going to be create ......"

echo "Display the spid number of session here: "

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "sqlplus /nolog" <

conn sys/oracle_4U@$v_dbname as sysdba

select instance_number from v\$instance;

select spid from v\$process p , v\$session s , v\$mystat m where p.addr=s.paddr and m.sid=s.sid and rownum=1;

alter database backup controlfile to trace;

quit

!

fi

echo ""

}


sub_offlining_users_immediate() {

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "sqlplus /nolog" <

conn sys/oracle_4U@$v_dbname as sysdba

set echo off

set feedback off

select instance_number from v\$instance;

alter tablespace users offline immediate;

quit

!

fi

echo " "

}


sub_offlining_tbsocp05_test_immediate() {

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "sqlplus /nolog" <

conn sys/oracle_4U@$v_dbname as sysdba

set echo off

set feedback off

select instance_number from v\$instance;

alter tablespace tbsocp05_test offline immediate;

quit

!

fi

echo " "

}


sub_shutdowning_abort() {

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/srvctl stop database -d $v_dbname -o abort"

fi

}


sub_altering_default_tablespace() {

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "sqlplus /nolog" <

conn / as sysdba

alter database default tablespace example;

quit

!

fi

echo ""

}


sub_dropping_users() {

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

echo "***FROM THEN ON: DROP***"

su - oracle -c "sqlplus /nolog" <

conn / as sysdba

drop user sh cascade;

drop user oe cascade;

drop tablespace users including contents and datafiles;

quit

!

fi

echo " "

}


##

## 0.2.3 Database SQL Operation End

## 0.2.4 Database RMAN Operation Begin

##


# sub_backingup_controlfile_nocatalog has $1

sub_backingup_controlfile_nocatalog() {

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "rman target sys/oracle_4U@$v_dbname" <

backup tag "$1" current controlfile;

quit

!

fi

echo ""

}


sub_deleting_backup_controlfile_nocatalog() {

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "rman target sys/oracle_4U@$v_dbname" <

delete noprompt backup of controlfile;

delete noprompt copy of controlfile;

!

fi

echo ""

}


sub_resync_catalog() {

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

v_ip=$(ifconfig | grep '192\.168\.0' | head -n 1| cut -d . -f 4| cut -d ' ' -f 1)

grep 'LABS ADD' /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora

if [ $? == '1' ]

then

echo " " >> /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora

echo "rcat =" >> /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora

echo " (DESCRIPTION =" >> /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora

echo " (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.90)(PORT = 1521))" >> /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora

echo " (CONNECT_DATA =" >> /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora

echo " (SERVER = DEDICATED)" >> /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora

echo " (SERVICE_NAME = rcat.example.com)" >> /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora

echo " )" >> /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora

echo " )" >> /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora

echo " " >> /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora

echo '#LABS ADD' >> /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora

fi

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

echo "***Connecting Catalog***"

su - oracle -c "rman target sys/oracle_4U@$v_dbname catalog u90/oracle_4U@rcat" <

resync catalog;

!

fi

echo " "

}


##

## 0.2.4 Database RMAN Operation End

## 0.2.5 Database SQL/RMAN Combined Operation Begin

##


# sub_onlining_users_nocatalog has $1

sub_onlining_users_nocatalog() {

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "sqlplus /nolog" <

conn sys/oracle_4U@$v_dbname as sysdba

select instance_number from v\$instance;

alter tablespace users online;

quit

!

fi

echo " "

# rman

echo "***AFTER TABLESPACE ONLINE***"

echo "***BACKUP AGAIN***"

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "rman target sys/oracle_4U@$v_dbname" <

backup tag "$1" tablespace users;

!

fi

echo " "

}


# sub_offlining_users_nocatalog has $1

sub_offlining_users_nocatalog() {

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "sqlplus /nolog" <

conn sys/oracle_4U@$v_dbname as sysdba

select instance_number from v\$instance;

alter tablespace users offline;

quit

!

fi

echo " "

# rman

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "rman target sys/oracle_4U@$v_dbname"<

backup tag "$1" tablespace users;

!

fi

echo " "

}


# sub_readingwrite_users_nocatalog has $1

sub_readingwrite_users_nocatalog() {

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "sqlplus /nolog" <

conn sys/oracle_4U@$v_dbname as sysdba

select instance_number from v\$instance;

alter tablespace users read write;

quit

!

fi

echo " "

# rman

echo "***AFTER TABLESPACE REWRITE***"

echo "***BACKUP AGAIN***"

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "rman target sys/oracle_4U@$v_dbname" <

backup tag "$1" tablespace users;

!

fi

echo " "

}


# sub_readingonly_users_nocatalog has $1

sub_readingonly_users_nocatalog() {

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "sqlplus /nolog" <

conn sys/oracle_4U@$v_dbname as sysdba

select instance_number from v\$instance;

alter tablespace users read only;

quit

!

fi

echo " "

# rman

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

su - oracle -c "rman target sys/oracle_4U@$v_dbname" <

backup tag "$1" tablespace users;

!

fi

echo " "

}


sub_deleting_early_online_backup_users() {

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

echo "***DELETE THE EARLY ONLINE BACKUP OF USERS***"

echo "***DELETE THE EARLY READ WRITE BACKUP OF USERS***"

su - oracle -c "rman target sys/oracle_4U@$v_dbname" <

delete noprompt backup of tablespace users;

delete noprompt copy of tablespace users;

!

sub_deleting_backup_controlfile_nocatalog

fi

echo " "

}


##

## 0.2.5 Database SQL/RMAN Combined Operation End

### 0.2 Database Operation End

#### 0 Subprograms End

####


从以上脚本可以看出,许多实验需要catalog恢复目录。在脚本中规定恢复目录存在于一台IP192.168.0.90的主机上,服务名为rcat.example.com”,监听端口为:1521”。恢复目录用户名为u90”,密码为oracle_4U”。请事先准备好该设备。


5.2 PXE推送端主机上安装备份恢复案例场景模拟脚本

为了方便读者,作者编写了一个一步到位的安装程序bcl-install”。此程序在PXE推送端主机上安装。

bcl-install”包含的主要内容就是上面的子程序。bcl-install”程序实际上是一个shell编程的自解压安装包,因此不论操作系统是32位和64位;也不论是在6Enterprise Linux还是在5Enterprise Linux上都能运行。


[root@server1 ~]# ./bcl-install


5.3 Oracle 11gR2 RAC环境节点主机部署备份恢复案例场景模拟脚本

现在准备开始在Oracle 11gR2 RAC环境节点主机部署备份恢复案例场景模拟脚本。


5.3.1 PXE推送端主机上准备IP地址列表

为了指定进行备份恢复案例场景模拟的Oracle 11gR2 RAC环境节点主机列表, 请编写“/tmp/botang-config-xshare/course/general/v_botang_all_ipsshd_open”文件,把每套要被模拟备份恢复场景的Oracle 11gR2 RAC环境节点主机的IP地址以空格隔开写成一行,以192.168.0.33192.168.0.34举例如下:


[root@server1 ~]# cd /tmp/botang-config-xshare/course/general

[root@server1 general]# cat v_botang_all_ipsshd_open

192.168.0.33 192.168.0.34


5.3.2 PXE推送端主机上初始化实验脚本


[root@server1 ~]# bcl --RACGRID11g13 newlabs

...

Password Number is: 5.

RAC FITABLE

The course for you to decide: ?

general


****************************************************************************************************

一般注意事项:

1.以下大多数实验要求数据库处于归档模式,一些实验要求有全库备份,请一定注意users表空间要有单独的备份通道(使它自己包含在它自己的备份集中)。

2.把压缩包中各个实验脚本中的*.sqlbclcustom-subprogram放在/home/oracle/下面, root身份运行Cbclcustom.sh(可以放在任何地方),即可实施破坏并作实验。

3.sys的密码一定要叫做oracle_4U

4.实验环境的griddb_home1一定要按照课程环境安装。

5.唯独实验6b和实验15需要在执行完成Cbclcustom.sh之后运行各自文件夹下面的begin-realpost。作进一步破坏,请打开begin-realpost阅读一下就明白了。

6.11g没有实验2

****************************************************************************************************

RACGRID11g13.ori/

RACGRID11g13.ori/7a_当前控制文件和数据文件完好_日志文件全部损坏_正常关机不完全恢复_数据不丢_不需备份/

RACGRID11g13.ori/7a_当前控制文件和数据文件完好_日志文件全部损坏_正常关机不完全恢复_数据不丢_不需备份/begin-real

RACGRID11g13.ori/7a_当前控制文件和数据文件完好_日志文件全部损坏_正常关机不完全恢复_数据不丢_不需备份/bclcustom-subprogram

...


PXE推送端主机上初始化实验脚本的目的是:解压缩脚本压缩包“/usr/sbin/botang-config-lesson.d/CUSTOM/RACGRID11g13.ori.tgz”到“/usr/sbin/botang-config-lesson.d/CUSTOM/RACGRID11g13.ori”,供调用。

/usr/sbin/botang-config-lesson.d/CUSTOM/RACGRID11g13.ori”里每一个文件夹,就是一个备份恢复场景模拟脚本。举例如下:


[root@station90 ~]# cd /usr/sbin/botang-config-lesson.d/CUSTOM/RACGRID11g13.ori/14_删除表空间不完全恢复

[root@station90 14_删除表空间不完全恢复]# ls

bclcustom-subprogram begin-real ctable.sql Pbclcustom.sh Rbclcustom.sh ttable.sql vsftpdrestart-prepare

begin-prepare Cbclcustom.sh end ptable.sql rtable.sql vsftpdrestart-end vsftpdrestart-real

[root@station90 14_删除表空间不完全恢复]#


bcl”程序在批量部署时,自动完成以下四个阶段工作:

第一阶段:拷贝该场景下“*.sql和“bclcustom-subprogram”Oracle 11gR2 RAC环境节点主机的“/home/oracle”下。

第二阶段:通过ssh调用该场景下的“Pbclcustom.sh”Oracle 11gR2 RAC环境节点主机运行,其标准输出收集起来形成ftp页面:“ftp://192.168.0.245/pub/bclresult-xx/prepare”,供查阅。“Pbclcustom.sh”会自动判断奇数/偶数节点,会在奇数执行而绕过 偶数节点。“Pbclcustom.sh”的主要任务是判断Oracle 11gR2 RAC环境节点主机的健康状态。

第三阶段:通过ssh调用该场景下的“Cbclcustom.sh”Oracle 11gR2 RAC环境节点主机运行,其标准输出收集起来形成ftp页面:“ftp://192.168.0.245/pub/bclresult-xx/real”,供查阅。“Cbclcustom.sh”会自动判断奇数/偶数节点,会在奇数执行而绕过 偶数节点。“Cbclcustom.sh”的主要任务是在Oracle 11gR2 RAC环境节点主机搞破坏,模拟场景。

Cbclcustom.sh”程序会调用“ctable.sql”脚本,后者会在每套Oracle 11gR2 RAC环境节点主机该场景中建立一个表名为“t”打头加上随机数的表。这样保证了每套Oracle 11gR2 RAC环境节点在本场景中表名的唯一性。只有现场恢复了,才能找到该表。使得这套程序能适用考试和面试。

ctable.sql”脚本会伴随着日志切换插入该表“12345”5行数值。实验最后的“Rbclcustom.sh”脚本会记住每套Oracle 11gR2 RAC环境节点主机该场景中建立的那个表,并查询其数值,评测该备份恢复场景的恢复结果。如该场景是完全恢复能找到“12345”5行数值;如场景是不完全恢复而且无法找全数值,由于“45”两个数值对应的redo log entry是在丢失或不可用的日志上,只能找到“ 123”(在rac环境下,由于日志 thread的交替,可能数值3也找不到)。每个场景的“ctable.sql”都由公共子程序库“bclcustom-subprogram”中的子程序sub_creating调用,但是每个场景的“ctable.sql”都不一样,即在数据库中做的场景特定操作。

对于编号为“6b”的实验,系统还需自动多走一步:在每套Oracle 11gR2 RAC环境节点主机上删除特定日志(每套系统都会判断是哪一个日志),其标准输出收集起来替换盖掉日志序列号形成ftp页面:“ftp://192.168.0.245/pub/bclresult-xx/real-post。同时暂时锁住“ftp://192.168.0.245/pub/bclresult-xx/real”

对于编号为“15”的实验, 系统还需自动多走两步:在每套Oracle 11gR2 RAC环境节点主机上删除特定日志(每套系统都会判断是哪一个日志),并将该场景恢复掉,制造出一个新 incarnation--“3号化身”,以便让用户之后穿越 incarnation恢复到“2号化身”。其标准输出收集起来形成ftp页面:“ftp://192.168.0.245/pub/bclresult-xx/real-post

第四阶段:通过ssh调用该场景下的“Rbclcustom.sh”Oracle 11gR2 RAC环境节点主机运行,其标准输出收集起来形成ftp页面:“ftp://192.168.0.245/pub/bclresult-xx/end”,供查阅。“Rbclcustom.sh”会自动判断奇数/偶数节点,会在奇数执行而绕过 偶数节点。如前所述,“Rbclcustom.sh”的主要任务是在Oracle 11gR2 RAC环境节点主机 评测该备份恢复场景的恢复结果。

特殊的情况:对于每一个场景,要做实验的用户也可自行把压缩包中对应的实验脚本中的“*.sql”和“bclcustom-subprogram”放在Oracle 11gR2 RAC环境节点主机“/home/oracle/”下面, 自行以root身份依次运行“Pbclcustom.sh”自检环境-->“Cbclcustom.sh”实施破坏并作实验-->最后运行“Rbclcustom.sh”收集实验结果。所不同的是:标准输出直接在屏幕上,从“prepare”到“real”到“end”的整个过程表名都是“edu234”(而不是随机表名)。


6. Oracle11gR2 RAC环境“dd”和“rever”,在后续特定实验前通过“rever”初始化环境

在开始实验之前,显然要求每套Oracle 11gR2 RAC环境都要根据推送时的标准安装好。并都已经开启归档、已经做好rman全库备份(无论磁带机或磁盘备份)。为了方便标识,建议在每套Oracle 11gR2 RAC环境中都建一张表:


Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.3.0

Connected as SYS


SQL> conn / as sysdba

Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.3.0

Connected as SYS


SQL> create table sys.tname(a varchar2(50));


Table created


SQL> insert into sys.tname values ('做实验者姓名');


1 row inserted


如果读者需要连续做实验,在后续特定实验前,为了避免实验间连续恢复产生的过度复杂性,建议读者通过冷备份rever初始化环境,在特定实验前会有提示。

每套Oracle 11gR2 RAC环境,在做好以上所有工作并准备做第一个实验之前,请手工冷备份整套环境。以“oracle”用户在每套Oracle 11gR2 RAC环境第一台节点主机上运行:“/home/oracle/copy.sh”能达到手工冷备份整套环境的目的。以后可以在任何时候,通过以“oracle”用户运行“/home/oracle/rever.sh”初始化环境。如果该套Oracle 11gR2 RAC环境使用磁带机做备份,请以“root”身份运行“copytape-root.sh”备份虚拟磁带库。当以“oracle”用户运行“/home/oracle/rever.sh”初始化环境后,都要再以“root”身份运行“revertape-root.sh”初始化虚拟带库。并重新注册catalog

通过在PXE推送端主机上运行:


[root@server1 ~]# bcl --RACGRID11g13 0

三个问题都选择y


以上命令把脚本“copy.sh”和“rever.sh”,直接推到每套Oracle 11gR2 RAC环境第一台节点主机“/home/oracle”之下。同时脚本“copy.sh”和“rever.sh”PXE推送端主机ftp站点:“ftp://192.168.0.254/pub/bclresult-0/prepare也可下载到。“copytape-root.sh”和“ revertape-root.sh”虽然在bcl程序中不提供,但是它们的内容列在脚本“copy.sh”和“rever.sh”之后。有需要的,将其编写在每套Oracle 11gR2 RAC环境所有节点主机上(任何路径),以“root”身份并运行。

copy.sh”内容如下:


#!/bin/sh

###

### 0 Subprogram Section Begin

###


v_start_time=$(date +%"s")

sub_confirm() {

sub_answer() {

unset SUBANS

sub_sub_answer(){

SUBANS=`echo $SUBANS |tr -d "[:blank:]"`

if [ -z $SUBANS ]

then

SUBANS="NULL"

fi

}

#

# Sub_sub_answer end.

#

read -p "$1" SUBANS

sub_sub_answer # Line15

# Line15 begin: Deal with $SUNANS:

until [ $SUBANS == "y" -o $SUBANS == "n" ]

do

echo "This question should be answered either with \"y\" or \"n\"."

read -p "$1" SUBANS

sub_sub_answer

done

# Line15 end.

}

#

# Sub_answer end.

#

unset SUBCON1

unset SUBCON2

SUBCON1=0

SUBCON2=1

until [ $(echo $SUBCON1|tr -d "[:blank:]") == $(echo $SUBCON2|tr -d "[:blank:]") ]

do

read -p "$1" SUBCON1

sub_answer "Your input is: \"$SUBCON1\". Are you sure ?(y/n) "

if [ -z $(echo $SUBCON1|tr -d "[:blank:]") ]

then

SUBCON1="NULL"

fi

if [ $SUBANS == "y" ]

then

SUBCON2=$SUBCON1

fi

done

}

v_dbname=`cat /home/oracle/dbname 2>/dev/null | tr -d [:blank:]`

v_first_node=`cat /home/oracle/nodeinfo 2>/dev/null | head -n 1`

v_second_node=`cat /home/oracle/nodeinfo 2>/dev/null | tail -n 1`


###

### 0 Subprogram Section End

### 1 Main Section Begin

###


# 1 Decision Root or Oracle Begin

if [ $(id -u) == 0 ]

then

echo "Please login as oracle NOT root."

exit

fi

# 1 Decision Root or Oracle End

# 2 Stop DB Begin

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

if [ -z $v_dbname ]

then

sub_confirm "Please specify the database name: ? "

v_dbname=$SUBCON1

echo $v_dbname>/home/oracle/dbname

fi

if [ -z $v_first_node ]

then

sub_confirm "Please specify the first node name: ? "

v_first_node=$SUBCON1

fi

if [ -z $v_second_node ]

then

sub_confirm "Please specify the second node name: ? "

v_second_node=$SUBCON1

fi

srvctl stop instance -d $v_dbname -i ${v_dbname}1

sudo /u01/app/11.2.0/grid/bin/crs_stat -t

srvctl stop instance -d $v_dbname -i ${v_dbname}2

sudo /u01/app/11.2.0/grid/bin/crs_stat -t

sudo /u01/app/11.2.0/grid/bin/crsctl stop has

ssh $v_second_node "sudo /u01/app/11.2.0/grid/bin/crsctl stop has"

echo "Please wait ......"

sleep 60

fi

/usr/bin/stopdb &>/dev/null

# 2 Stop DB End

# 3 Man Directory Begin

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

if [ ! -d /u01/data/backup ]

then

sub_confirm "Please input the full path of directory to hold the 11 rawdevices backup of RAC, need about 18G ( oracle user should have !!!WRITE PERMISSION!!! in it): ? "

else

SUBCON1=/u01/data

fi

rm -rf $SUBCON1/backup 2>/dev/null

mkdir -p $SUBCON1/backup 2>/dev/null

chown oracle:oinstall $SUBCON1/backup

fi

#rm -rf /u01/app/oracle/man_recovery_area/orcl/backup/

mkdir -p /u01/app/oracle/man_recovery_area/orcl 2>/dev/null

# 3 Man Directory End

# 4 Backup Important Begin

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

for i in `ls /dev/oracleasm/disks`

do

dd if=/dev/oracleasm/disks/$i of=$SUBCON1/backup/$i.img bs=4M &

done

wait

fi

# 4 Backup Important End

# 5 Backup Miscellaneous Begin

# 5 Backup Miscellaneous End

# 6 Start DB Begin

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

sudo /u01/app/11.2.0/grid/bin/crsctl start has

ssh $v_second_node "sudo /u01/app/11.2.0/grid/bin/crsctl start has"

v_end_time=$(date +%"s")

echo "总共花了:$[ $v_end_time - $v_start_time ]秒。再等90秒为你启动集群。"

sleep 90

sudo /u01/app/11.2.0/grid/bin/crsctl start resource ora.DATA.dg

sudo /u01/app/11.2.0/grid/bin/crsctl start resource ora.FRA.dg

srvctl start database -d $v_dbname

sudo /u01/app/11.2.0/grid/bin/crs_stat -t

fi

# 6 End DB End


rever.sh”内容如下:


#!/bin/sh

###

### 0 Subprogram Section Begin

###


v_start_time=$(date +%"s")

sub_confirm() {

sub_answer() {

unset SUBANS

#

# Sub_sub_answer begin:

sub_sub_answer(){

SUBANS=`echo $SUBANS |tr -d "[:blank:]"`

if [ -z $SUBANS ]

then

SUBANS="NULL"

fi

}

#

# Sub_sub_answer end.

#

read -p "$1" SUBANS

sub_sub_answer # Line15

# Line15 begin: Deal with $SUNANS:

until [ $SUBANS == "y" -o $SUBANS == "n" ]

do

echo "This question should be answered either with \"y\" or \"n\"."

read -p "$1" SUBANS

sub_sub_answer

done

# Line15 end.

}

#

# Sub_answer end.

#

unset SUBCON1

unset SUBCON2

SUBCON1=0

SUBCON2=1

until [ $(echo $SUBCON1|tr -d "[:blank:]") == $(echo $SUBCON2|tr -d "[:blank:]") ]

do

read -p "$1" SUBCON1

sub_answer "Your input is: \"$SUBCON1\". Are you sure ?(y/n) "

if [ -z $(echo $SUBCON1|tr -d "[:blank:]") ]

then

SUBCON1="NULL"

fi

if [ $SUBANS == "y" ]

then

SUBCON2=$SUBCON1

fi

done

}

v_dbname=`cat /home/oracle/dbname 2>/dev/null | tr -d [:blank:]`

v_first_node=`cat /home/oracle/nodeinfo 2>/dev/null | head -n 1`

v_second_node=`cat /home/oracle/nodeinfo 2>/dev/null | tail -n 1`


###

### 0 Subprogram Section End

### 1 Main Section Begin

###


# 1 Decision Root or Oracle Begin

if [ $(id -u) == 0 ]

then

echo "Please login as oracle NOT root."

exit

fi

# 1 Decision Root or Oracle End

# 2 Stop DB Begin

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

v_dbname=`cat /home/oracle/dbname | tr -d [:blank:]`

v_first_node=`cat /home/oracle/nodeinfo | head -n 1 | tr -d [:blank:]`

v_second_node=`cat /home/oracle/nodeinfo | tail -n 1 | tr -d [:blank:]`

srvctl stop instance -d $v_dbname -i ${v_dbname}1 -o abort

sudo /u01/app/11.2.0/grid/bin/crs_stat -t

srvctl stop instance -d $v_dbname -i ${v_dbname}2 -o abort

sudo /u01/app/11.2.0/grid/bin/crs_stat -t

sudo /u01/app/11.2.0/grid/bin/crsctl stop has

ssh $v_second_node "sudo /u01/app/11.2.0/grid/bin/crsctl stop has"

echo "Please wait ......"

sleep 60

fi


emctl stop dbconsole


# 2 Stop DB End

# 3 Delete Begin

# 3 Delete End

# 4 Recovery Begin


if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

if [ ! -d /u01/data/backup ]

then

sub_confirm "Please input the full path of directory to hold the 11 rawdevices backup of RAC, need about 18G: ? "

else

SUBCON1=/u01/data

fi

for i in `ls /dev/oracleasm/disks`

do

dd of=/dev/oracleasm/disks/$i if=$SUBCON1/backup/$i.img bs=4M&

done

wait

fi

# 4 Recovery End

if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]

then

sudo /u01/app/11.2.0/grid/bin/crsctl start has

ssh $v_second_node "sudo /u01/app/11.2.0/grid/bin/crsctl start has"

v_end_time=$(date +%"s")

echo "总共花了:$[ $v_end_time - $v_start_time ]秒。"

sleep 90

sudo /u01/app/11.2.0/grid/bin/crsctl start resource ora.DATA.dg

sudo /u01/app/11.2.0/grid/bin/crsctl start resource ora.FRA.dg

srvctl start database -d $v_dbname

sudo /u01/app/11.2.0/grid/bin/crs_stat -t

fi


copytape-root.sh”内容如下:


#!/bin/sh

service observiced stop

service mhvtl stop

rmmod mhvtl


mkdir -p /u01/app/oracle/man_recovery_area/orcl/backup/tape 2>/dev/null

cd /opt/ ; tar -zcvf /u01/app/oracle/man_recovery_area/orcl/backup/tape/mhvtl.tgz mhvtl

cd /usr/local/oracle/ ; tar -zcvf /u01/app/oracle/man_recovery_area/orcl/backup/tape/backup.tgz backup

cd /usr/etc/; tar -zcvf /u01/app/oracle/man_recovery_area/orcl/backup/tape/ob.tgz ob

chown -R oracle:oinstall /u01/app/oracle/man_recovery_area/orcl/backup/tape/


service mhvtl start

service observiced start


revertape-root.sh内容如下:


#!/bin/sh

service observiced stop

service mhvtl stop

rmmod mhvtl


cd /opt/ ; tar -zxvf /u01/app/oracle/man_recovery_area/orcl/backup/tape/mhvtl.tgz

cd /usr/local/oracle/ ; tar -zxvf /u01/app/oracle/man_recovery_area/orcl/backup/tape/backup.tgz

cd /usr/etc/; tar -zxvf /u01/app/oracle/man_recovery_area/orcl/backup/tape/ob.tgz

sleep 3

service mhvtl start

service observiced start


lsscsi -g

obtool inventory -L lib01

lsscsi -g


7. Oracle11gR2 RAC备份恢复案例一:完全恢复类场景批量模拟以及恢复要点

7.1 1a_users表空间在线损坏


PXE推送端主机上运行:

[root@server1 ~]# bcl --RACGRID11g13 1

三个选项选y。每个选项结束后,分别提供以下输出:

ftp://192.168.0.245/pub/bclresult-xx/prepare”

ftp://192.168.0.245/pub/bclresult-xx/real”

ftp://192.168.0.245/pub/bclresult-xx/end”下同

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

sub_getting 1a 1a_users表空间在线损坏

sub_detecting

sub_creating

sub_offlining_users_immediate

sub_destroying "users*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

sub_creating”调用的ctable.sql”内容:

--drop table hr.edu234;

--

set echo off

set feedback off

select * from sys.tname;

create table hr.edu234 ( a number ) tablespace users;

alter system switch logfile;

insert into hr.edu234 values(1);

alter system switch logfile;

commit;

alter system switch logfile;

insert into hr.edu234 values(2);

alter system switch logfile;

commit;

insert into hr.edu234 values(3);

alter system switch logfile;

commit;

insert into hr.edu234 values(4);

alter system switch logfile;

commit;

insert into hr.edu234 values(5);

commit;

--

set serveroutput on

exec dbms_output.put_line(' ');

exec dbms_output.put_line('************************** ');

exec dbms_output.put_line('Table successfully created.');

exec dbms_output.put_line('************************** ');

exec dbms_output.put_line(' ');

恢复要点:

以下所有备份恢复实验,如果使用rman,连接catalog与否,用户自选除非注明。

rman中恢复:restore该数据文件,recover该数据文件。


7.2 1b_下线user表空间损坏


PXE推送端主机上运行:

[root@server1 ~]# bcl --RACGRID11g13 1b

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

sub_getting 1b 1b_下线user表空间损坏

sub_detecting

sub_creating

sub_offlining_users_nocatalog LABS-1B-USERS-AFTER-OFFLINE

sub_destroying "users*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

sub_creating”调用的ctable.sql”内容:

1a_users表空间在线损坏

恢复要点:

rman中恢复:restore该数据文件,online该表空间


7.3 1c_只读user表空间损坏


PXE推送端主机上运行:

[root@server1 ~]# bcl --RACGRID11g13 1c

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

sub_getting 1c 1c_只读user表空间损坏

sub_detecting

sub_creating

sub_readingonly_users_nocatalog LABS-1C-USERS-AFTER-READ-ONLY

sub_offlining_users_immediate

sub_destroying "users*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

sub_creating”调用的ctable.sql”内容:

1a_users表空间在线损坏

恢复要点:

rman中恢复:restore该数据文件,online该表空间 read write该表空间。


7.4 1d_users表空间热备


PXE推送端主机上运行:

[root@server1 ~]# bcl --RACGRID11g13 1d

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

sub_getting 1d 1d_users表空间热备

sub_detecting

sub_creating

echo " "

echo " "

sub_revealing

sub_shutdowning_abort

sub_clearing

echo "THE END"

sub_creating”调用的ctable.sql”内容:

--drop table hr.edu234;

--

set echo off

set feedback off

select * from sys.tname;

create table hr.edu234 ( a number ) tablespace users;

alter system switch logfile;

insert into hr.edu234 values(1);

alter system switch logfile;

commit;

alter system switch logfile;

insert into hr.edu234 values(2);

alter system switch logfile;

commit;

insert into hr.edu234 values(3);

alter system switch logfile;

commit;

set echo on

set feedback on

alter tablespace users begin backup;

select * from v$backup;

set echo off

set feedback off

insert into hr.edu234 values(4);

alter system switch logfile;

commit;

insert into hr.edu234 values(5);

commit;

--

set serveroutput on

exec dbms_output.put_line(' ');

exec dbms_output.put_line('************************** ');

exec dbms_output.put_line('Table successfully created.');

exec dbms_output.put_line('************************** ');

exec dbms_output.put_line(' ');

恢复要点:

1)启动到mountsqlplus中恢复:alter database end backup; alter database open;

2srvctl启动其他实例。


7.5 3_system表空间离线损坏


PXE推送端主机上运行:

[root@server1 ~]# bcl --RACGRID11g13 3

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

sub_getting 3 3_system表空间离线损坏

sub_detecting

sub_creating

sub_shutdowning_normal

sub_destroying "system*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

sub_creating”调用的ctable.sql”内容:

--drop table sys.edu234;

--

set echo off

set feedback off

select * from sys.tname;

create table sys.edu234 ( a number ) tablespace system;

alter system switch logfile;

insert into sys.edu234 values(1);

alter system switch logfile;

commit;

alter system switch logfile;

insert into sys.edu234 values(2);

alter system switch logfile;

commit;

insert into sys.edu234 values(3);

alter system switch logfile;

commit;

insert into sys.edu234 values(4);

alter system switch logfile;

commit;

insert into sys.edu234 values(5);

commit;

--

set serveroutput on

exec dbms_output.put_line(' ');

exec dbms_output.put_line('************************** ');

exec dbms_output.put_line('Table successfully created.');

exec dbms_output.put_line('************************** ');

exec dbms_output.put_line(' ');

恢复要点:

1)启动到mountrman中恢复:restore system表空间,recover system 表空间。

2srvctl启动其他实例。


7.6 4_tbsocp05_test没有备份的表空间损坏


PXE推送端主机上运行:

[root@server1 ~]# bcl --RACGRID11g13 4

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

sub_getting 4 4_tbsocp05_test没有备份的表空间损坏

sub_detecting

echo "***TABLESPACE CREATED***"

sub_creating

sub_offlining_tbsocp05_test_immediate

sub_destroying "tbsocp05_test*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

sub_creating”调用的ctable.sql”内容:

--drop table hr.edu234;

--

set echo off

set feedback off

select * from sys.tname;

create tablespace tbsocp05_test datafile size 5M;

create table hr.edu234 ( a number ) tablespace tbsocp05_test;

alter system switch logfile;

insert into hr.edu234 values(1);

alter system switch logfile;

commit;

alter system switch logfile;

insert into hr.edu234 values(2);

alter system switch logfile;

commit;

insert into hr.edu234 values(3);

alter system switch logfile;

commit;

insert into hr.edu234 values(4);

alter system switch logfile;

commit;

insert into hr.edu234 values(5);

commit;

--

set serveroutput on

exec dbms_output.put_line(' ');

exec dbms_output.put_line('************************** ');

exec dbms_output.put_line('Table successfully created.');

exec dbms_output.put_line('************************** ');

exec dbms_output.put_line(' ');

恢复要点:

1)在sqlplus里恢复:alter database create datafile '原文件名';

2OMF改了文件名,因此:alter database rename file '旧文件名' to '新文件名';

3recover datafile '新文件名'


8. Oracle11gR2 RAC备份恢复案例二:不完全恢复类场景批量模拟以及恢复要点

8.1 5_基于时间的不完全恢复


所有被推送端做实验机准备:

由于没有必要老是在之后的实验中都需要考虑到tbsocp05_test表空间的特殊恢复需求,本实验前请务必备份 tbsocp05_test表空间

PXE推送端主机上运行:

[root@server1 ~]# bcl --RACGRID11g13 5

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

sub_getting 5 5_基于时间的不完全恢复

sub_detecting

sub_creating

echo " "

echo " "

sub_revealing

echo " "

sub_clearing

echo "THE END"

sub_creating”调用的ctable.sql”内容:

--drop table hr.edu234;

--

set echo off

set feedback off

select * from sys.tname;

create table hr.edu234 ( a number ) tablespace users;

alter system switch logfile;

insert into hr.edu234 values(1);

alter system switch logfile;

commit;

--

set serveroutput on

exec dbms_output.put_line(' ');

exec dbms_output.put_line('************************** ');

exec dbms_output.put_line('Table successfully created.');

exec dbms_output.put_line('************************** ');

exec dbms_output.put_line(' ');

--

select * from hr.edu234;

exec dbms_output.put_line('********************************************************************************************************** ');

exec dbms_output.put_line('After the displayed moment, the table will continuously be inserted with more rows, but finnally be droped.');

exec dbms_output.put_line('********************************************************************************************************** ');

exec dbms_output.put_line(' ');

host sleep 5

alter session set nls_date_format='yyyy-mm-dd:hh24:mi:ss';

select sysdate from dual;

host sleep 3

alter system switch logfile;

insert into hr.edu234 values(2);

alter system switch logfile;

commit;

insert into hr.edu234 values(3);

alter system switch logfile;

commit;

insert into hr.edu234 values(4);

alter system switch logfile;

commit;

insert into hr.edu234 values(5);

commit;

select * from hr.edu234;

drop table hr.edu234 purge;

恢复要点:

1)启动到mountrmanrun{}块中恢复:根据ctable.sql输出的时间set until timerestore databaserecover databasealter database open resetlogs;

2srvctl启动其他实例。


8.2 6a_基于log序列号的不完全恢复


PXE推送端主机上运行:

[root@server1 ~]# bcl --RACGRID11g13 6a

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

sub_getting 6a 6a_基于log序列号的不完全恢复

sub_detecting

sub_creating

echo " "

echo " "

sub_revealing

echo " "

sub_clearing

echo "THE END"

sub_creating”

调用的ctable.sql”内容:

--drop table hr.edu234;

--

set echo off

set feedback off

select * from sys.tname;

create table hr.edu234 ( a number ) tablespace users;

alter system switch logfile;

insert into hr.edu234 values(1);

alter system switch logfile;

commit;

--

set serveroutput on

exec dbms_output.put_line(' ');

exec dbms_output.put_line('************************** ');

exec dbms_output.put_line('Table successfully created.');

exec dbms_output.put_line('************************** ');

exec dbms_output.put_line(' ');

--

select * from hr.edu234;

exec dbms_output.put_line('*********************************************************************************************************** ');

exec dbms_output.put_line('After the displayed moment, the table will continuously be inserted with more rows, but finnally be droped..');

exec dbms_output.put_line('*********************************************************************************************************** ');

exec dbms_output.put_line(' ');

host sleep 5

select THREAD#, SEQUENCE# from v$log;

archive log list

host sleep 3

alter system switch logfile;

insert into hr.edu234 values(2);

alter system switch logfile;

commit;

insert into hr.edu234 values(3);

alter system switch logfile;

commit;

insert into hr.edu234 values(4);

alter system switch logfile;

commit;

insert into hr.edu234 values(5);

commit;

select * from hr.edu234;

drop table hr.edu234 purge;

恢复要点:

1)启动到mountrmanrun{}块中恢复:根据ctable.sql输出的日志序列号set until sequence xx thread xrestore databaserecover databasealter database open resetlogs;

2)特别注意ctable.sql输出的日志序列号需要加1,因为until不包含的意思。

3srvctl启动其他实例。


续篇
6

鲜花

握手

雷人

路过

鸡蛋

刚表态过的朋友 (6 人)

相关阅读

QQ|手机版|Botang唐波's Oracle Station    

GMT+8, 2017-6-16 16:31 , Processed in 0.131935 second(s), 22 queries .

返回顶部