用Shell脚本在推出的RAC节点上批量部署32个Oracle11gR2 RAC备份恢复案例场景的方法PART2

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


在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

sub_creating

echo "***BEFORE TABLESPACE READONLY***"

sub_scripting_controlfile_nocatalog

sub_readingonly_users_nocatalog LABS-9D-USERS-AFTER-READ-ONLY

echo "***AFTER TABLESPACE READONLY***"

sub_scripting_controlfile_nocatalog

sub_deleting_backup_controlfile_nocatalog

sub_resync_catalog

sub_shutdowning_abort

sub_destroying "current*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

“sub_creating”

调用的“ctable.sql”内容:

同“1a_users表空间在线损坏”

恢复要点:

1)找到sub_scripting_controlfile_nocatalog给出的trace文件名,编辑成sql脚本:留下set #1 noresetlogs部分,去掉set #2。在users表空间只读前后各有一个trace文件,用之前的那个,不然会出现missing00004

2)启动到nomountsqlplus中恢复:改cluster_database初始化参数为false;执行以上脚本;cluster_database初始化参数为truerecover database; alter database openalter tablespace users online; alter  tablespace users read write;

3srvctl启动其他实例。


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


在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

sub_deleting_early_online_backup_users

echo "***LABS TOTALLY DIFFERENT BEGINS: TABLESPACE  OFFLINE***"

echo "***BEFORE TABLESPACE ONLINE***"

echo "***BACKUP***"

sub_offlining_users_nocatalog LABS-10A-USERS-BEFORE-ONLINE

sub_backingup_controlfile_nocatalog LABS-10A-CONTR-BEFORE-ONLINE

echo "***FROM THEN ON: ONLINE***"

sub_onlining_users_nocatalog LABS-10A-USERS-AFTER-ONLINE

sub_backingup_controlfile_nocatalog LABS-10A-CONTR-AFTER-ONLINE

sub_resync_catalog

sub_creating

sub_shutdowning_abort

sub_destroying "current*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

“sub_creating”

调用的“ctable.sql”内容:

同“1a_users表空间在线损坏”

恢复要点:

1)启动到nomountrman中恢复:restore controlfilemount数据库;用tag“LABS-10A-CONTR-AFTER-ONLINE的控制文件备份来恢复。这是因为控制文件不能很好地经历表空间从下线到上线的变化。如果用了tagLABS-10A-CONTR-BEFORE-ONLINE”的控制文件备份来恢复,resetlogs之后需要跟上后续恢复。我们对比发现在不连接catalog的情况下进行恢复,10gR2的数据库如果用错了以上的tag,问题更严重,根本无法打开数据库。

2)在rman中恢复:recover databasealter database open resetlogs;(二进制控制文件restore后指导的恢复,都要resetlogs);

4srvctl启动其他实例。


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


在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

sub_deleting_early_online_backup_users

echo "***LABS TOTALLY DIFFERENT BEGINS: TABLESPACE  OFFLINE***"

echo "***BEFORE TABLESPACE ONLINE***"

echo "***BACKUP***"

sub_offlining_users_nocatalog LABS-10B-USERS-BEFORE-ONLINE

sub_scripting_controlfile_nocatalog

echo "***FROM THEN ON: ONLINE***"

sub_onlining_users_nocatalog LABS-10B-USERS-AFTER-ONLINE

sub_scripting_controlfile_nocatalog

sub_deleting_backup_controlfile_nocatalog

sub_resync_catalog

sub_creating

sub_shutdowning_abort

sub_destroying "current*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

“sub_creating”

调用的“ctable.sql”内容:

同“1a_users表空间在线损坏”

恢复要点:

1)找到sub_scripting_controlfile_nocatalog给出的trace文件名,编辑成sql脚本:留下set #1 noresetlogs部分,去掉set #2。在users表空间下线前后各有一个trace文件,用之后的那个,不然会出现missing00004

2)启动到nomountsqlplus中恢复:改cluster_database初始化参数为false;执行以上脚本;cluster_database初始化参数为truerecover database;alter database open

