一键DG脚本(静默安装建实例建DG)

本文发布时间: 2019-Mar-22
首先,这只是为了练习shell而写大神们不屑请别看不懂shell的可以看看,做个参考,把一些功能当做魔板我知道红黑联盟,linux公社等会盗转,所以提前问候你们全家了脚本大致步骤是:1.判断是否创建oracle用户,如果没有创建就创建,并设置密码为oracle2.解析config.conf文件,获取用户输入的SID等等参数3.做安装前的参数配置,创建所需目录4.安装数据库软件,配置监听,创建实例5.配置pfile,设置force_logging,传输数据文件到备库(没用rman duplicate,没有为什么)6.剩下就没啥了其实最后写完发现所有的建库所需参数均可以自己在脚本中生成.dbt文件,但是我就不改了#!/bin/bashecho '#################################################' echo '# #'echo '# #'echo '# FaN's Script #'echo '# #'echo '# #'echo '#################################################'service iptables stopSETPASSWD(){#set passwordexpect -c ' set timeout 2; spawn passwd oracle expect { password { send 'oracle'; exp_continue } *assword* { send 'oracle' } }; '}#create user and groupcat /etc/passwd|awk -F':' '{print $1}'|grep 'oracle>' > /dev/nullresult=$?if [ '$result' == '1' ];then echo 'user oracle does not exist,Starting to create user!' /usr/sbin/groupadd oinstall > /dev/null /usr/sbin/groupadd dba > /dev/null /usr/sbin/useradd -g oinstall -G dba -d /home/oracle oracle cat /etc/passwd|awk -F':' '{print $1}'|grep 'oracle>' > /dev/null result1=$? if [ '$result1' == '0' ];then echo 'user oracle has been created' else echo 'we has a few problems during creating the user,please check!' fi#set passwd SETPASSWD >> /dev/null echo ' The user oracle's password is set to oracle '#chown chmod for /oracle chown oracle:oinstall /oracle chmod 755 /oracle chown oracle:oinstall /oracle/711 chmod 755 /oracle/711elif [ '$result' == '0' ];then echo 'user oracle have already been created'fi#Parsing the config fileerrParam() { echo '[ERROR] `$1' is empty, check configfile '$configfile'' echo '' exit}SOFTWARE_HOME=ORACLE_SID=INVENTORY_LOCATION=ORACLE_BASE=ORACLE_HOME=DB_NAME=configfile=/oracle/711/config.confif [ -f $configfile ]; then param=$(cat $configfile | tr -d '' | grep -v '^#' | grep -v '^$')else echo '[ERROR] $configfile not found!' exitfiwhile read ido key=$(echo '$i' | awk -F'=' '{print $1}') value=$(echo '$i' | awk -F'=' '{print $2}') [ '$key' == 'SOFTWARE_HOME' ] && SOFTWARE_HOME=$value [ '$key' == 'ORACLE_SID' ] && ORACLE_SID=$value [ '$key' == 'INVENTORY_LOCATION' ] && INVENTORY_LOCATION=$value [ '$key' == 'ORACLE_HOME' ] && ORACLE_HOME=$value [ '$key' == 'ORACLE_BASE' ] && ORACLE_BASE=$value [ '$key' == 'DB_NAME' ] && DB_NAME=$value [ '$key' == 'ARCH' ] && ARCH=$value [ '$key' == 'P_DB' ] && P_DB=$value [ '$key' == 'P_IP' ] && P_IP=$value [ '$key' == 'S_DB' ] && S_DB=$value [ '$key' == 'S_IP' ] && S_IP=$value [ '$key' == 'P_B_UNIQUE_NAME' ] && P_B_UNIQUE_NAME=$value [ '$key' == 'S_B_UNIQUE_NAME' ] && S_B_UNIQUE_NAME=$value [ '$key' == 'ctl' ] && ctl=$valuedone <<< '$param'[ 'x$SOFTWARE_HOME' == 'x' ] && errParam SOFTWARE_HOME[ 'x$ORACLE_SID' == 'x' ] && ORACLE_SID=orcl[ 'x$INVENTORY_LOCATION' == 'x' ] && INVENTORY_LOCATION=/oracle/Inventory[ 'x$ORACLE_BASE' == 'x' ] && ORACLE_BASE=/oracle[ 'x$ORACLE_HOME' == 'x' ] && ORACLE_HOME=/oracle/db11g[ 'x$DB_NAME' == 'x' ] && DB_NAME=orcl[ 'x$ARCH' == 'x' ] && ARCH=/oracle/arch[ 'x$P_B_UNIQUE_NAME' == 'x' ] && P_B_UNIQUE_NAME=primary[ 'x$S_B_UNIQUE_NAME' == 'x' ] && S_B_UNIQUE_NAME=standbyechoecho '#################################################'echo 'SOFTWARE_HOME is $SOFTWARE_HOME'echo 'ORACLE_SID is $ORACLE_SID'echo 'INVENTORY_LOCATION is $INVENTORY_LOCATION'echo 'ORACLE_BASE is $ORACLE_BASE'echo 'ORACLE_HOME is $ORACLE_HOME'echo 'DB_NAME is $DB_NAME'echo 'Archivelogs are in $ARCH'#echo 'Controlfiles are in $ctl'echo '#################################################'#cont='&quot;$ctl&quot;'#调用slient_setup.sh为备库安装数据库软件echo 'starting install oracle software on standby'expect -c ' spawn ssh $S_IP expect { yes/no { send 'yes'; exp_continue } *assword* { send 'oracle' } } ; expect ]# { send 'cd /oracle/711 ' }; expect ]# { send 'sh /oracle/711/slient_setup.sh ' };# send ; expect eof ; 'set_host(){cat >> /etc/hosts << EOF$P_IP$P_DB$S_IP$S_DBEOF}set_host# Set up the shell variables:echo 'EDITOR=vi' >> /home/oracle/.bash_profileecho 'export EDITOR' >> /home/oracle/.bash_profileecho 'umask 022' >> /home/oracle/.bash_profileecho 'export ORACLE_SID=$ORACLE_SID' >> /home/oracle/.bash_profileecho 'export ORACLE_BASE=$ORACLE_BASE' >> /home/oracle/.bash_profileecho 'export ORACLE_HOME=$ORACLE_HOME' >> /home/oracle/.bash_profileecho 'export PATH=$ORACLE_HOME/bin:$GRID_HOME/bin:$PATH' >> /home/oracle/.bash_profileecho 'export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/rdbms/lib:/lib:/usr/lib' >> /home/oracle/.bash_profileecho 'export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$ORACLE_HOME/network/jlib' >> /home/oracle/.bash_profileecho 'stty erase ^h' >> /home/oracle/.bash_profile#preinstall echo '#add for database' >> /etc/sysctl.confecho 'fs.file-max = 6815744' >> /etc/sysctl.confecho 'net.ipv4.ip_local_port_range = 9000 65500' >> /etc/sysctl.confecho 'net.core.rmem_max=262144' >> /etc/sysctl.confecho 'net.core.rmem_max = 4194304' >> /etc/sysctl.confecho 'net.core.wmem_max=262144' >> /etc/sysctl.confecho 'net.core.wmem_max = 1048576' >> /etc/sysctl.confecho 'fs.aio-max-nr = 1048576' >> /etc/sysctl.confecho 'kernel.shmmni = 4096' >> /etc/sysctl.confecho 'kernel.shmmax = 957691904' >> /etc/sysctl.confecho 'kernel.shmall = 2097152' >> /etc/sysctl.confecho 'kernel.sem = 250 32000 100 128' >> /etc/sysctl.confecho 'net.core.rmem_default = 262144' >> /etc/sysctl.confecho 'net.core.wmem_default = 262144' >> /etc/sysctl.confsysctl -p >> /dev/nullecho 'oracle soft nproc 2047' >> /etc/security/limits.confecho 'oracle hard nproc 16384' >> /etc/security/limits.confecho 'oracle soft nofile 1024' >> /etc/security/limits.confecho 'oracle hard nofile 65536' >> /etc/security/limits.confecho 'session required pam_limits.so' >>/etc/pam.d/loginecho 'if [ $USER = 'oracle' ] || [ $USER = 'grid' ]; then' >> /etc/profileecho 'if [ $SHELL = '/bin/ksh' ]; then' >> /etc/profileecho 'ulimit -p 16384' >> /etc/profileecho 'ulimit -n 65536' >> /etc/profileecho 'else' >> /etc/profileecho 'ulimit -u 16384 -n 65536' >> /etc/profileecho 'fi' >> /etc/profileecho 'umask 022' >> /etc/profileecho 'fi' >> /etc/profile#make db_install.rspmk_db_install(){ echo 'oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0' >> db_install.rsp echo 'oracle.install.option=INSTALL_DB_SWONLY' >> db_install.rsp echo 'ORACLE_HOSTNAME=$HOSTNAME' >> db_install.rsp echo 'UNIX_GROUP_NAME=oinstall' >> db_install.rsp echo 'INVENTORY_LOCATION=$INVENTORY_LOCATION' >> db_install.rsp echo 'SELECTED_LANGUAGES=zh_CN,en' >> db_install.rsp echo 'ORACLE_HOME=$ORACLE_HOME' >> db_install.rsp echo 'ORACLE_BASE=$ORACLE_BASE' >> db_install.rsp echo 'oracle.install.db.InstallEdition=EE' >> db_install.rsp echo 'oracle.install.db.EEOptionsSelection=false' >> db_install.rsp echo 'oracle.install.db.optionalComponents=' >> db_install.rsp echo 'oracle.install.db.DBA_GROUP=dba' >> db_install.rsp echo 'oracle.install.db.OPER_GROUP=oinstall' >> db_install.rsp echo 'oracle.install.db.CLUSTER_NODES=' >> db_install.rsp echo 'oracle.install.db.isRACOneInstall=false' >> db_install.rsp echo 'oracle.install.db.racOneServiceName=' >> db_install.rsp echo 'oracle.install.db.config.starterdb.type=GENERAL_PURPOSE' >> db_install.rsp echo 'oracle.install.db.config.starterdb.globalDBName=' >> db_install.rsp echo 'oracle.install.db.config.starterdb.SID=' >> db_install.rsp echo 'oracle.install.db.config.starterdb.characterSet=' >> db_install.rsp echo 'oracle.install.db.config.starterdb.memoryOption=false' >> db_install.rsp echo 'oracle.install.db.config.starterdb.memoryLimit=' >> db_install.rsp echo 'oracle.install.db.config.starterdb.installExampleSchemas=false' >> db_install.rsp echo 'oracle.install.db.config.starterdb.enableSecuritySettings=true' >> db_install.rsp echo 'oracle.install.db.config.starterdb.password.ALL=' >> db_install.rsp echo 'oracle.install.db.config.starterdb.password.SYS=' >> db_install.rsp echo 'oracle.install.db.config.starterdb.password.SYSTEM=' >> db_install.rsp echo 'oracle.install.db.config.starterdb.password.SYSMAN=' >> db_install.rsp echo 'oracle.install.db.config.starterdb.password.DBSNMP=' >> db_install.rsp echo 'oracle.install.db.config.starterdb.control=DB_CONTROL' >> db_install.rsp echo 'oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL=' >> db_install.rsp echo 'oracle.install.db.config.starterdb.automatedBackup.enable=false' >> db_install.rsp echo 'oracle.install.db.config.starterdb.automatedBackup.osuid=' >> db_install.rsp echo 'oracle.install.db.config.starterdb.automatedBackup.ospwd=' >> db_install.rsp echo 'oracle.install.db.config.starterdb.storageType=' >> db_install.rsp echo 'oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=' >> db_install.rsp echo 'oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=' >> db_install.rsp echo 'oracle.install.db.config.asm.diskGroup=' >> db_install.rsp echo 'oracle.install.db.config.asm.ASMSNMPPassword=' >> db_install.rsp echo 'MYORACLESUPPORT_USERNAME=' >> db_install.rsp echo 'MYORACLESUPPORT_PASSWORD=' >> db_install.rsp echo 'SECURITY_UPDATES_VIA_MYORACLESUPPORT=false' >> db_install.rsp echo 'DECLINE_SECURITY_UPDATES=true' >> db_install.rsp echo 'PROXY_HOST=' >> db_install.rsp echo 'PROXY_PORT=' >> db_install.rsp echo 'PROXY_USER=' >> db_install.rsp echo 'PROXY_PWD=' >> db_install.rsp echo 'PROXY_REALM=' >> db_install.rsp echo 'COLLECTOR_SUPPORTHUB_URL=' >> db_install.rsp echo 'oracle.installer.autoupdates.option=SKIP_UPDATES' >> db_install.rsp echo 'oracle.installer.autoupdates.downloadUpdatesLoc=' >> db_install.rsp echo 'AUTOUPDATES_MYORACLESUPPORT_USERNAME=' >> db_install.rsp echo 'AUTOUPDATES_MYORACLESUPPORT_PASSWORD=' >> db_install.rsp}#mk db_install.rspmk_db_installechoecho 'db_install.rsp has been created'echo #chown chmod db_install.rspchown oracle:oinstall db_install.rspchmod 755 db_install.rsp#mkdir ORACLE_HOME ORACLE_BASE INVENTORY_LOCATIONif [ ! -d '$ORACLE_BASE' ];then mkdir -p $ORACLE_BASEfiif [ ! -d '$ORACLE_HOME' ];then mkdir -p $ORACLE_HOMEfiif [ ! -d '$INVENTORY_LOCATION' ];then mkdir -p $INVENTORY_LOCATIONfiif [ ! -d '$ARCH' ];then mkdir -p $ARCHfichown -R oracle:oinstall $ORACLE_BASEchown -R oracle:oinstall $ORACLE_HOMEchown -R oracle:oinstall $ARCHchown -R oracle:oinstall $INVENTORY_LOCATION#install oracle softwaresetupDatabase() { runStr=' cd $SOFTWARE_HOME nohup ./runInstaller -silent -force -responseFile /oracle/711/db_install.rsp >> /oracle/711/setupDatabase.out 2>&1 & ' su - oracle -c '$runStr' while true do echo -n '.' sleep 3s grep 'Successfully Setup Software' /oracle/711/setupDatabase.out >> /dev/null if [ $? -eq 0 ]; then sh ${INVENTORY_LOCATION}/orainstRoot.sh sh ${ORACLE_HOME}/root.sh break fi done}sleep 1secho 'steup oracle database...'setupDatabaseecho 'steup succsed.'echolistenrsp(){cat >> /oracle/711/listen.rsp << EOF[GENERAL]RESPONSEFILE_VERSION='11.2'CREATE_TYPE='CUSTOM'[oracle.net.ca]INSTALLED_COMPONENTS={'server','net8','javavm'}INSTALL_TYPE=''typical''LISTENER_NUMBER=1LISTENER_NAMES={'LISTENER'}LISTENER_PROTOCOLS={'TCP;1521'}LISTENER_START=''LISTENER''NAMING_METHODS={'TNSNAMES','ONAMES','HOSTNAME'}NSN_NUMBER=1NSN_NAMES={'EXTPROC_CONNECTION_DATA'}NSN_SERVICE={'PLSExtProc'}NSN_PROTOCOLS={'TCP;HOSTNAME;1521'}EOF}listenrspchown oracle:oinstall /oracle/711/listen.rspchmod 755 /oracle/711/listen.rspnetcac(){ cmd=' nohup netca -silent -responseFile /oracle/711/listen.rsp >> /oracle/711/netca.log 2>&1 & ' su - oracle -c '$cmd' while true do echo -n '.' sleep 1s grep -E 'The exit code is 0|退出代码是0' /oracle/711/netca.log >> /dev/null if [ $? -eq 0 ]; then echo 'Listener Successfully Created' break fi done}sleep 1secho 'starting create listener...'netcacecho 'Create Successfully'echo#不想创建实力只执行以上的内容就可以了mkdbcarsp(){cat >> /oracle/711/dbca.rsp << EOF[GENERAL]RESPONSEFILE_VERSION = '11.2.0'OPERATION_TYPE = 'createDatabase'[CREATEDATABASE]GDBNAME = '$DB_NAME'SID = '$ORACLE_SID'TEMPLATENAME = 'orcl.dbt'[createTemplateFromDB]SOURCEDB = 'myhost:1521:orcl'SYSDBAUSERNAME = 'system'TEMPLATENAME = 'My Copy TEMPLATE'[createCloneTemplate]SOURCEDB = 'orcl'TEMPLATENAME = 'My Clone TEMPLATE'[DELETEDATABASE]SOURCEDB = 'orcl'[generateScripts]TEMPLATENAME = 'New Database'GDBNAME = 'orcl11.us.oracle.com'[CONFIGUREDATABASE][ADDINSTANCE]DB_UNIQUE_NAME = 'orcl11g.us.oracle.com'NODELIST=SYSDBAUSERNAME = 'sys'[DELETEINSTANCE]DB_UNIQUE_NAME = 'orcl11g.us.oracle.com'INSTANCENAME = 'orcl11g'SYSDBAUSERNAME = 'sys'EOF}mkdbcarspval=$(cat /oracle/711/orcl7.dbt |grep 'log_archive_dest_1'|awk -F'=' '{print $4}'|awk -F''' '{print $1}')cp -p /oracle/711/orcl7.dbt ${ORACLE_HOME}/assistants/dbca/templates/orcl.dbteval sed -i 's#$val#$ARCH#' ${ORACLE_HOME}/assistants/dbca/templates/orcl.dbtcreate_db(){ cmd1=' nohup dbca -silent -createDatabase -responseFile /oracle/711/dbca.rsp -sysPassword 'oracle' -systemPassword 'oracle' >> /oracle/711/dbca.log 2>&1 & ' su - oracle -c '$cmd1' while true do echo -n '.' sleep 1s grep '100%' /oracle/711/dbca.log >> /dev/null if [ $? -eq 0 ]; then echo 'instance create Successfully' break fi done}sleep 1secho 'starting create instance...'create_dbechoecho 'Instance Create Successfully'###在这之上的是安装数据库软件并创建实例sleep 3s#force logging#!/bin/bashcrpfile(){su - oracle -c 'sqlplus -S / as sysdba << !set trimspool on feedback off pagesize 0 heading offcreate pfile='/home/oracle/initorcl.ora' from spfile;exit;!'}crpfile >> /oracle/711/dg.log 2>&1ad=$(cat /home/oracle/initorcl.ora |grep 'log_archive_dest_1='LOCATION')af=$(cat /home/oracle/initorcl.ora |grep 'log_archive_format')eval sed -i 's#$ad##' /home/oracle/initorcl.oraeval sed -i 's#$af##' /home/oracle/initorcl.oracp -p /home/oracle/initorcl.ora /home/oracle/initstandby.orastc=$(cat /home/oracle/initstandby.ora | grep 'control_files')audit=$(cat /home/oracle/initstandby.ora | grep 'audit_file_dest')eval sed -i 's#$stc##' /home/oracle/initstandby.oraeval sed -i 's#$audit##' /home/oracle/initstandby.ora#追加如下内容insersp(){cat >> /home/oracle/initorcl.ora << EOFDB_UNIQUE_NAME=$P_B_UNIQUE_NAMELOG_ARCHIVE_CONFIG='DG_CONFIG=($P_B_UNIQUE_NAME,$S_B_UNIQUE_NAME)'LOG_ARCHIVE_DEST_1= 'LOCATION=$ARCH VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=$P_B_UNIQUE_NAME'LOG_ARCHIVE_DEST_2= 'SERVICE=$S_B_UNIQUE_NAME SYNC AFFIRM NET_TIMEOUT=30 VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=$S_B_UNIQUE_NAME'LOG_ARCHIVE_DEST_STATE_1=ENABLELOG_ARCHIVE_DEST_STATE_2=ENABLEREMOTE_LOGIN_PASSWORDFILE=EXCLUSIVELOG_ARCHIVE_FORMAT=%t_%s_%r.arcLOG_ARCHIVE_MAX_PROCESSES=3FAL_SERVER=standbyDB_FILE_NAME_CONVERT='$ORACLE_BASE/oradata/standby','$ORACLE_BASE/oradata/$ORACLE_SID'LOG_FILE_NAME_CONVERT= '$ORACLE_BASE/oradata/standby','$ORACLE_BASE/oradata/$ORACLE_SID'STANDBY_FILE_MANAGEMENT=AUTOEOF}insersp >> /oracle/711/dg.log 2>&1cstdpfile(){cat >> /home/oracle/initstandby.ora << EOFcontrol_files='$ORACLE_BASE/oradata/standby/std_control01.ctl'audit_file_dest='/oracle/admin/standby/adump'DB_UNIQUE_NAME=$S_B_UNIQUE_NAMELOG_ARCHIVE_CONFIG='DG_CONFIG=($P_B_UNIQUE_NAME,$S_B_UNIQUE_NAME)'LOG_ARCHIVE_DEST_1= 'LOCATION=$ARCH VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=$S_B_UNIQUE_NAME'LOG_ARCHIVE_DEST_2= 'SERVICE=$P_B_UNIQUE_NAME SYNC AFFIRM NET_TIMEOUT=30 VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=$P_B_UNIQUE_NAME'LOG_ARCHIVE_DEST_STATE_1=ENABLELOG_ARCHIVE_DEST_STATE_2=ENABLEREMOTE_LOGIN_PASSWORDFILE=EXCLUSIVELOG_ARCHIVE_FORMAT=%t_%s_%r.arcLOG_ARCHIVE_MAX_PROCESSES=3FAL_SERVER=standbyDB_FILE_NAME_CONVERT='$ORACLE_BASE/oradata/$ORACLE_SID','$ORACLE_BASE/oradata/standby'LOG_FILE_NAME_CONVERT= '$ORACLE_BASE/oradata/$ORACLE_SID','$ORACLE_BASE/oradata/standby'STANDBY_FILE_MANAGEMENT=AUTOEOF}cstdpfile >> /oracle/711/dg.log 2>&1su - oracle -c 'sqlplus -S / as sysdba << !set trimspool on feedback off pagesize 0 heading offshutdown immediate;startup pfile='/home/oracle/initorcl.ora';shutdown immediate;create spfile from pfile='/home/oracle/initorcl.ora';startup mount;exit;!'#########现在是mountshutoracle(){Shut_Oracle_Down=$(su - oracle -c 'sqlplus -S / as sysdba << !set trimspool on feedback off pagesize 0 heading offshutdown immediate;exit;!')echo $Shut_Oracle_Down | grep 'ORACLE instance shut down'if [ $? -eq 0 ];then echo 'Instacne Shutdown Successfully!'else echo 'Instacne still open, please shutdown manual(you have two minute to shutdown the database!)' sleep 120sfi}mountoracle(){Mount_Oracle=$(su - oracle -c 'sqlplus -S / as sysdba << !set trimspool on feedback off pagesize 0 heading offstartup mount;exit;!')echo $Mount_Oracle | grep 'Database mounted'if [ $? -eq 0 ];then echo 'Database Mounted Successfully!'fi} alterforce(){alterlogging=$(su - oracle -c 'sqlplus -S / as sysdba << !set trimspool on feedback off pagesize 0 heading offalter database force logging;exit;!')}chklogging(){chk=$(su - oracle -c 'sqlplus -S / as sysdba << !set trimspool on feedback off pagesize 0 heading offselect force_logging from v\$database;exit;!')if [ '$chk' == 'NO' ];then echo 'force logging is NO'elif [ '$chk' == 'YES' ]; then echo 'force logging is enabled'fi}chkmount(){mountstat=$(su - oracle -c 'sqlplus -S / as sysdba << !set trimspool on feedback off pagesize 0 heading offselect status from v\$instance;exit;!')}####开始查看是否启用force loggingecho 'check force logging'force_logging=$(su - oracle -c 'sqlplus -S / as sysdba << !set trimspool on feedback off pagesize 0 heading offselect force_logging from v\$database;exit;!')if [ '$force_logging' == 'NO' ];then echo 'force logging is NO' echo 'startng alter database force logging' chkmount if [ 'mountstat' == 'MOUNTED' ];then #shutoracle alterforce chklogging else shutoracle mountoracle alterforce chklogging fielif [ '$force_logging' == 'YES' ];then echo 'force logging is enabled'fi#创建standby controlfilecsc(){su - oracle -c 'sqlplus -S / as sysdba << !set trimspool on feedback off pagesize 0 heading offALTER DATABASE CREATE STANDBY CONTROLFILE AS '/home/oracle/std_control01.ctl';exit;!'}findalert(){alertpath=$(su - oracle -c 'sqlplus -S / as sysdba << !set trimspool on feedback off pagesize 0 heading offselect value from v\$parameter where name='background_dump_dest';exit;!')}if [ '$mountstat' == 'MOUNTED' ];then csc if [ -f /home/oracle/std_control01.ctl ];then echo 'Standby Controlfile Create Successfully' else echo 'Faild To Create Standby Controlfile' fielse shutoracle echo $Shut_Oracle_Down | grep 'ORACLE instance shut down' if [ $? -eq 0 ];then mountoracle echo $Mount_Oracle | grep 'Database mounted' if [ $? -eq 0 ];then csc if [ -f /home/oracle/std_control01.ctl ];then echo 'Standby Controlfile Create Successfully' else echo 'Faild To Create Standby Controlfile' exit -1 fi fi fifisendpfile(){expect -c ' spawn scp /home/oracle/initstandby.ora [email protected]$S_IP:$ORACLE_HOME/dbs/initstandby.ora expect { yes/no { send 'yes'; exp_continue } *assword* { send 'oracle' } }; expect ] { send exit } ; expect 100% ; expect eof ; '}mkd_1(){expect -c ' spawn ssh [email protected]$S_IP expect { yes/no { send 'yes'; exp_continue } *assword* { send 'oracle' } } ; expect ] { send 'mkdir -p /oracle/oradata/standby ' }; expect eof ; '}mkd_2(){expect -c ' spawn ssh [email protected]$S_IP expect { yes/no { send 'yes'; exp_continue } *assword* { send 'oracle' } } ; expect ] { send 'mkdir -p /oracle/admin/standby/adump ' }; expect eof ; '}sendstdc(){expect -c ' spawn scp /home/oracle/std_control01.ctl [email protected]$S_IP:$ORACLE_BASE/oradata/standby/std_control01.ctl expect { yes/no { send 'yes'; exp_continue } *assword* { send 'oracle' } }; expect 100% expect eof ; '}sendsystem(){expect -c ' set timeout -1 spawn scp $ORACLE_BASE/oradata/$ORACLE_SID/system01.dbf [email protected]$S_IP:$ORACLE_BASE/oradata/standby/ expect { yes/no { send 'yes'; exp_continue } *assword* { send 'oracle' } }; expect 100% expect eof ; '}sendsysaux(){expect -c ' set timeout -1 spawn scp $ORACLE_BASE/oradata/$ORACLE_SID/sysaux01.dbf [email protected]$S_IP:$ORACLE_BASE/oradata/standby/ expect { yes/no { send 'yes'; exp_continue } *assword* { send 'oracle' } }; expect 100% expect eof ; '}sendtemp(){expect -c ' set timeout -1 spawn scp $ORACLE_BASE/oradata/$ORACLE_SID/temp01.dbf [email protected]$S_IP:$ORACLE_BASE/oradata/standby/ expect { yes/no { send 'yes'; exp_continue } *assword* { send 'oracle' } }; expect 100% expect eof ; '}sendundo(){expect -c ' set timeout -1 spawn scp $ORACLE_BASE/oradata/$ORACLE_SID/undotbs01.dbf [email protected]$S_IP:$ORACLE_BASE/oradata/standby/ expect { yes/no { send 'yes'; exp_continue } *assword* { send 'oracle' } }; expect 100% expect eof ; '}senduser(){expect -c ' set timeout -1 spawn scp $ORACLE_BASE/oradata/$ORACLE_SID/users01.dbf [email protected]$S_IP:$ORACLE_BASE/oradata/standby/ expect { yes/no { send 'yes'; exp_continue } *assword* { send 'oracle' } }; expect 100% expect eof ; '}sendpasswd(){expect -c ' spawn scp $ORACLE_HOME/dbs/orapw$ORACLE_SID [email protected]$S_IP:$ORACLE_HOME/dbs/orapwstandby expect { yes/no { send 'yes'; exp_continue } *assword* { send 'oracle' } }; expect 100% expect eof ; '}echo 'mkdir standby for standby'echosleep 3smkd_1 >> /oracle/711/dg.log 2>&1echo 'mkdir adump for standby'echosleep 3smkd_2 >> /oracle/711/dg.log 2>&1echo 'send orapw file to standby'echosleep 3ssendpasswd >> /oracle/711/dg.log 2>&1echo 'send pfile to standby'echosleep 3ssendpfile >> /oracle/711/dg.log 2>&1echo 'send standby controlfile to standby'echosleep 3ssendstdc >> /oracle/711/dg.log 2>&1echo 'send system.dbf to standby'echosleep 3ssendsystem >> /oracle/711/dg.log 2>&1echo 'send sysaux.dbf to standby'echosleep 3ssendsysaux >> /oracle/711/dg.log 2>&1echo 'send temp.dbf to standby'echosleep 3ssendtemp >> /oracle/711/dg.log 2>&1echo 'send undo.dbf to standby'echosleep 3ssendundo >> /oracle/711/dg.log 2>&1echo 'send user.dbf to standby'echo sleep 3ssenduser >> /oracle/711/dg.log 2>&1echo 'add tns'#tnscat >> $ORACLE_HOME/network/admin/tnsnames.ora << EOF$P_B_UNIQUE_NAME= (DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=$P_DB)(PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=$P_B_UNIQUE_NAME) (SERVER=DEDICATED) ) )$S_B_UNIQUE_NAME= (DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=$S_DB)(PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=$S_B_UNIQUE_NAME) (SERVER=DEDICATED) ) )EOFsendtns(){expect -c ' spawn scp $ORACLE_HOME/network/admin/tnsnames.ora [email protected]$S_IP:$ORACLE_HOME/network/admin/tnsnames.ora expect { yes/no { send 'yes'; exp_continue } *assword* { send 'oracle' } }; expect 100% expect eof ; '}echo 'send tns to standby'sendtns >> /oracle/711/dg.log 2>&1add_p_stdlog(){su - oracle -c 'sqlplus -S / as sysdba << !set trimspool on feedback off pagesize 0 heading offalter database add standby logfile '/oracle/oradata/$ORACLE_SID/std_redo01.log' size 50m;alter database add standby logfile '/oracle/oradata/$ORACLE_SID/std_redo02.log' size 50m;alter database add standby logfile '/oracle/oradata/$ORACLE_SID/std_redo03.log' size 50m;alter database add standby logfile '/oracle/oradata/$ORACLE_SID/std_redo04.log' size 50m;exit;!'}echo 'create standby redolog for primary'add_p_stdlog >> /oracle/711/dg.log 2>&1register(){su - oracle -c 'sqlplus -S / as sysdba << !set trimspool on feedback off pagesize 0 heading offalter system register;exit;!'}register >> /oracle/711/dg.log 2>&1#去备库mount 建standby redo#调用mount_standby.shexpect -c ' spawn ssh $S_IP expect { yes/no { send 'yes'; exp_continue } *assword* { send 'oracle' } } ; expect ] { send 'cd /oracle/711 ' }; expect ] { send 'sh /oracle/711/mount_standby.sh ' };# send ; expect eof ; '#至此主库mount,备库mountsleep 10s#open主库get_standby_status(){standby_status=$(su - oracle -c 'sqlplus -S sys/[email protected] as sysdba << !set trimspool on feedback off pagesize 0 heading offselect status from v\$instance;exit;!')}echoecho 'get standby status'get_stanby_statusecho $standby_statusopen(){su - oracle -c 'sqlplus -S / as sysdba << !set trimspool on feedback off pagesize 0 heading offalter database open;exit;!'}#if [ '$standby_status' == 'Mounted' ];then# echo '开始收尾工作open主库'# open >> /oracle/711/dg.log 2>&1#else# echo 'standby not mounted please check'# exit -1#fiwhile truedo get_standby_status if [ '$standby_status' == 'MOUNTED' ];then echo '开始收尾工作open主库' open >> /oracle/711/dg.log 2>&1 break fidoneexpect -c ' spawn ssh $S_IP expect { yes/no { send 'yes'; exp_continue } *assword* { send 'oracle' } } ; expect ] { send 'cd /oracle/711 ' }; expect ] { send 'sh /oracle/711/recover.sh ' };# send ; expect eof ; 'echo 'all done!' config文件类似于这样:# 指定软件存放目录SOFTWARE_HOME=/tmp/database#指定oracle实例名称,默认orclORACLE_SID=orcl#指定INVENTORYINVENTORY_LOCATION=/oracle/oraInventory#指定oracle基目录,默认/oracleORACLE_BASE=/oracle#SET ORACLE_HOME,默认/oracle/db11gORACLE_HOME=/oracle/db11g#SET DB_NAME,默认orclDB_NAME=orcl#指定归档路径,默认为{ORACLE_HOME}/archARCH=/oracle/arch#指定主库hostname,此脚本并不会配置按照您的填写配置主机名P_DB=master#指定主库的ip,此脚本并不会配置按照您的填写配置ipP_IP=192.168.134.139#指定备库hostname,此脚本并不会配置按照您的填写配置主机名S_DB=slave#指定备库的ip,此脚本并不会配置按照您的填写配置ipS_IP=192.168.134.134#指定主库B_UNIQUE_NAME,默认为primaryP_B_UNIQUE_NAME=primary#指定备库B_UNIQUE_NAME,默认为standbyS_B_UNIQUE_NAME=standby#指定控制文件,默认两个分别为{ORACLE_BASE}/oradata/{DB_UNIQUE_NAME}/control01.ctl和{ORACLE_BASE}/oradata/{DB_UNIQUE_NAME}/control02.ctl#ctl=/disk1/control01.ctl,/disk2/control02.ctl,/disk3/control03.ctl到这脚本没有完,具体看附件哦传不了附件,那就算了吧


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2019-May-25 12:56pm
栏目列表