#### #### 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 #### |