3srvctl启动其他实例。


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


在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

sub_deleting_early_online_backup_users

echo "***LABS TOTALLY DIFFERENT BEGINS: TABLESPACE READ ONLY***"

echo "***BEFORE TABLESPACE WRITE***"

echo "***BACKUP***"

sub_readingonly_users_nocatalog LABS-10C-USERS-BEFORE-RW

sub_backingup_controlfile_nocatalog LABS-10C-CONTR-BEFORE-RW

echo "***FROM THEN ON: READ WARITE***"

sub_readingwrite_users_nocatalog LABS-10C-USERS-AFTER-RW

sub_backingup_controlfile_nocatalog LABS-10C-CONTR-AFTER-RW

sub_resync_catalog

sub_creating

sub_shutdowning_abort

sub_destroying "current*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

“sub_creating”

调用的“ctable.sql”内容:

同“1a_users表空间在线损坏”

恢复要点:

1)启动到nomountrman中恢复:restore controlfilemount数据库;用tag“LABS-10C-CONTR-AFTER-RW的控制文件备份来恢复。这是因为控制文件不能很好地经历表空间从下线到上线的变化。如果用了tagLABS-10C-CONTR-BEFORE-RW”来恢复,resetlogs之后需要跟上后续恢复。我们对比发现在不连接catalog的情况下进行恢复,10gR2的数据库如果用错了以上的tag,问题更严重,根本无法打开数据库。

2)在rman中恢复:recover databasealter database open resetlogs;(二进制控制文件restore后指导的恢复,都要resetlogs);

4srvctl启动其他实例。


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


在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

sub_deleting_early_online_backup_users

echo "***LABS TOTALLY DIFFERENT BEGINS: TABLESPACE READ  ONLY***"

echo "***BEFORE TABLESPACE READ WRITE***"

echo "***BACKUP***"

sub_readingonly_users_nocatalog LABS-10D-USERS-BEFORE-RW

sub_scripting_controlfile_nocatalog

echo "***FROM THEN ON: READ WRITE***"

sub_readingwrite_users_nocatalog LABS-10D-USERS-AFTER-RW

sub_scripting_controlfile_nocatalog

sub_deleting_backup_controlfile_nocatalog

sub_resync_catalog

sub_creating

sub_shutdowning_abort

sub_destroying "current*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

“sub_creating”

调用的“ctable.sql”内容:

同“1a_users表空间在线损坏”

恢复要点:

1)找到sub_scripting_controlfile_nocatalog给出的trace文件名,编辑成sql脚本:留下set #1 noresetlogs部分,去掉set #2。在users表空间下线前后各有一个trace文件,用之后的那个,不然会出现missing00004

2)启动到nomountsqlplus中恢复:改cluster_database初始化参数为false;执行以上脚本;cluster_database初始化参数为truerecover database;alter database open

3srvctl启动其他实例。


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


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


在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

sub_creating

sub_backingup_controlfile_nocatalog LABS-11A-CONTROLFILE

sub_resync_catalog

sub_shutdowning_abort

sub_destroying "current*"

sub_destroying "group*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

“sub_creating”

调用的“ctable.sql”内容:

同“1a_users表空间在线损坏”

恢复要点:

注意:如果刚做完实验10d,本场景之前,rever环境

1)在线日志被删除,日志序列号请用asmcmd确认。

2)启动到nomountrman中恢复:restore  controlfilemount数据库。

3)在rmanrun{}中恢复:set  until sequence 在线日志currentsequencethread xrestore databaserecover  database;alter database open  resetlogs;

4)srvctl启动其他实例。


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


在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

sub_creating

sub_scripting_controlfile_nocatalog

sub_deleting_backup_controlfile_nocatalog

sub_resync_catalog

sub_shutdowning_abort

sub_destroying "current*"

sub_destroying "group*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

“sub_creating”

调用的“ctable.sql”内容:

同“1a_users表空间在线损坏”

恢复要点:

注意:如果刚做完实验11a,本场景之前,rever环境

