为了账号安全,请及时绑定邮箱和手机立即绑定

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

标签:
Oracle


“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.tgzmhvtl

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

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 tablehr.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 tablehr.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 usersbegin 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)启动到mount在sqlplus中恢复:alter database end backup; alter database  open;

2)srvctl启动其他实例。

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 tablesys.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)启动到mount在rman中恢复:restore system表空间,recoversystem 表空间。

2)srvctl启动其他实例。

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 '原文件名';

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

3)recover datafile '新文件名' ;

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

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

在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 tablehr.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)启动到mount在rman的run{}块中恢复:根据ctable.sql输出的时间set until time;restore database;recover database;alter database open resetlogs;

2)srvctl启动其他实例。

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

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

drop table hr.edu234 purge;

恢复要点:

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

1)启动到mount在rman的run{}块中恢复:根据ctable.sql输出的日志序列号set until sequence xx thread x;restore database;recover database;alter database open resetlogs;

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

3)srvctl启动其他实例。

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

在PXE推送端主机上运行:

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

“bcl --RACGRID11g13 6b”之后会自动运行的 “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

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"

echo  "DELETE ARCHIVELOGS SUCCESSFULLY,THE END AGAIN" >> $i

done

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

sub_getting 6b 6b_基于cancel的不完全恢复

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_clearing

echo "THE END"

“sub_creating”

调用的“ctable.sql”内容:

同“6a_基于log序列号的不完全恢复”

恢复要点:

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

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

2)为了练习cancel语法,本实验在sqlplus进行。

3)启动到mount在rman中做一些预备工作:restore那些delete input 的archivelog;restore  database;

4)在sqlplus中恢复:recover  database until cancel; alter database open resetlogs;

5)srvctl启动其他实例。

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

在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

sub_creating

sub_shutdowning_normal

sub_destroying "group*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

“sub_creating”

调用的“ctable.sql”内容:

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

恢复要点:

1)启动到mount在sqlplus中恢复:recover  database until cancel; alter database open resetlogs;

2)srvctl启动其他实例。

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

在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

sub_creating

sub_shutdowning_abort

sub_destroying "group*"

sub_revealing

echo " "

sub_clearing

echo 'From then on, catalog your database, but use it or not depends  on you when recovering !!!'

echo "THE END"

“sub_creating”

调用的“ctable.sql”内容:

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

恢复要点:

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

1)先按7a做,会失败。失败时会提示在线日志文件current组的sequence号。日志序列号请用asmcmd确认。

2)在rman的run{}块中恢复:set until sequence 在线日志文件current组的sequence号thread x ; restore database;recover database;alterdatabase open resetlogs;

3)srvctl启动其他实例。

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

在PXE推送端主机上运行:

注意:此编号之后的实验,请准备好catalog。恢复目录存在于一台IP为192.168.0.90的主机上,服务名为“rcat.example.com”,监听端口为:“1521”。恢复目录用户名为“u90”,密码为“oracle_4U”。请事先准备好该设备。

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

sub_creating

sub_backingup_controlfile_nocatalog LABS-8A-CONTROLFILE

sub_resync_catalog

sub_shutdowning_abort

sub_destroying "current*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

“sub_creating”

调用的“ctable.sql”内容:

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

恢复要点:

1)启动到nomount在rman中恢复:restore controlfile;mount数据库

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

4)srvctl启动其他实例。

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

在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

sub_creating

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”内容:

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

恢复要点:

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

2)启动到nomount在sqlplus恢复:改cluster_database初始化参数为false;执行以上脚本;改cluster_database初始化参数为true;recover database;alter database open;

3)srvctl启动其他实例。

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

在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

sub_creating

sub_backingup_controlfile_nocatalog LABS-9A-CONTROL-BEFORE-OFFLINE

sub_offlining_users_nocatalog LABS-9A-USERS-AFTER-OFFLINE

sub_backingup_controlfile_nocatalog LABS-9A-CONTROL-AFTER-OFFLINE

sub_resync_catalog

sub_shutdowning_abort

sub_destroying "current*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

“sub_creating”

调用的“ctable.sql”内容:

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

恢复要点:

1)启动到nomount在rman中恢复:restore controlfile;mount数据库;用tag为“LABS-9A-CONTROL-BEFORE-OFFLINE”或tag为“LABS-9A-CONTROL-AFTER-OFFLINE”的控制文件备份来恢复都可以。控制文件能经历表空间从上线到下线的变化。

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

4)srvctl启动其他实例。

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

在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

sub_creating

echo "***BEFORE TABLESPACE OFFLINE***"

sub_scripting_controlfile_nocatalog

sub_offlining_users_nocatalog LABS-9B-USERS-AFTER-OFFLINE

echo "***AFTER TABLESPACE OFFLINE***"

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)启动到nomount在sqlplus恢复:改cluster_database初始化参数为false;执行以上脚本;改cluster_database初始化参数为true;recover database;alter database open;alter tablespace users online;

3)srvctl启动其他实例。

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

在PXE推送端主机上运行:

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

场景模拟脚本内容:

. /home/oracle/bclcustom-subprogram

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

sub_detecting

sub_creating

sub_backingup_controlfile_nocatalog LABS-9C-CONTR-BEFORE-READONLY

sub_readingonly_users_nocatalog LABS-9C-USERS-AFTER-READONLY

sub_backingup_controlfile_nocatalog LABS-9C-CONTROL-AFTER-READONLY

sub_resync_catalog

sub_shutdowning_abort

sub_destroying "current*"

sub_revealing

echo " "

sub_clearing

echo "THE END"

“sub_creating”

调用的“ctable.sql”内容:

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

恢复要点:

1)启动到nomount在rman中恢复:restore controlfile;mount数据库;用tag为“LABS-9C-CONTR-BEFORE-READONLY”或tag为“LABS-9C-CONTROL-AFTER-READONLY”的控制文件备份来恢复都可以。控制文件能经历表空间从读写到只读的变化。

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

4)srvctl启动其他实例。

©著作权归作者所有:来自51CTO博客作者botang的原创作品,如需转载,请注明出处,否则将追究法律责任

批量部署Oracle脚本RAC节点RAC


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消