1)找到sub_scripting_controlfile_nocatalog给出的trace文件名,编辑成sql脚本:留下set #2 resetlogs部分,去掉set #1

2)启动到nomountsqlplus恢复:改cluster_database初始化参数为false;执行以上脚本;cluster_database初始化参数为true;自动到mount

3)在rman中做一些预备工作:restore那些delete input archivelogrestore  database;

4)在线日志被删除,日志序列号请用asmcmd确认。

5)在sqlplus中恢复:recover  database until cancel using backup controlfile; 注意set  #2脚本中本身给的提示recover database using backup  controlfile”是不正确的,会直接导致打不开数据库。

6)在sqlplus中恢复:遇到在线日志currentsequence号时,敲cancelalter  database open resetlogs;

7)添加临时文件,块跟踪文件等。

8srvctl启动其他实例。


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


在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

sub_deleting_early_online_backup_users

echo "***LABS TOTALLY DIFFERENT BEGINS: TABLESPACE  OFFLINE***"

echo "***BEFORE TABLESPACE ONLINE***"

echo "***BACKUP***"

sub_offlining_users_nocatalog LABS-12A-USERS-BEFORE-ONLINE

sub_backingup_controlfile_nocatalog LABS-12A-CONTR-BEFORE-ONLINE

echo "***FROM THEN ON: ONLINE***"

sub_onlining_users_nocatalog LABS-12A-USERS-AFTER-ONLINE

sub_backingup_controlfile_nocatalog LABS-12A-CONTR-AFTER-ONLINE

sub_resync_catalog

sub_creating

sub_shutdowning_abort

sub_destroying "current*"

sub_destroying "group*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

“sub_creating”

调用的“ctable.sql”内容:

同“1a_users表空间在线损坏”

恢复要点:

注意:如果刚做完实验11b,本场景之前,rever环境

1)先按10a做,会失败。在线日志被删除,日志序列号请用asmcmd确认。

2)与10a不同的是必需在rmanrun{}块中恢复:set until sequence 在线日志currentsequencethread xrestore databaserecover  database;alter database open  resetlogs;

3srvctl启动其他实例。


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


在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

sub_deleting_early_online_backup_users

echo "***LABS TOTALLY DIFFERENT BEGINS: TABLESPACE  OFFLINE***"

echo "***BEFORE TABLESPACE ONLINE***"

echo "***BACKUP***"

sub_offlining_users_nocatalog LABS-12B-USERS-BEFORE-ONLINE

sub_scripting_controlfile_nocatalog

echo "***FROM THEN ON: ONLINE***"

sub_onlining_users_nocatalog LABS-12B-USERS-AFTER-ONLINE

sub_scripting_controlfile_nocatalog

sub_deleting_backup_controlfile_nocatalog

sub_resync_catalog

sub_creating

sub_shutdowning_abort

sub_destroying "current*"

sub_destroying "group*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

“sub_creating”

调用的“ctable.sql”内容:

同“1a_users表空间在线损坏”

恢复要点:

注意:如果刚做完实验12a,本场景之前,rever环境

1)先按10b做,会失败。在线日志被删除,日志序列号请用asmcmd确认。

2)找到sub_scripting_controlfile_nocatalog给出的trace文件名,编辑成sql脚本:留下set #2 resetlogs部分,去掉set #1。在users表空间下线前后各有一个trace文件,用之后的那个,不然会出现missing00004

3)启动到nomountsqlplus恢复:改cluster_database初始化参数为false;执行以上脚本;cluster_database初始化参数为true;自动到mount

4)在rman中做一些预备工作:restore那些delete input archivelogrestore  database;

5)在sqlplus中恢复:recover  database until cancel using backup controlfile; 注意set  #2脚本中本身给的提示recover database using backup  controlfile”是不正确的,会直接导致打不开数据库。

6)在sqlplus中恢复:遇到在线日志currentsequence号时,敲cancelalter  database open resetlogs;

7)添加临时文件,块跟踪文件等。

8srvctl启动其他实例。


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


在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

sub_deleting_early_online_backup_users

echo "***LABS TOTALLY DIFFERENT BEGINS: TABLESPACE READ  ONLY***"

echo "***BEFORE TABLESPACE WRITE***"

echo "***BACKUP***"

sub_readingonly_users_nocatalog LABS-12C-USERS-BEFORE-RW

sub_backingup_controlfile_nocatalog LABS-12C-CONTR-BEFORE-RW

echo "***FROM THEN ON: READ WARITE***"

sub_readingwrite_users_nocatalog LABS-12C-USERS-AFTER-RW

sub_backingup_controlfile_nocatalog LABS-12C-CONTR-AFTER-RW

sub_resync_catalog

sub_creating

sub_shutdowning_abort

sub_destroying "current*"

sub_destroying "group*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

“sub_creating”

调用的“ctable.sql”内容:

同“1a_users表空间在线损坏”

恢复要点:

注意:如果刚做完实验12b,本场景之前,rever环境

1)先按10c做,会失败。在线日志被删除,日志序列号请用asmcmd确认。

2)与10c不同的是必需在rmanrun{}块中恢复:set until sequence 在线日志currentsequencethread xrestore databaserecover  database;alter database open  resetlogs;

3srvctl启动其他实例。


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


在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

sub_deleting_early_online_backup_users

echo "***LABS TOTALLY DIFFERENT BEGINS: TABLESPACE READ  ONLY***"

echo "***BEFORE TABLESPACE READ WRITE***"

echo "***BACKUP***"

sub_readingonly_users_nocatalog LABS-12D-USERS-BEFORE-RW

sub_scripting_controlfile_nocatalog

echo "***FROM THEN ON: READ WRITE***"

sub_readingwrite_users_nocatalog LABS-12D-USERS-AFTER-RW

sub_scripting_controlfile_nocatalog

sub_deleting_backup_controlfile_nocatalog

sub_resync_catalog

sub_creating

sub_shutdowning_abort

sub_destroying "current*"

sub_destroying "group*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

“sub_creating”

调用的“ctable.sql”内容:

同“1a_users表空间在线损坏”

恢复要点:

注意:如果刚做完实验12c,本场景之前,rever环境

1)先按10d做,会失败。在线日志被删除,日志序列号请用asmcmd确认。

2)找到sub_scripting_controlfile_nocatalog给出的trace文件名,编辑成sql脚本:留下set #2 resetlogs部分,去掉set #1。在users表空间下线前后各有一个trace文件,用之后的那个,不然会出现missing00004

3)启动到nomountsqlplus恢复:改cluster_database初始化参数为false;执行以上脚本;cluster_database初始化参数为true;自动到mount

4)在rman中做一些预备工作:restore那些delete input archivelogrestore  database;

5)在sqlplus中恢复:recover  database until cancel using backup controlfile; 注意set  #2脚本中本身给的提示recover database using backup  controlfile”是不正确的,会直接导致打不开数据库。

6)在sqlplus中恢复:遇到在线日志currentsequence号时,敲cancelalter  database open resetlogs;

7)添加临时文件,块跟踪文件等。

8srvctl启动其他实例。


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


在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

echo "BEFORE TABLESPACE CREATION"

echo "***BACKUP***"

sub_backingup_controlfile_nocatalog LABS-13A-CONTR-BEFORE-CREA

sub_resync_catalog

echo "***TABLESPACE CREATED***"

sub_creating

echo "AFTER TABLESPACE CREATION"

echo "***BACKUP AGAIN***"

sub_backingup_controlfile_nocatalog LABS-13A-CONTR-AFTER-CREA

sub_resync_catalog

sub_shutdowning_abort

sub_destroying "current*"

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_test2 datafile size 5M;

create tablehr.edu234 (  a number ) tablespace tbsocp05_test2;

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)启动到nomountrman中恢复:restore controlfilemount数据库;用tag“LABS-13A-CONTR-BEFORE-CREAtag“LABS-13A-CONTR-AFTER-CREA的控制文件备份来恢复都可以。控制文件能经历新建表空间的变化。我们对比发现在不连接catalog的情况下进行恢复,10gR2的数据库如果用tag“LABS-13A-CONTR-BEFORE-CREA来恢复,该新建表空间对应的数据文件会出现uname00007问题,需要跟上后续恢复。

2)在rman中恢复:recover databasealter database open resetlogs;(二进制控制文件restore后指导的恢复,都要resetlogs

4srvctl启动其他实例。


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


在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

echo "BEFORE TABLESPACE CREATION"

sub_scripting_controlfile_nocatalog

echo "***TABLESPACE CREATED***"

sub_creating

echo "AFTER TABLESPACE CREATION"

sub_scripting_controlfile_nocatalog

sub_deleting_backup_controlfile_nocatalog

sub_shutdowning_abort

sub_destroying "current*"

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_test3 datafile size 5M;

create tablehr.edu234 (  a number) tablespace tbsocp05_test3;

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)找到sub_scripting_controlfile_nocatalog给出的trace文件名,编辑成sql脚本:留下set #1 noresetlogs部分,去掉set #2。在新建表空间前后各有一个trace文件,用之后的那个,不然会出现missing00004

2)启动到nomountsqlplus中恢复:改cluster_database初始化参数为false;执行以上脚本;cluster_database初始化参数为truerecover database;alter database open

3srvctl启动其他实例。


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


在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

sub_altering_default_tablespace

echo "***BEFORE TABLESPACE DROP***"

echo "***BACKUP***"

sub_backingup_controlfile_nocatalog LABS-14-CONTR-BEFORE-DROP

sub_creating

sub_dropping_users

echo "***AFTER TABLESPACE DROP***"

echo "***BACKUP AGAIN***"

sub_backingup_controlfile_nocatalog LABS-14-CONTR-AFTER-DROP

sub_resync_catalog

echo " "

sub_revealing

echo " "

sub_clearing

echo "THE END"

“sub_creating”

调用的“ctable.sql”内容:

同“1a_users表空间在线损坏”

恢复要点:

注意:如果刚做完实验13b,本场景之前,rever环境

1)启动到nomountrman中恢复:restore  controlfilemount数据库;用tag“LABS-14-CONTR-BEFORE-DROP的控制文件备份来恢复。不然恢复后数据文件出missing00004

2)找所有实例上的alert日志,发现开始删除表空间的时间。将这个时间减去1秒。

3)启动到mountrmanrun{}块中恢复:根据减去1秒的时间set until timerestore databaserecover databasealter database open resetlogs;

2srvctl启动其他实例。


9.10 15_穿越incarnation不完全恢复


在PXE推送端主机上运行:

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

“bcl --RACGRID11g13 15”之后会自动运行的 “real-post”脚本内容(其他场景无本项):

#!/bin/sh

rm -f /root/tmp/bclcustom.sh

for i in `ls /root/tmp/bclresult*`

do

v_botang_thread=$(  grep -A 2 INSTANCE_NUMBER $i | tail -n 1 | tr -d '[:blank:]')

v_botang_currlog=$(  grep'Current log sequence'  $i| tail -n 1 | cut -c 29- )

v_botang_currlogplus1=$[  $v_botang_currlog + 1 ]

v_botang_oldestlog=$(  grep'Oldest online log  sequence' $i | tail -n 1 | cut -c29- )

v_botang_oldestlogbefore=$(  grep'Oldest online log  sequence' $i | head -n 1 | cut -c29- )

v_botang_nextlog=$(  grep'Next log sequence to  archive' $i | tail -n 1 | cut -c 29- )

v_botang_nextlogbefore=$(  grep'Next log sequence to  archive' $i | head -n 1 | cut -c 29- )

v_botang_currlogdest=$(  grep 'Archive destination' $i|  tail -n 1 | cut -c 29- )

v_botang_ip=$(echo  $i| cut -f 2 -d - )

perl -i  -pe "s,Oldest online log sequence$v_botang_oldestlog,Oldest online log sequenceXXX," $i

perl -i  -pe "s,Oldest online log sequence$v_botang_oldestlogbefore,Oldest online log sequenceAAA," $i

perl -i  -pe "s,Next log sequence to archive$v_botang_nextlog,Next log sequence  to archiveYYY," $i

perl -i  -pe "s,Next log sequence to archive$v_botang_nextlogbefore,Next log  sequence to archiveBBB," $i

grep -v  'Current log sequence' $i > $i.tmp

rm -f$i

mv  $i.tmp$i

cat >  /root/tmp/rac.sh <<EOL

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 -q  '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  " "

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

then

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

find /  thread_${v_botang_thread}_seq_$v_botang_currlogplus1*

exit

EOF

sleep 1

v_path1=\$(cut  -f 2 -d '+' /home/oracle/asm|  head -n 1 | tr -d [:blank:])

v_path2="+"\$v_path1

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

rm -rf  \$v_path2

exit

EOF

fi

EOL

scp-q -o ConnectTimeout=1-o StrictHostKeyChecking=no -o  NumberOfPasswordPrompts=1 -o ConnectionAttempts=1 /root/tmp/rac.sh$v_botang_ip:/usr/bin

ssh -q -o  ConnectTimeout=1-o  StrictHostKeyChecking=no -o NumberOfPasswordPrompts=1 -o ConnectionAttempts=1  $v_botang_ip "chmod +x /usr/bin/rac.sh"

ssh -q -o  ConnectTimeout=1-o  StrictHostKeyChecking=no -o NumberOfPasswordPrompts=1 -o ConnectionAttempts=1  $v_botang_ip /usr/bin/rac.sh >>$i 2>&1

ssh -q -o  ConnectTimeout=1-o  StrictHostKeyChecking=no -o NumberOfPasswordPrompts=1 -o ConnectionAttempts=1  $v_botang_ip "rm -rf /usr/bin/rac.sh"

rm  -rf/root/tmp/bclshell-$v_botang_ip

echo  "v_dbname=\$(cat /home/oracle/dbname | tr -d [:blank:])" >>  /root/tmp/bclshell-$v_botang_ip

echo 'su -  oracle -c "srvctl start instance -i ${v_dbname}1 -d $v_dbname -o mount  &>/dev/null"' >> /root/tmp/bclshell-$v_botang_ip

echo 'su -  oracle -c "srvctl start instance -i ${v_dbname}2 -d $v_dbname -o mount  &>/dev/null"' >> /root/tmp/bclshell-$v_botang_ip

echo  "if [ -f /u01/app/11.2.0/grid/dbs/hc_+ASM1.dat ]" >>  /root/tmp/bclshell-$v_botang_ip

echo  "then" >> /root/tmp/bclshell-$v_botang_ip

echo  "su - oracle -c \"rman target sys/oracle_4U@\${v_dbname} \"  <<EOF " >> /root/tmp/bclshell-$v_botang_ip

echo  "run { ">> /root/tmp/bclshell-$v_botang_ip

echo  "set until sequence $v_botang_currlogplus1 thread  $v_botang_thread;" >>/root/tmp/bclshell-$v_botang_ip

echo  "restore database;">>/root/tmp/bclshell-$v_botang_ip

echo  "recover database;">>/root/tmp/bclshell-$v_botang_ip

echo  "}" >>/root/tmp/bclshell-$v_botang_ip

echo  "EOF" >> /root/tmp/bclshell-$v_botang_ip

echo  "su - oracle -c \"sqlplus /nolog \" <<EOF "  >> /root/tmp/bclshell-$v_botang_ip

echo  "connsys/oracle_4U@\${v_dbname}1  as sysdba">>  /root/tmp/bclshell-$v_botang_ip

echo  "alter database flashback off;">>/root/tmp/bclshell-$v_botang_ip

echo  "alter database open resetlogs;">>/root/tmp/bclshell-$v_botang_ip

echo  "set echo off" >> /root/tmp/bclshell-$v_botang_ip

echo  "set feedback off" >> /root/tmp/bclshell-$v_botang_ip

echo  "@/home/oracle/rtable.sql;" >>  /root/tmp/bclshell-$v_botang_ip

echo  "quit">>  /root/tmp/bclshell-$v_botang_ip

echo  "EOF" >> /root/tmp/bclshell-$v_botang_ip

echo  "su - oracle -c \"sqlplus /nolog \" <<EOF "  >> /root/tmp/bclshell-$v_botang_ip

echo  "connsys/oracle_4U@\${v_dbname}2 as sysdba">> /root/tmp/bclshell-$v_botang_ip

echo  "alter database open;">>/root/tmp/bclshell-$v_botang_ip

echo  "quit">>  /root/tmp/bclshell-$v_botang_ip

echo  "EOF" >> /root/tmp/bclshell-$v_botang_ip

echo"fi" >>  /root/tmp/bclshell-$v_botang_ip

echo  "rm -f /home/oracle/rtable.sql" >>  /root/tmp/bclshell-$v_botang_ip

echo  " echo \"DELETE ARCHIVELOGS HAVE ALREADY BEEN RECOVERED FOR LAB15  SUCCESSFULLY,THE END AGAIN\"" >>  /root/tmp/bclshell-$v_botang_ip

scp -q -o  ConnectTimeout=1-o  StrictHostKeyChecking=no -o NumberOfPasswordPrompts=1 -o ConnectionAttempts=1  /root/tmp/bclshell-$v_botang_ip$v_botang_ip:/usr/bin/ >/dev/null  2>&1

scp -q -o  ConnectTimeout=1-o  StrictHostKeyChecking=no -o NumberOfPasswordPrompts=1 -o ConnectionAttempts=1  /root/tmp/bclsend-$v_botang_ip/rtable.sql$v_botang_ip:/home/oracle/ >/dev/null  2>&1

ssh -q -o  ConnectTimeout=1-o  StrictHostKeyChecking=no -o NumberOfPasswordPrompts=1 -o ConnectionAttempts=1  $v_botang_ipchmod +x  /usr/bin/bclshell-$v_botang_ip

(ssh -q -o  ConnectTimeout=1-o  StrictHostKeyChecking=no -o NumberOfPasswordPrompts=1 -o ConnectionAttempts=1  $v_botang_ip /usr/bin/bclshell-$v_botang_ip>>$i 2>&1)&

done

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

sub_getting 15 15_穿越incarnation不完全恢复

sub_detecting

sub_creating

sub_shutdowning_normal

sub_destroying "system*"

sub_destroying "undotbs1*"

sub_destroying "undotbs2*"

sub_destroying "sysaux*"

sub_destroying "example*"

sub_destroying "users*"

sub_revealing

echo " "

sub_startuping_node1mount

sub_clearing_excludertable

echo "THE END"

“sub_creating”

调用的“ctable.sql”内容:

--drop table hr.edu234;

--

set echo off

set feedback off

select* from sys.tname;

selectinstance_number  from v$instance;

create tablehr.edu234 (  a number ) tablespace users;

create tablehr.specialedu234( a varchar2(100)) tablespace users;

insert into hr.specialedu234 values('11g SUCCESS');

commit;

host sleep 5

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

selectsysdate from dual;

host sleep 3

truncate table hr.specialedu234;

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 * fromhr.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

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 * fromhr.edu234;

drop table hr.edu234 purge;

恢复要点:

注意:如果刚做完实验14,本场景之前,rever环境

1)启动到mountrman中:reset database to incarnation 2;

2)在rmanrun{}块中恢复:根据ctable.sql输出的时间set until timerestore databaserecover databasealter database open resetlogs;

2srvctl启动其他实例。


总结

推送+场景模拟”是本文的设计思想,希望对DBA演练备份恢复技术会有帮助。本文中所提及的所有原创程序均提供下载和md5sum文件。 读者使用这些程序不应出于商业目的,作者对使用这些程序可能带来的一切后果不承担任何法律责任。bcpbcl”的其他选项也能推送10g单机版环境、11g单机版环境和10gRAC环境,同时也能模拟10g单机版环境、11g单机版环境和10gRAC环境的备份恢复场景。请读者自行摸索这些功能。


你可能感兴趣的:(批量部署,Oracle脚本,RAC节点)