├── Tips ├── Linux挂载cdrom.txt ├── 批量杀掉Oracle连接会话.txt ├── Linux如何查看CPU个数.txt ├── 终止Oracle中正在运行的RMAN备份任务.txt ├── 查看连接到Oracle服务器的应用或客户端的IP地址.txt ├── Linux如何查看进程的开始运行时间.txt ├── 清除OracleRAC日志.txt └── AIX主机查看CPU和内存参数.txt ├── rman_backup ├── rman_windows │ ├── README.md │ ├── rman_test.bat │ └── rman_test.txt ├── rman_backup_ASM.sh └── rman_backup.sh ├── rsync ├── remote_server_configuration │ ├── rsyncd.secrets │ ├── rsyncd.motd │ └── rsyncd.conf ├── local_server_configuration │ └── rsyncd.conf ├── rsync_backup_with_log_refresh.sh └── README.md ├── rman_validate ├── README.md └── rman_validate_v2.sh ├── purge_listener_xml └── purge_listener_xml.sh ├── oracle_service ├── automatically_open_oracle.sh ├── oracle └── README.md ├── linux_logo └── buddha_bless_never_downtime.sh ├── check_rac_res ├── check_rac_res_status_2.sh └── check_rac_res_status.sh ├── ssh └── local_trust_ssh_remote.txt ├── adg ├── del_standby_arch.sh ├── check_stb_arch_apply.sh ├── rman_del_arch_mm_seq.sh ├── check_dg_redo_apply.sql └── check_dg_redo_apply.sh ├── rman_backup_and_restore_experiment ├── README_CN.TXT ├── README.md ├── README_EN.TXT ├── scp_log_file_to_target.sh ├── rman_validate_v2.sh ├── ssh_mutual_trust_linux_for_source.sh └── ssh_mutual_trust_linux_for_target.sh ├── exp ├── exp_test_and_del_yesterday.sh └── exp_test_and_del_yesterday_2.sh ├── oracle_logo_banner ├── oracle_logo_2.sh ├── oracle_logo_3.sh └── oracle_logo.sh ├── statistics_all_disk_files ├── statistics_all_disk_files_2.txt ├── statistics_all_disk_files.sh ├── statistics_all_disk_files_2.sh └── statistics_all_disk_files.txt ├── get_client_ip ├── get_client_ip.sh └── get_client_ip.ksh ├── expdp ├── expdp_test_and_del_yesterday.sh └── expdp_test_and_del_yesterday_2.sh ├── check_arch_used_percent └── check_arch_used_percent.sh ├── shell_demo ├── test_mkdir.sh ├── check_shell_command_return_value.sh └── check_oracle_instance_nums.sh ├── batch_remove └── batch_remove_listener_xml_on_2018.sh ├── rotate_process_file ├── back_and_clean_alert_log.sh ├── retention_expdp_test_dump_file_2days.sh ├── back_and_clean_listener_log.sh └── rotate_reserve_base_dmp.sh ├── dig_listener_log_xml └── dig_ip_via_listener_log_xml.sh ├── README.md ├── recognize_dg_arch └── oracle_dg_arch_recognize.sh └── scp └── scp_expdp_parallel_local_to_remote.sh /Tips/Linux挂载cdrom.txt: -------------------------------------------------------------------------------- 1 | mount -t iso9660,ro /dev/sr0 /media -------------------------------------------------------------------------------- /Tips/批量杀掉Oracle连接会话.txt: -------------------------------------------------------------------------------- 1 | kill -9 `ps -ef | grep LOCAL=NO | awk '{print $2}'` 2 | -------------------------------------------------------------------------------- /rman_backup/rman_windows/README.md: -------------------------------------------------------------------------------- 1 | # "rman_test.txt" must be located on "e:\backup\". 2 | -------------------------------------------------------------------------------- /rsync/remote_server_configuration/rsyncd.secrets: -------------------------------------------------------------------------------- 1 | # Username:Password 2 | oracle:complexpassword 3 | -------------------------------------------------------------------------------- /Tips/Linux如何查看CPU个数.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Linux-Shell-Scripts/HEAD/Tips/Linux如何查看CPU个数.txt -------------------------------------------------------------------------------- /Tips/终止Oracle中正在运行的RMAN备份任务.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Linux-Shell-Scripts/HEAD/Tips/终止Oracle中正在运行的RMAN备份任务.txt -------------------------------------------------------------------------------- /Tips/查看连接到Oracle服务器的应用或客户端的IP地址.txt: -------------------------------------------------------------------------------- 1 | netstat -np | grep 1521 | awk -F ' ' '{print $5}' | awk -F ':' '{print $1}' | sort -h | uniq -c -------------------------------------------------------------------------------- /rman_backup/rman_windows/rman_test.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set oracle_sid=test 4 | 5 | D:\oracle\ora92\bin\rman target sys/xxxx@test nocatalog cmdfile='e:\backup\rman_test.txt' log 'e:\backup\test\log\%date:~0,4%_%date:~5,2%_%date:~8,2%.log' 6 | -------------------------------------------------------------------------------- /rman_validate/README.md: -------------------------------------------------------------------------------- 1 | # RMAN Validate 2 | 3 | * [rman_validate_v2.sh](https://github.com/guestart/Linux-Shell-Scripts/blob/master/rman_validate/rman_validate_v2.sh) - This shell script file used to validate rman backupset of all that is generated last night (One week is a rman backup recycle). 4 | -------------------------------------------------------------------------------- /rsync/remote_server_configuration/rsyncd.motd: -------------------------------------------------------------------------------- 1 | # The motd file with rsyncd is located in the remote oracle database server. 2 | +++++++++++++++++++++++++++++++++++++++++++++ 3 | Welcome to use the oracle rsync services! 4 | 2021 5 | +++++++++++++++++++++++++++++++++++++++++++++ 6 | -------------------------------------------------------------------------------- /Tips/Linux如何查看进程的开始运行时间.txt: -------------------------------------------------------------------------------- 1 | [root@xxxx ~]# service crond status 2 | crond (pid 46777) is running... 3 | 4 | [root@xxxx ~]# ps -ef | grep crond 5 | root 17074 32610 0 17:36 pts/10 00:00:00 grep crond 6 | root 46777 1 0 2022 ? 00:00:40 crond 7 | 8 | [root@xxxx ~]# ps -eo pid,lstart,etime | grep 46777 9 | 46777 Sat Nov 19 20:33:43 2022 110-21:00:32 10 | [root@xxxx ~]# -------------------------------------------------------------------------------- /rman_backup/rman_windows/rman_test.txt: -------------------------------------------------------------------------------- 1 | run{ 2 | CONFIGURE RETENTION POLICY TO REDUNDANCY 7; 3 | configure controlfile autobackup on; 4 | configure controlfile autobackup format for device type disk to 'E:\backup\test\%F'; 5 | allocate channel c1 type disk ; 6 | backup database format 'e:\backup\test\test_db_%U' 7 | plus archivelog format 'e:\backup\test\test_arc_%U'; 8 | release channel c1; 9 | 10 | } 11 | 12 | crosscheck backupset; 13 | 14 | delete noprompt obsolete; 15 | -------------------------------------------------------------------------------- /rsync/remote_server_configuration/rsyncd.conf: -------------------------------------------------------------------------------- 1 | # The configuration file of rsyncd is located in the remote oracle database server. 2 | # 3 | pid file = /var/run/rsyncd.pid 4 | port = 873 5 | address = xx.xxx.x.xx 6 | uid = root 7 | gid = root 8 | use chroot = no 9 | read only = yes 10 | hosts allow = xx.xxx.xx.xx/255.255.255.255 xx.xxx.x.xx/255.255.255.255 11 | hosts deny = * 12 | max connections = 5 13 | motd file = /etc/rsyncd.motd 14 | transfer logging = yes 15 | log format = %t %a %m %f %b 16 | log file = /var/log/rsyncd.log 17 | lock file = /var/run/rsyncd.lock 18 | secrets file = /etc/rsyncd.secrets 19 | 20 | [prodb1] 21 | comment = my rsync prodb1 22 | list = no 23 | ignore errors 24 | path = /home/oracle/rman_backup 25 | auth users = oracle 26 | secrets file = /etc/rsyncd.secrets 27 | -------------------------------------------------------------------------------- /Tips/清除OracleRAC日志.txt: -------------------------------------------------------------------------------- 1 | [root@yyds01 ~]# crontab -l 2 | 00 09 * * 1,5 ~/clear_rac_log.sh 3 | 4 | vi clear_rac_log.sh 5 | 6 | #!/bin/bash 7 | 8 | disk_avail_size=`df -h | grep "/" | head -1 | awk -F ' ' '{print $5}' | awk -F '%' '{print $1}'` 9 | 10 | if [ ${disk_avail_size} -ge 80 ]; then 11 | find /u01/app/grid/diag/tnslsnr/yyds01/listener/trace -name "listener_*.log" -exec rm -rf {} \; 12 | find /u01/app/grid/diag/tnslsnr/yyds01/listener/alert -name "log_*.xml" -exec rm -rf {} \; 13 | find /u01/app/grid/diag/tnslsnr/yyds01/listener_scan1/alert -name "log_*.xml" -exec rm -rf {} \; 14 | find /u01/app/grid/diag/tnslsnr/yyds01/listener_scan1/trace -name "listener_scan1_*.log" -exec rm -rf {} \; 15 | find /u01/app/grid/diag/tnslsnr/yyds01/asmnet1lsnr_asm/trace -name "asmnet1lsnr_asm_*.log" -exec rm -rf {} \; 16 | find /u01/app/grid/diag/crs/yyds01/crs/trace -name "*" -exec rm -rf {} \; 17 | find /u01/app/oracle/diag/rdbms/yydsdb/yydsdb1/trace -name "*.tr*" -exec rm -rf {} \; 18 | fi -------------------------------------------------------------------------------- /rsync/local_server_configuration/rsyncd.conf: -------------------------------------------------------------------------------- 1 | # The configure file of rsyncd is located in oracle sync backup server. 2 | # /etc/rsyncd: configuration file for rsync daemon mode 3 | 4 | # See rsyncd.conf man page for more options. 5 | 6 | # configuration example: 7 | 8 | # uid = nobody 9 | # gid = nobody 10 | # use chroot = yes 11 | # max connections = 4 12 | # pid file = /var/run/rsyncd.pid 13 | # exclude = lost+found/ 14 | # transfer logging = yes 15 | # timeout = 900 16 | # ignore nonreadable = yes 17 | # dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 18 | 19 | pid file = /var/run/rsyncd.pid 20 | port = 873 21 | address = xx.xxx.xx.xx 22 | uid = root 23 | gid = root 24 | use chroot = no 25 | read only = yes 26 | hosts allow = xx.xxx.xx.xx/255.255.255.255 xx.xxx.x.xx/255.255.255.255 27 | hosts deny = * 28 | max connections = 5 29 | motd file = /etc/rsyncd.motd 30 | transfer logging = yes 31 | log format = %t %a %m %f %b 32 | log file = /var/log/rsyncd.log 33 | lock file = /var/run/rsyncd.lock 34 | -------------------------------------------------------------------------------- /purge_listener_xml/purge_listener_xml.sh: -------------------------------------------------------------------------------- 1 | [grid@xxxx01 ~]$ cat /home/oracle/purge_listener_xml.sh 2 | #!/bin/bash 3 | source ~/.bash_profile 4 | 5 | lsnr_used_ratio=`df -h /u01 | grep -v "Filesystem" | xargs | awk -F ' ' '{print $5}' | awk -F '%' '{print $1}'` 6 | 7 | if [ ${lsnr_used_ratio} -ge 75 ]; then 8 | rm -rf /u01/app/oracle/diag/tnslsnr/xxxx01/listener/alert/log_*.xml 9 | rm -rf /u01/app/11.2.0/grid/log/diag/tnslsnr/xxxx01/listener_scan1/alert/log_*.xml 10 | fi 11 | 12 | [grid@xxxx02 ~]$ cat /home/oracle/purge_listener_xml.sh 13 | #!/bin/bash 14 | source ~/.bash_profile 15 | 16 | lsnr_used_ratio=`df -h /u01 | grep -v "Filesystem" | xargs | awk -F ' ' '{print $5}' | awk -F '%' '{print $1}'` 17 | 18 | if [ ${lsnr_used_ratio} -ge 75 ]; then 19 | rm -rf /u01/app/oracle/diag/tnslsnr/xxxx02/listener/alert/log_*.xml 20 | rm -rf /u01/app/11.2.0/grid/log/diag/tnslsnr/xxxx02/listener_scan1/alert/log_*.xml 21 | fi 22 | 23 | [grid@xxxx01 ~]$ crontab -l 24 | 00 20 * * * /home/grid/purge_listener_xml.sh 25 | 26 | [grid@xxxx02 ~]$ crontab -l 27 | 00 20 * * * /home/grid/purge_listener_xml.sh 28 | -------------------------------------------------------------------------------- /oracle_service/automatically_open_oracle.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export ECHO=`which echo` 4 | export SU=`which su` 5 | 6 | export ORA_OWNER=oracle 7 | export ORA_HOME=`$SU - ${ORA_OWNER} -c "dbhome"` 8 | export ORA_LOGFILE=/var/log/oracle.log 9 | 10 | $ECHO "$0 : (start oracle database ...)" 11 | $SU - ${ORA_OWNER} -c "${ORA_HOME}/bin/dbstart ${ORA_HOME}" >> ${ORA_LOGFILE} 12 | 13 | # You need invoke this SHELL script in /etc/rc.local in order to be able to 14 | # automatically startup oracle database after restarting server. 15 | # 16 | # Such as, the following demo: 17 | # [root@prodb1 ~]# cat /etc/rc.local 18 | # !/bin/sh 19 | # 20 | # This script will be executed *after* all the other init scripts. 21 | # You can put your own initialization stuff in here if you don't 22 | # want to do the full Sys V style init stuff. 23 | # 24 | # touch /var/lock/subsys/local 25 | # 26 | # Startup rsyncd process 27 | # /usr/bin/rsync --daemon --port=873 --config=/etc/rsyncd.conf >/dev/null 2>&1 28 | # 29 | # Automatically Startup Oracle Database Instance after restarting server 30 | # sh /home/oracle/automatically_open_oracle.sh 31 | -------------------------------------------------------------------------------- /linux_logo/buddha_bless_never_downtime.sh: -------------------------------------------------------------------------------- 1 | # Put the following stuff to '/etc/motd' which has been written permission by root user on generic Linux. 2 | # 3 | # _oo8oo_ 4 | # o8888888o 5 | # 88" . "88 6 | # (| -_- |) 7 | # 0\ = /0 8 | # ___/'==='\___ 9 | # .' \\| |// '. 10 | # / \\||| : |||// \ 11 | # / _||||| -:- |||||_ \ 12 | # | | \\\ - /// | | 13 | # | \_| ''\---/'' |_/ | 14 | # \ .-\__ '-' __/-. / 15 | # ___'. .' /--.--\ '. .'___ 16 | # ."" '< '.___\_<|>_/___.' >' "". 17 | # | | : `- \`.:`\ _ /`:.`/ -` : | | 18 | # =====`-.____`.___ \_____/ ___.`____.-`===== 19 | # `=---=` 20 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 21 | # Buddha bless Never downtime 22 | # 23 | -------------------------------------------------------------------------------- /check_rac_res/check_rac_res_status_2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | db_version=`sqlplus -s / as sysdba < /tmp/all_rac_res.txt 15 | 16 | all_rac_res_name=$(crsctl stat res | grep -E "NAME" | awk -F '=' '{print $2}' | awk -F '(' '{print $1}') 17 | 18 | for arrn in ${all_rac_res_name} 19 | do 20 | crsctl stat res ${arrn} -l | grep -v "DEGREE_ID" | xargs >> /tmp/all_rac_res.txt 21 | done 22 | 23 | def_offline_rac_res_name="ora.gsd ora.helper ora.proxy_advm ora.rhpserver ora.mgmt.ghchkpt.acfs ora.MGMT.GHCHKPT.advm" 24 | 25 | > /tmp/def_offline_rac_res.txt 26 | 27 | for dorrn in ${def_offline_rac_res_name} 28 | do 29 | crsctl stat res ${dorrn} -l | grep -v "CRS-2613" | grep -v "DEGREE_ID" | xargs >> /tmp/def_offline_rac_res.txt 30 | done 31 | 32 | sed -i '/^$/d' /tmp/def_offline_rac_res.txt 33 | 34 | echo -e "The TARGET and STATE status of rac resource is OFFLINE, INTERMEDIATE, or UNKNOWN, which is as below: \n" 35 | 36 | grep -F -v -f /tmp/def_offline_rac_res.txt /tmp/all_rac_res.txt | grep -E "OFFLINE|INTERMEDIATE|UNKNOWN" 37 | -------------------------------------------------------------------------------- /ssh/local_trust_ssh_remote.txt: -------------------------------------------------------------------------------- 1 | ======================================================= 2 | 配置 本地服务器 SSH信任 远程服务器 3 | [oracle@orcl1 ~]$ ssh-keygen -t rsa 4 | Enter file in which to save the key (/home/oracle/.ssh/id_rsa):回车 5 | Created directory '/home/oracle/.ssh'. 6 | Enter passphrase (empty for no passphrase):回车 7 | Enter same passphrase again:回车 8 | Your identification has been saved in /home/oracle/.ssh/id_rsa. 9 | Your public key has been saved in /home/oracle/.ssh/id_rsa.pub. 10 | The key fingerprint is: 11 | 28:aa:fc:b5:17:55:87:1d:1e:8e:88:e3:78:fd:e3:21 oracle@orcl1 12 | 13 | [oracle@orcl1 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub oracle@orcl2 14 | The authenticity of host 'orcl2 (xxx.xxx.x.xxx)' can't be established. 15 | RSA key fingerprint is 7e:fc:21:bc:d7:48:0e:fd:97:c9:f7:e6:90:c7:44:c4. 16 | Are you sure you want to continue connecting (yes/no)? yes回车 17 | Warning: Permanently added 'orcl2,xxx.xxx.x.xxx' (RSA) to the list of known hosts. 18 | oracle@orcl2's password:输入密码(不回显)回车 19 | Now try logging into the machine,with "ssh 'oracle@orcl2'",and check in: 20 | 21 | .ssh/authorized_keys 22 | 23 | to make sure we haven't added extra keys that you weren't expecting. 24 | 25 | [oracle@orcl1 ~]$ ssh orcl2 26 | Last login: Fri Feb 24 14:44:36 2017 from orcl1 27 | [oracle@orcl2 ~]$ 28 | -------------------------------------------------------------------------------- /adg/del_standby_arch.sh: -------------------------------------------------------------------------------- 1 | DG备库上新增 定时删除已经应用的归档日志的计划任务 2 | 3 | $ mkdir -p ~/del_standby_arch 4 | $ cd del_standby_arch/ 5 | $ mkdir -p ./log 6 | $ 7 | $ vi del_standby_arch.sh 8 | #!/bin/bash 9 | source ~/.bash_profile; 10 | dt=`date +%Y%m%d_%H%M%S` 11 | log="/home/oracle/del_standby_arch/log/del_standby_arch_${dt}.log" 12 | 13 | $ORACLE_HOME/bin/sqlplus -silent "/ as sysdba" << EOF > ${log} 14 | set heading off; 15 | set pagesize 0; 16 | set term off; 17 | set feedback off; 18 | set linesize 32767; 19 | select substr(name, 1) 20 | select case substr(name, 1, 1) 21 | when '/' then 'rm -f ' 22 | when '+' then 'asmcmd rm -f ' 23 | end || name from v\$archived_log 24 | where APPLIED = 'YES' 25 | and DELETED = 'NO'; 26 | exit; 27 | EOF 28 | 29 | awk '{ if (NR == (total-4)) print $0 }' total=$(wc -l < ${log}) ${log} 30 | sh ${log} 31 | 32 | # 或如果在ASM环境 33 | # for ln in `cat ${log} | wc -l | head -n-5` 34 | # do 35 | # asmcmd << EOF 36 | # ${ln} 37 | # exit; 38 | # EOF 39 | # done 40 | 41 | $ORACLE_HOME/bin/rman target / << EOF 42 | crosscheck archivelog all; 43 | delete noprompt expired archivelog all; 44 | crosscheck archivelog all; 45 | exit; 46 | EOF 47 | 48 | $ chmod a+x ./del_standby_arch.sh 49 | 50 | $ crontab -l 51 | 00 08 * * 1,5 /home/oracle/del_standby_arch/del_standby_arch.sh 52 | -------------------------------------------------------------------------------- /rman_backup_and_restore_experiment/README_CN.TXT: -------------------------------------------------------------------------------- 1 | ---- 2 | 总述 3 | ---- 4 | 5 | 这个“README_CN.TXT”文件是专门用于在Oracle数据库服务器上做RMAN备份和恢复实验的。 6 | 有两台Oracle数据库服务器,一台是源Oracle数据库,即生产环境;另一台是目标Oracle数据库, 7 | 它只安装了Linux操作系统和Oracle数据库软件。我们需要在这台服务器上用源Oracle数据库 8 | 的RMAN备份集恢复出一个数据库。 9 | 10 | -------------------------------------------------------- 11 | 整个RMAN恢复过程包括5个SHELL脚本文件(包括每个脚本文件的介绍) 12 | -------------------------------------------------------- 13 | 14 | -- 1. ssh_mutual_trust_linux_for_source.sh ==> ( 在源主机上设置目标主机的SSH互信功能 ) 15 | -- 2. ssh_mutual_trust_linux_for_target.sh ==> ( 在目标主机上设置源主机的SSH互信功能 ) 16 | -- 3. collect_info_from_source_oracle.sh ==> ( 从源主机收集一些信息 ) 17 | -- 4. scp_log_file_to_target.sh ==> ( 远程复制文件"/tmp/source_oracle_dbinfo.log"到目标主机 ) 18 | -- 5. rman_restore_and_recover_to_target_oracle.sh ==> ( 用RMAN还原和恢复Oracle到目标主机 ) 19 | 20 | ------------------ 21 | 执行SHELL脚本的流程 22 | ------------------ 23 | 24 | 所有的SHELL脚本都是在Oracle用户下执行。 25 | 26 | (1) 在源和目标的Oracle数据库服务器上设置SSH互信功能,即在源主机上执行脚本"ssh_mutual_trust_linux_for_source.sh", 27 | 在目标主机上执行脚本"ssh_mutual_trust_linux_for_target.sh"; 28 | 29 | (2) 在源主机上执行脚本"collect_info_from_source_oracle.sh"用来收集一些基本信息,然后再执行脚本"scp_log_file_to_target.sh", 30 | 即远程复制文件"/tmp/source_oracle_dbinfo.log"到目标主机的"/tmp"目录; 31 | 32 | (3) 在目标主机执行脚本"rman_restore_and_recover_to_target_oracle.sh",用来还原和恢复Oracle数据库。 33 | -------------------------------------------------------------------------------- /exp/exp_test_and_del_yesterday.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # The crontab setting on oracle user of linux server is as follows: 4 | 5 | # 00 18 * * * ~/rman_backup/exp_test_and_del_yesterday.sh >>/dev/null 2>&1 6 | 7 | ################################################## 8 | # Export environment variable of oracle user 9 | 10 | source ~/.bash_profile; 11 | 12 | export ORACLE_BASE=/u01/app/oracle 13 | 14 | export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 15 | 16 | export NLS_LANG=AMERICAN_AMERICA.AL32UTF8 17 | 18 | export EXP=$ORACLE_HOME/bin/exp 19 | 20 | ################################################## 21 | # Define some shell variables 22 | 23 | export ECHO=`which echo` 24 | 25 | export RM=`which rm` 26 | 27 | export DATE=`which date` 28 | 29 | export CURRENT_DATE=`$DATE +%Y%m%d%H%M%S` 30 | 31 | ########################################################################### 32 | # Export and generate dmp and log file of Oracle user about test 33 | # via exp command 34 | 35 | $EXP test/xxxx@test file=~/rman_backup/exp_test_${CURRENT_DATE}.dmp log=~/rman_backup/exp_test_${CURRENT_DATE}.log owner=test 36 | 37 | ########################################################## 38 | 39 | if [ `$ECHO $?` -eq 0 ]; then 40 | 41 | # Switch current directory to exp_dir 42 | 43 | cd ~/rman_backup 44 | 45 | # Remove dmp and log file yesterday,only reserve today's 46 | 47 | $RM -rf test_`$DATE -d'yesterday' +%Y%m%d`* 48 | 49 | fi 50 | -------------------------------------------------------------------------------- /adg/check_stb_arch_apply.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | oracle_version=$1 3 | oracle_sid=$2 4 | source ~/${oracle_version}_${oracle_sid}.env; 5 | if [ ! -f ~/tmp/${oracle_sid}/thread_arch_seq/thread_arch_seq.txt ]; then 6 | mkdir -p ~/tmp/${oracle_sid} 7 | touch ~/tmp/${oracle_sid}/thread_arch_seq/thread_arch_seq.txt 8 | fi 9 | sqlplus -S / as sysdba << EOF 10 | spool /home/oracle/tmp/${oracle_sid}/thread_arch_seq/thread_arch_seq.txt 11 | set echo off 12 | set trimspool on 13 | set trimout on 14 | set termout on 15 | set heading off 16 | set feedback off 17 | select thread# || ' ' || min(sequence#) || ' ' || max(sequence#) as thread_mm_seq from v\$archived_log where APPLIED = 'YES' and DELETED = 'NO' group by thread# order by thread#; 18 | spool off 19 | exit 20 | EOF 21 | 22 | 或 23 | 24 | #!/bin/bash 25 | oracle_version=$1 26 | oracle_sid=$2 27 | source ~/${oracle_version}_${oracle_sid}.env; 28 | if [ ! -f ~/tmp/${oracle_sid}/thread_arch_seq/thread_arch_seq.txt ]; then 29 | mkdir -p ~/tmp/${oracle_sid} 30 | touch ~/tmp/${oracle_sid}/thread_arch_seq/thread_arch_seq.txt 31 | fi 32 | sqlplus -S / as sysdba << EOF > ~/tmp/${oracle_sid}/thread_arch_seq/thread_arch_seq.txt 33 | set echo off 34 | set trimspool on 35 | set trimout on 36 | set termout on 37 | set heading off 38 | set feedback off 39 | select thread# || ' ' || min(sequence#) || ' ' || max(sequence#) as thread_mm_seq from v\$archived_log where APPLIED = 'YES' and DELETED = 'NO' group by thread# order by thread#; 40 | exit 41 | EOF 42 | -------------------------------------------------------------------------------- /oracle_logo_banner/oracle_logo_2.sh: -------------------------------------------------------------------------------- 1 | # Put the following stuff to '/etc/motd' which has been written permission by root user on generic Linux. 2 | 3 | ###################################################################################### 4 | # # 5 | # +-------+ +------- + +-------/ + +-------/ (R) # 6 | # ( ) | ) / \ ( | ( # 7 | # ( ) | ) / \ ( | ( # 8 | # ( ) |------ / \ ( | (-------/ # 9 | # ( ) | \ / ----- \ ( | ( # 10 | # ( ) | \ | | ( | / ( # 11 | # +-------+ - -- - - +-------/ +-------+ +-------/ # 12 | # # 13 | # # 14 | # +----------------------------------+ # 15 | # | Applications & Platform Services | # 16 | # +----------------------------------+ # 17 | # # 18 | ###################################################################################### 19 | -------------------------------------------------------------------------------- /oracle_logo_banner/oracle_logo_3.sh: -------------------------------------------------------------------------------- 1 | # Put the following stuff to '/etc/motd' which has been written permission by root user on generic Linux. 2 | 3 | ############################################################################################################### 4 | # # 5 | # +----------+ +--------- -+- +----------+ + + +-----------+ (R) # 6 | # ( ---------- ) | --------) / - \ ( ----------/ | | - ----------/ # 7 | # ( ( ) ) | | ) ) / / \ \ ( ( | | ( ( # 8 | # ( ( ) ) | | ) ) / / \ \ ( ( | | ( ( # 9 | # ( ( ) ) | |----- ) / / \ \ / / | | / / +++++++++ # 10 | # ( ( ) ) | |----- / / \-----\ \ ( ( | | ( ( # 11 | # ( ( ) ) | | \ \ / / \------\ \ ( ( | | ( ( # 12 | # ( ---------- ) | | \ \ | | | | ( ----------+ | ----------+ - ----------+ # 13 | # +----------+ - - ----- - - - - +----------/ +----------/ +----------/ # 14 | # # 15 | ############################################################################################################### 16 | -------------------------------------------------------------------------------- /exp/exp_test_and_del_yesterday_2.sh: -------------------------------------------------------------------------------- 1 | # Author: Quanwen Zhao 2 | # Last Updated: Jul 11, 2019 3 | 4 | #!/bin/bash 5 | 6 | # The crontab setting on oracle user of linux server is as follows: 7 | 8 | # 00 18 * * * ~/rman_backup/exp_test_and_del_yesterday.sh >>/dev/null 2>&1 9 | 10 | ################################################## 11 | # Export environment variable of oracle user 12 | 13 | source ~/.bash_profile; 14 | 15 | export ORACLE_BASE=/u01/app/oracle 16 | 17 | export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 18 | 19 | export NLS_LANG=AMERICAN_AMERICA.AL32UTF8 20 | 21 | export EXP=$ORACLE_HOME/bin/exp 22 | 23 | ################################################## 24 | # Define some shell variables 25 | 26 | export ECHO=`which echo` 27 | 28 | export RM=`which rm` 29 | 30 | export DATE=`which date` 31 | 32 | export CURRENT_DATE=`$DATE +%Y%m%d%H%M%S` 33 | 34 | ########################################################################### 35 | # Export and generate dmp and log file of Oracle user about test 36 | # via exp command 37 | # adding four number of new parameters - "direct, buffer, feedback and recordlength" 38 | 39 | $EXP test/xxxx@test file=~/rman_backup/exp_test_${CURRENT_DATE}.dmp log=~/rman_backup/exp_test_${CURRENT_DATE}.log owner=test direct=y buffer=10240000 feedback=10000 recordlength=65535 40 | 41 | ########################################################## 42 | 43 | if [ `$ECHO $?` -eq 0 ]; then 44 | 45 | # Switch current directory to exp_dir 46 | 47 | cd ~/rman_backup 48 | 49 | # Remove dmp and log file yesterday,only reserve today's 50 | 51 | $RM -rf test_`$DATE -d'yesterday' +%Y%m%d`* 52 | 53 | fi 54 | -------------------------------------------------------------------------------- /statistics_all_disk_files/statistics_all_disk_files_2.txt: -------------------------------------------------------------------------------- 1 | +---------+ 2 | | *HDB* | 3 | +---------+ 4 | 5 | 20180627040001 - 20180629040001 6 | 7 | Total Nums: 3 8 | 9 | +---------+ 10 | | *HDC* | 11 | +---------+ 12 | 13 | Total Nums: 0 14 | 15 | +---------+ 16 | | *HDD* | 17 | +---------+ 18 | 19 | Total Nums: 0 20 | 21 | +---------+ 22 | | *HDE* | 23 | +---------+ 24 | 25 | 20171023040001 - 20180221040001 26 | 27 | Total Nums: 35 28 | 29 | +---------+ 30 | | *HDF* | 31 | +---------+ 32 | 33 | 20180222040001 - 20180322040001 34 | 35 | Total Nums: 29 36 | 37 | +---------+ 38 | | *HDG* | 39 | +---------+ 40 | 41 | 20180323040001 - 20180418040001 42 | 43 | Total Nums: 26 44 | 45 | +---------+ 46 | | *HDH* | 47 | +---------+ 48 | 49 | 20180419040002 - 20180513040001 50 | 51 | Total Nums: 25 52 | 53 | +---------+ 54 | | *HDI* | 55 | +---------+ 56 | 57 | 20180514040002 - 20180605040001 58 | 59 | Total Nums: 23 60 | 61 | +---------+ 62 | | *HDJ* | 63 | +---------+ 64 | 65 | 20180606040002 - 20180626040001 66 | 67 | Total Nums: 21 68 | 69 | +---------+ 70 | | *HDK* | 71 | +---------+ 72 | 73 | 20170120040001 - 20170127040001 74 | 75 | Total Nums: 8 76 | 77 | +---------+ 78 | | *HDL* | 79 | +---------+ 80 | 81 | 20170128040001 - 20170204040001 82 | 83 | Total Nums: 8 84 | 85 | +---------+ 86 | | *HDM* | 87 | +---------+ 88 | 89 | 20170205040001 - 20170212040002 90 | 91 | Total Nums: 8 92 | 93 | +---------+ 94 | | *HDN* | 95 | +---------+ 96 | 97 | 20170213040001 - 20170220040001 98 | 99 | Total Nums: 8 100 | 101 | +---------+ 102 | | *HDO* | 103 | +---------+ 104 | 105 | 20170221040001 - 20170225040001 106 | 107 | Total Nums: 5 108 | -------------------------------------------------------------------------------- /adg/rman_del_arch_mm_seq.sh: -------------------------------------------------------------------------------- 1 | -- https://blog.csdn.net/zr3036720790/article/details/129351309 2 | -- 形如 3 | -- 1 443 3958 4 | -- 2 200 4000 5 | -- 多行的thread_arch_seq.txt文件, 用for循环前需要加 IFS=$'\n' 6 | 7 | -- https://blog.csdn.net/theonegis/article/details/52751238/ 8 | -- 或者使用while循环 while read -r ln 9 | 10 | 11 | #!/bin/bash 12 | oracle_version=$1 13 | oracle_sid=$2 14 | source ~/${oracle_version}_${oracle_sid}.env; 15 | IFS=$'\n' 16 | sed -i '/^$/d' ~/tmp/${oracle_sid}/thread_arch_seq/thread_arch_seq.txt 17 | for ln in `cat ~/tmp/${oracle_sid}/thread_arch_seq/thread_arch_seq.txt` 18 | do 19 | threadN=`echo ${ln}` 20 | tn=`echo ${threadN} | awk -F ' ' '{print $1}'` 21 | arch_min_seq=`echo ${threadN} | awk -F ' ' '{print $2}'` 22 | arch_max_seq=`echo ${threadN} | awk -F ' ' '{print $3}'` 23 | rman target / << EOF > ~/tmp/bstsdb/thread_arch_seq/thread_arch_del_seq.log 24 | crosscheck archivelog all; 25 | delete noprompt archivelog from sequence ${arch_min_seq} until sequence `expr ${arch_max_seq} - 5` thread ${tn}; 26 | crosscheck archivelog all; 27 | exit; 28 | EOF 29 | done 30 | 31 | 32 | -- 在Linux平台下 33 | -- Error 处理: /bin/bash^M: bad interpreter: No such file or directory 34 | -- 35 | -- 解决办法: 使用在终端输入 sed -i 's/\r$//' sh文件名 36 | -- 37 | -- 原因:sh文件在Windows的记事本中编辑过, 在Windows下每一行结尾是\n\r, 而Linux下则是\n, 38 | -- 在Windows下编辑过的sh文件在Linux下打开看的时候 每一行的结尾就会多出一个字符\r. 39 | -- 40 | -- 用 cat -A sh文件名 会看到这个\r字符被显示为^M. 41 | -- 或 cat -vET sh文件名 42 | -- 43 | -- A就是all, 所有的都显示, 也就是说\n\r默认不显示. 44 | -- 45 | -- 怎么删除掉呢? 46 | -- 47 | -- 正则表达式 sed -i 's/\r$//' sh文件名 48 | -- 49 | -- -i 插入 50 | -- s 替代模式 51 | -- \r$ 表示任何以\r结束的字符 52 | -- 53 | -- 整句意思就是 把以\r结束的字符换在空白 54 | 55 | 56 | -- 在Windows平台下 57 | -- 在Windows下notepad++编辑的shell脚本文件, 选择 视图 -> 显示符号 -> 显示行尾符 (和字符集无关) 58 | -- 会看到CRLF, 即 \n\r 59 | -- 按Ctrl+H, 调出替换对话框, 查找\n\r, 替换为\n, 点 全部替换. 60 | -------------------------------------------------------------------------------- /Tips/AIX主机查看CPU和内存参数.txt: -------------------------------------------------------------------------------- 1 | -- AIX主机管理-查看CPU和内存参数 2 | -- https://blog.csdn.net/oradbm/article/details/124565324 3 | 4 | -- 查看逻辑CPU个数 5 | 6 | [xxxxxx:root:/] pmcycles -m 7 | CPU 0 runs at 4208 MHz 8 | CPU 1 runs at 4208 MHz 9 | CPU 2 runs at 4208 MHz 10 | CPU 3 runs at 4208 MHz 11 | CPU 4 runs at 4208 MHz 12 | CPU 5 runs at 4208 MHz 13 | CPU 6 runs at 4208 MHz 14 | CPU 7 runs at 4208 MHz 15 | CPU 8 runs at 4208 MHz 16 | CPU 9 runs at 4208 MHz 17 | CPU 10 runs at 4208 MHz 18 | CPU 11 runs at 4208 MHz 19 | CPU 12 runs at 4208 MHz 20 | CPU 13 runs at 4208 MHz 21 | CPU 14 runs at 4208 MHz 22 | CPU 15 runs at 4208 MHz 23 | CPU 16 runs at 4208 MHz 24 | CPU 17 runs at 4208 MHz 25 | CPU 18 runs at 4208 MHz 26 | CPU 19 runs at 4208 MHz 27 | CPU 20 runs at 4208 MHz 28 | CPU 21 runs at 4208 MHz 29 | CPU 22 runs at 4208 MHz 30 | CPU 23 runs at 4208 MHz 31 | 32 | -- 查看物理CPU个数 33 | 34 | [xxxxxx:root:/] prtconf|grep Processors 35 | Number Of Processors: 12 36 | 37 | -- 查看内存 38 | 39 | (1) a. lsdev -Cc memory b. lsattr -El mem0 40 | 41 | lsdev -Cc memory 42 | 43 | [xxxxxx:root:/] lsdev -Cc memory 44 | L2cache0 Available L2 Cache 45 | mem0 Available Memory 46 | 47 | lsattr -El mem0 48 | 49 | [xxxxxx:root:/] lsattr -El mem0 50 | ent_mem_cap I/O memory entitlement in Kbytes False 51 | goodsize 102400 Amount of usable physical memory in Mbytes False 52 | mem_exp_factor Memory expansion factor False 53 | size 102400 Total amount of physical memory in Mbytes False 54 | var_mem_weight Variable memory capacity weight False 55 | 56 | (2) bootinfo -r 57 | 58 | [xxxxxx:root:/] bootinfo -r 59 | 104857600 60 | 61 | 说明机器的物理内存为104857600kB。 62 | 63 | (3) prtconf | grep "Memory Size" 64 | 65 | [xxxxxx:root:/] prtconf | grep "Memory Size" 66 | Memory Size: 102400 MB 67 | Good Memory Size: 102400 MB 68 | -------------------------------------------------------------------------------- /rman_backup_and_restore_experiment/README.md: -------------------------------------------------------------------------------- 1 | # RMAN Backup and Restore Experiment 2 | 3 | ### Readme: 4 | 5 | * [README_EN.TXT](https://github.com/guestart/Linux-Shell-Scripts/blob/master/rman_backup_and_restore_experiment/README_EN.TXT) - The english version of introducing each shell script file's meaning and the order to execute it 6 | 7 | * [README_CN.TXT](https://github.com/guestart/Linux-Shell-Scripts/blob/master/rman_backup_and_restore_experiment/README_CN.TXT) - The chinese version of introducing each shell script file's meaning and the order to execute it 8 | 9 | ### Entire Shell Scripts: 10 | 11 | * [ssh_mutual_trust_linux_for_source.sh](https://github.com/guestart/Linux-Shell-Scripts/blob/master/rman_backup_and_restore_experiment/ssh_mutual_trust_linux_for_source.sh) - Set target host's ssh mutual trust function on source host 12 | 13 | * [ssh_mutual_trust_linux_for_target.sh](https://github.com/guestart/Linux-Shell-Scripts/blob/master/rman_backup_and_restore_experiment/ssh_mutual_trust_linux_for_target.sh) - Set source host's ssh mutual trust function on target host 14 | 15 | * [collect_info_from_source_oracle.sh](https://github.com/guestart/Linux-Shell-Scripts/blob/master/rman_backup_and_restore_experiment/collect_info_from_source_oracle.sh) - Collect some information from source host 16 | 17 | * [scp_log_file_to_target.sh](https://github.com/guestart/Linux-Shell-Scripts/blob/master/rman_backup_and_restore_experiment/scp_log_file_to_target.sh) - Scp file "/tmp/source_oracle_dbinfo.log" to target host 18 | 19 | * [rman_restore_and_recover_to_target_oracle.sh](https://github.com/guestart/Linux-Shell-Scripts/blob/master/rman_backup_and_restore_experiment/rman_restore_and_recover_to_target_oracle.sh) - Use rman restore and recover oracle to target host 20 | 21 | ### RMAN Validate: 22 | 23 | * [rman_validate_v2.sh](https://github.com/guestart/Linux-Shell-Scripts/blob/master/rman_backup_and_restore_experiment/rman_validate_v2.sh) - Validate the rman backupset on source host 24 | -------------------------------------------------------------------------------- /rman_backup_and_restore_experiment/README_EN.TXT: -------------------------------------------------------------------------------- 1 | ------- 2 | Summary 3 | ------- 4 | 5 | This is the "README_EN.TXT" file for doing rman backup and recovery experiment on 6 | oracle database server. There are two oracle database server, one is source 7 | oracle database and it's production environment; another is target oracle 8 | database and it has only insalled linux and oracle database software, we need 9 | to restore and recover a oracle database with source oracle's rman backupsets. 10 | 11 | ----------------------------------------------------------------------------------- 12 | Entire rman restore process include five shell scripts and introduction per script: 13 | ----------------------------------------------------------------------------------- 14 | 15 | -- 1. ssh_mutual_trust_linux_for_source.sh ==> ( set target host's ssh mutual trust function on source host ) 16 | 17 | -- 2. ssh_mutual_trust_linux_for_target.sh ==> ( set source host's ssh mutual trust function on target host ) 18 | 19 | -- 3. collect_info_from_source_oracle.sh ==> ( collect some information from source host ) 20 | 21 | -- 4. scp_log_file_to_target.sh ==> ( scp file "/tmp/source_oracle_dbinfo.log" to target host ) 22 | 23 | -- 5. rman_restore_and_recover_to_target_oracle.sh ==> ( use rman restore and recover oracle to target host ) 24 | 25 | ----------------------------- 26 | Execute shell script process: 27 | ----------------------------- 28 | 29 | All of shell scripts are executed on oracle user. 30 | 31 | (1) set ssh mutual trust function between source oracle database and target 32 | oracle database, and execute script "ssh_mutual_trust_linux_for_source.sh" in source host 33 | and execute script "ssh_mutual_trust_linux_for_target.sh" in target host. 34 | 35 | (2) execute script "collect_info_from_source_oracle.sh" for collect some information 36 | on source host,and then execute script "scp_log_file_to_target.sh", scp file 37 | "/tmp/source_oracle_dbinfo.log" to dir "/tmp" of target host. 38 | 39 | (3) execute script "rman_restore_and_recover_to_target_oracle.sh" on target host for 40 | restoreing and recovering oracle database. 41 | -------------------------------------------------------------------------------- /get_client_ip/get_client_ip.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | chmod +s `which netstat`; 4 | 5 | # lsnr_port=`su - oracle -c "lsnrctl status | grep PORT | tail -1 | awk -F '=' '{print \$6}' | awk -F ')' '{print \$1}'"` 6 | lsnr_port=$(su - oracle -c "lsnrctl status | grep PORT | tail -1 | awk -F '=' '{print \$6}' | awk -F ')' '{print \$1}'") 7 | 8 | su - oracle -c "netstat -antp | grep ${lsnr_port} | grep -v "asm_" | grep -v "ora_" | grep -v "tnslsnr" | grep "ESTABLISHED" | awk -F ' ' '{print \$7,\$5}' | awk -F ':' '{print \$1}' | tr '/' ' ' | awk -F ' ' '{print \$1,\$3}'" > /tmp/spid_and_ip.txt 9 | 10 | su - oracle -c "sqlplus -s / as sysdba" < s.machine 60 | ORDER BY i.instance_number 61 | ) 62 | SELECT s.*, c.ip_addr 63 | FROM sess s, clientip c 64 | WHERE s.spid = c.spid; 65 | exit; 66 | eof 67 | -------------------------------------------------------------------------------- /rman_backup/rman_backup_ASM.sh: -------------------------------------------------------------------------------- 1 | # RMAN Configuration 2 | 3 | # CONFIGURE RETENTION POLICY TO REDUNDANCY 3; 4 | # CONFIGURE CONTROLFILE AUTOBACKUP ON; 5 | # CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '+BACK/%F'; 6 | 7 | # cd /app/oracle 8 | # mkdir -p rman_backup/log 9 | # cd rman_backup 10 | 11 | # ASM BACKUP DISK is "+BACK". 12 | 13 | $ cat rman_back.sh 14 | 15 | #!/bin/bash 16 | 17 | source ~/.bash_profile; 18 | 19 | export DATE=`which date` 20 | 21 | export DATE_W=`$DATE +%u` 22 | 23 | export CURRENT_DATE=`$DATE +%F` 24 | 25 | export RMAN=$ORACLE_HOME/bin 26 | 27 | export BACK_LOG='/app/oracle/rman_backup/log' 28 | 29 | # One week rman backup of incremental level 0 on Saturday and incremental level 1 on Sunday ~ Friday at 01:00 am. 30 | 31 | case $DATE_W in 32 | 33 | 5) 34 | 35 | $RMAN/rman nocatalog log $BACK_LOG/level0_$CURRENT_DATE.log <>/dev/null 2>&1 9 | 10 | ################################################## 11 | # Export environment variable of oracle user 12 | 13 | source ~/.bash_profile; 14 | 15 | export NLS_LANG=AMERICAN_AMERICA.AL32UTF8 16 | 17 | export EXPDP=$ORACLE_HOME/bin/expdp 18 | 19 | ################################################## 20 | # Define some shell variables 21 | 22 | export ECHO=`which echo` 23 | 24 | export RM=`which rm` 25 | 26 | export DATE=`which date` 27 | 28 | export CURRENT_DATE=`$DATE +%Y%m%d%H%M%S` 29 | 30 | ############################################################################### 31 | # Export and generate dmp and log file of Oracle user about test 32 | # via expdp command 33 | 34 | # $EXPDP test/xxxx@test schemas=test directory=expdp parallel=3 dumpfile=expdp_test_${CURRENT_DATE}_%U.dmp filesize=50G logfile=expdp_test_${CURRENT_DATE}.log statistics=none 35 | # If using the above expdp command as you can see the below export message warnings. 36 | 37 | # Export: Release 11.2.0.4.0 - Production on Fri Jul 5 14:28:51 2019 38 | 39 | # Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. 40 | 41 | # Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production 42 | # With the Partitioning, Oracle Label Security, OLAP, Data Mining, 43 | # Oracle Database Vault and Real Application Testing options 44 | # Legacy Mode Active due to the following parameters: 45 | # Legacy Mode Parameter: "statistics=none" Location: Command Line, ignored. <<== 46 | # Legacy Mode has set reuse_dumpfiles=true parameter. 47 | # ...... 48 | 49 | # Use the following right expdp command to exclude both statistics, because of the previous expdp command still export the statistics info. 50 | $EXPDP test/xxxx@test schemas=test directory=expdp parallel=3 dumpfile=expdp_test_${CURRENT_DATE}_%U.dmp filesize=50G logfile=expdp_test_${CURRENT_DATE}.log exclude=statistics 51 | 52 | ########################################################## 53 | 54 | if [ `$ECHO $?` -eq 0 ]; then 55 | 56 | # Switch current directory to expdp 57 | 58 | cd ~/rman_backup/expdp 59 | 60 | # Remove dmp and log file yesterday,only reserve today's 61 | 62 | $RM -rf expdp_test_`$DATE -d'yesterday' +%Y%m%d`*.dmp 63 | 64 | fi 65 | -------------------------------------------------------------------------------- /expdp/expdp_test_and_del_yesterday_2.sh: -------------------------------------------------------------------------------- 1 | # Author: Quanwen Zhao 2 | # Last Updated: Jul 11, 2019 3 | 4 | #!/bin/bash 5 | 6 | # The crontab setting on oracle user of linux server is as follows: 7 | 8 | # 00 04 * * * ~/rman_backup/expdp_test_and_del_yesterday.sh >>/dev/null 2>&1 9 | 10 | ################################################## 11 | # Export environment variable of oracle user 12 | 13 | source ~/.bash_profile; 14 | 15 | export NLS_LANG=AMERICAN_AMERICA.AL32UTF8 16 | 17 | export EXPDP=$ORACLE_HOME/bin/expdp 18 | 19 | ################################################## 20 | # Define some shell variables 21 | 22 | export ECHO=`which echo` 23 | 24 | export RM=`which rm` 25 | 26 | export DATE=`which date` 27 | 28 | export CURRENT_DATE=`$DATE +%Y%m%d%H%M%S` 29 | 30 | ############################################################################### 31 | # Export and generate dmp and log file of Oracle user about test 32 | # via expdp command 33 | 34 | # $EXPDP test/xxxx@test schemas=test directory=expdp parallel=3 dumpfile=expdp_test_${CURRENT_DATE}_%U.dmp filesize=50G logfile=expdp_test_${CURRENT_DATE}.log statistics=none 35 | # If using the above expdp command as you can see the below export message warnings. 36 | 37 | # Export: Release 11.2.0.4.0 - Production on Fri Jul 5 14:28:51 2019 38 | 39 | # Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. 40 | 41 | # Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production 42 | # With the Partitioning, Oracle Label Security, OLAP, Data Mining, 43 | # Oracle Database Vault and Real Application Testing options 44 | # Legacy Mode Active due to the following parameters: 45 | # Legacy Mode Parameter: "statistics=none" Location: Command Line, ignored. <<== 46 | # Legacy Mode has set reuse_dumpfiles=true parameter. 47 | # ...... 48 | 49 | # Use the following right expdp command to exclude both statistics, because of the previous expdp command still export the statistics info. 50 | # $EXPDP test/xxxx@test schemas=test directory=expdp parallel=3 dumpfile=expdp_test_${CURRENT_DATE}_%U.dmp filesize=50G logfile=expdp_test_${CURRENT_DATE}.log exclude=statistics 51 | 52 | # Adding a new parameter compression. 53 | $EXPDP test/xxxx@test schemas=test directory=expdp parallel=3 dumpfile=expdp_test_${CURRENT_DATE}_%U.dmp filesize=50G logfile=expdp_test_${CURRENT_DATE}.log exclude=statistics compression=all 54 | 55 | ########################################################## 56 | 57 | if [ `$ECHO $?` -eq 0 ]; then 58 | 59 | # Switch current directory to expdp 60 | 61 | cd ~/rman_backup/expdp 62 | 63 | # Remove dmp and log file yesterday,only reserve today's 64 | 65 | $RM -rf expdp_test_`$DATE -d'yesterday' +%Y%m%d`*.dmp 66 | 67 | fi 68 | -------------------------------------------------------------------------------- /adg/check_dg_redo_apply.sql: -------------------------------------------------------------------------------- 1 | -- ----------------------------------------------------------------- 2 | -- 3 | -- FileName : check_dg_redo_apply.sql 4 | -- 5 | -- Description : This sql script used to check redo data apply on 6 | -- 7 | -- Oracle DataGuard physical standby database. 8 | -- 9 | -- Author : Quanwen Zhao 10 | -- 11 | -- Create Date : 2017/07/11 12 | -- 13 | -- ----------------------------------------------------------------- 14 | 15 | SET heading ON 16 | SET trimspool ON 17 | SET newpage NONE 18 | SET echo OFF 19 | SET feedback OFF 20 | SET verify OFF 21 | SET define OFF 22 | SET termout OFF 23 | SET timing OFF 24 | SET colsep "|" 25 | 26 | SET linesize 400 27 | SET pagesize 200 28 | 29 | ---------------------------------------------------------------- 30 | -- Query value of current date oracle physical standby database 31 | ---------------------------------------------------------------- 32 | 33 | COL current_scn FOR 9999999999999999 34 | 35 | SELECT scn_to_timestamp(current_scn) FROM v$database; 36 | 37 | PROMPT 38 | 39 | --------------------------------------------------------------------------------- 40 | -- Query max value of sequence# and applied's status is yes by 'v$archived_log' 41 | --------------------------------------------------------------------------------- 42 | 43 | SELECT MAX(sequence#) FROM v$archived_log WHERE applied='YES'; 44 | 45 | PROMPT 46 | 47 | -------------------------------------------------------------------------------- 48 | -- Query max value of sequence# and applied's status is no by 'v$archived_log' 49 | -------------------------------------------------------------------------------- 50 | 51 | SELECT MAX(sequence#) FROM v$archived_log WHERE applied='NO'; 52 | 53 | PROMPT 54 | 55 | ---------------------------------------------------------------------------- 56 | -- Query value of 'process','pid','status' and etc. by 'v$managed_standby' 57 | ---------------------------------------------------------------------------- 58 | 59 | SELECT process,pid,status,sequence#,block#,blocks,delay_mins FROM v$managed_standby; 60 | 61 | PROMPT 62 | 63 | ---------------------------------------------------------------------- 64 | -- Query value of 'sequence#','status','archived' by 'v$standby_log' 65 | ---------------------------------------------------------------------- 66 | 67 | SELECT sequence#,status,archived FROM v$standby_log; 68 | 69 | PROMPT 70 | 71 | ------------------------------------------- 72 | -- Query all value by 'v$dataguard_stats' 73 | ------------------------------------------- 74 | 75 | COL name FOR a24 76 | COL value FOR a12 77 | COL unit FOR a28 78 | COL time_computed FOR a20 79 | COL datum_time FOR a20 80 | 81 | SELECT * FROM v$dataguard_stats; 82 | -------------------------------------------------------------------------------- /rman_backup_and_restore_experiment/scp_log_file_to_target.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # +-----------------------------------------------------------------------+ 4 | # | Quanwen Zhao | 5 | # | guestart@163.com | 6 | # | quanwenzhao.wordpress.com | 7 | # |-----------------------------------------------------------------------| 8 | # | Copyright (c) 2016-2017 Quanwen Zhao. All rights reserved. | 9 | # |-----------------------------------------------------------------------| 10 | # | DATABASE : Oracle | 11 | # | OS ENV : Linux | 12 | # | File : scp_log_file_to_target.sh | 13 | # | CLASS : LINUX Bourne-Again Shell Scripts | 14 | # | PURPOSE : This bash script file used to remote copy a local log | 15 | # | file to remote host. | 16 | # | | 17 | # | PARAMETERS : None. | 18 | # | | 19 | # | MODIFIED : 03/10/2017 (mm/dd/yyyy) | 20 | # | | 21 | # | NOTE : As with any code, ensure to test this script in a | 22 | # | development environment before attempting to run it in | 23 | # | production. | 24 | # +-----------------------------------------------------------------------+ 25 | 26 | # +-----------------------------------------------------------------------+ 27 | # | EXPORT ENVIRONMENT VARIABLE OF ORACLE USER | 28 | # +-----------------------------------------------------------------------+ 29 | 30 | source ~/.bash_profile; 31 | 32 | # +-----------------------------------------------------------------------+ 33 | # | GLOBAL VARIABLES ABOUT STRINGS AND BACKTICK EXECUTION RESULT OF SHELL | 34 | # +-----------------------------------------------------------------------+ 35 | 36 | export SCP=`which scp` 37 | 38 | export LOCAL_LOGFILE='/tmp/source_oracle_dbinfo.log' 39 | 40 | # Define Remote Host, For example, REMOTE_HOST='orcl1', According to your situation to set. 41 | export REMOTE_HOST='orcl13' 42 | 43 | # +-----------------------------------------------------------------------+ 44 | # | USE SCP COMMAND TO COPY A LOCAL LOG FILE TO TARGET HOST | 45 | # +-----------------------------------------------------------------------+ 46 | 47 | $SCP $LOCAL_LOGFILE oracle@$REMOTE_HOST:/tmp 48 | -------------------------------------------------------------------------------- /check_arch_used_percent/check_arch_used_percent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source ~/.bash_profile; 4 | 5 | arch_log_list=`sqlplus -s / as sysdba < /tmp/socket_and_spid.txt 10 | 11 | # Similarly the above suggestion it is the best to execute the following command via root user, if via oracle user, aix will report "awk: 0602-502 The statement cannot be correctly parsed". 12 | netstat -Aan | grep ${real_lsnr_port} | grep "ESTABLISHED" | awk -F ' ' '{print $1,$6}' | awk -F '.' '{print $1"."$2"."$3"."$4}' > /tmp/socket_and_ip.txt 13 | 14 | # To prevent outputing "[YOU HAVE NEW MAIL]" on any operation step of AIX we add ">>/dev/null" deliberately. 15 | su - oracle -c "sqlplus -s / as sysdba" <>/dev/null 16 | set feedback off 17 | create or replace directory exttab as '/tmp'; 18 | drop table socket_and_spid purge; 19 | create table socket_and_spid ( 20 | socket varchar2(20), 21 | spid varchar2(24) 22 | ) organization external 23 | ( type oracle_loader 24 | default directory exttab 25 | access parameters 26 | ( records delimited by newline 27 | fields terminated by whitespace 28 | reject rows with all null fields 29 | ) 30 | location ('socket_and_spid.txt') 31 | ) reject limit unlimited; 32 | drop table socket_and_ip purge; 33 | create table socket_and_ip ( 34 | socket varchar2(20), 35 | ip_addr varchar2(15) 36 | ) organization external 37 | ( type oracle_loader 38 | default directory exttab 39 | access parameters 40 | ( records delimited by newline 41 | fields terminated by whitespace 42 | reject rows with all null fields 43 | ) 44 | location ('socket_and_ip.txt') 45 | ) reject limit unlimited; 46 | set feedback on 47 | exit; 48 | eof 49 | 50 | su - oracle -c "sqlplus -s / as sysdba" < s.machine 78 | ORDER BY i.instance_number 79 | ), 80 | sas_sai AS ( 81 | SELECT sas.spid, sai.ip_addr 82 | FROM socket_and_spid sas, socket_and_ip sai 83 | WHERE sas.socket = sai.socket 84 | ) 85 | SELECT s.*, ss.ip_addr 86 | FROM sess s, sas_sai ss 87 | WHERE s.spid = ss.spid; 88 | exit; 89 | eof 90 | -------------------------------------------------------------------------------- /batch_remove/batch_remove_listener_xml_on_2018.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | 3 | # +----------------------------------------------------------------------------+ 4 | # | | 5 | # | File Name : batch_remove_listener_xml_on_2018.sh | 6 | # | | 7 | # | Author : Quanwen Zhao | 8 | # | | 9 | # | Description : This bash script file used to remove listener log xml file | 10 | # | | 11 | # | that located in "$ORACLE_BASE/diag/tnslsnr/$HOSTNAME | 12 | # | | 13 | # | /listener/alert" directory on oracle user of Oracle | 14 | # | | 15 | # | Database Server generated by 2018. | 16 | # | | 17 | # | Call Syntax : . ~/batch_remove_listener_xml_on_2018.sh | 18 | # | | 19 | # | or | 20 | # | | 21 | # | sh ~/batch_remove_listener_xml_on_2018.sh | 22 | # | | 23 | # | Last Modified: 11/04/209 (mm/dd/yyyy) | 24 | # | | 25 | # +----------------------------------------------------------------------------+ 26 | 27 | # +----------------------------------------------------------------------------+ 28 | # | | 29 | # | EXPORT ENVIRONMENT VARIABLE OF ORACLE USER | 30 | # | | 31 | # +----------------------------------------------------------------------------+ 32 | 33 | source ~/.bash_profile; 34 | 35 | # +----------------------------------------------------------------------------+ 36 | # | | 37 | # | DEFINE SOME SHELL STRING VARIABLES ON ABSOLUTE PATH OF EXTERNAL COMMAND | 38 | # | | 39 | # | AND DIRECTORY | 40 | # | | 41 | # +----------------------------------------------------------------------------+ 42 | 43 | export AWK=`which awk` 44 | export ECHO=`which echo` 45 | export GREP=`which grep` 46 | export HOSTNAME=`which hostname` 47 | export LS=`which ls` 48 | export RM=`which rm` 49 | export WC=`which wc` 50 | 51 | cd /u01/app/oracle/diag/tnslsnr/`$HOSTNAME`/listener/alert/ 52 | 53 | file_name=`$LS --full-time | $GREP '2018' | $AWK '{print $9}'` 54 | file_count=`$LS --full-time | $GREP '2018' | $AWK '{print $9}' | $WC -l` 55 | 56 | for file in $file_name 57 | do 58 | $RM -rf $file; 59 | $ECHO -e "$file has been removed." 60 | done 61 | $ECHO -e 62 | $ECHO -e "Total $file_count log.xml have been removed." 63 | -------------------------------------------------------------------------------- /rsync/rsync_backup_with_log_refresh.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # The crontab setting on oracle user of local linux server is as follows: 4 | 5 | # 00 03 * * * ~/rsync_script/rsync_backup_with_log_refresh.sh 6 | 7 | # +-----------------------------------------------------------------------+ 8 | # | Quanwen Zhao | 9 | # | guestart@163.com | 10 | # | quanwenzhao.wordpress.com | 11 | # |-----------------------------------------------------------------------| 12 | # | Copyright (c) 2021 - Quanwen Zhao. All rights reserved. | 13 | # |-----------------------------------------------------------------------| 14 | # | DATABASE : Oracle Database | 15 | # | OS ENV : Linux | 16 | # | File : rsync_backup_with_log_refresh.sh | 17 | # | CLASS : Linux bash script | 18 | # | PURPOSE : This bash script file uses to rsync oracle backup files | 19 | # | from REMOTE server to local. | 20 | # | | 21 | # | PARAMETERS : None. | 22 | # | | 23 | # | MODIFIED : 22/04/2021 (dd/mm/yyyy) | 24 | # | | 25 | # | NOTE : As with any code,ensure to test this script in a | 26 | # | development environment before attempting to run it in | 27 | # | production. | 28 | # +-----------------------------------------------------------------------+ 29 | 30 | # +-----------------------------------------------------------------------+ 31 | # | GLOBAL VARIABLES ABOUT BACKTICK EXECUTION RESULT OF SHELL AND STRINGS | 32 | # +-----------------------------------------------------------------------+ 33 | 34 | export AWK=`which awk` 35 | export ECHO=`which echo` 36 | export CUT=`which cut` 37 | export DATE=`which date` 38 | export DF=`which df` 39 | export FIND=`which find` 40 | export GREP=`which grep` 41 | export RSYNC=`which rsync` 42 | export SCRIPT=`which script` 43 | export TEE=`which tee` 44 | 45 | export DISK_USED_PERCENT=`$DF -h | $GREP "/DATA" | $AWK '{print $5}' | $CUT -d% -f1` 46 | 47 | export RSYNC_LOG_FILE=~/rsync_script/rsync_log/rsync_`$DATE +%Y%m%d-%H%M%S`.log 48 | export RSYNC_LOG_DIR=~/rsync_script/rsync_log 49 | export RSYNC_DIR=/DATA/rsync 50 | 51 | if [ $DISK_USED_PERCENT -le 95 ]; then 52 | $SCRIPT -a $RSYNC_LOG_FILE -c "$RSYNC -rvlHpogDtS --progress oracle@xx.xxx.x.xx:/home/oracle/rman_backup /DATA/rsync" 53 | $SCRIPT -a $RSYNC_LOG_FILE -c "$RSYNC -rvlHpogDtS --progress oracle@xx.xxx.x.xx:/u01/app/oracle/expdp /DATA/rsync" 54 | else 55 | $ECHO -e "\nDisk available free space is not enough! Please removing some expired files first and try to run this SHELL script.\n" | $TEE -a $RSYNC_LOG_FILE 56 | fi 57 | 58 | # Setting the retention policy (only retaining 168 days for backup files and rsync log files) 59 | # and they will automatically be purged if which are in the outside of retention policy in 60 | # order to avoid exhausting the disk space. 61 | # Ref: https://www.cyberciti.biz/faq/find-command-exclude-ignore-files/ 62 | 63 | $FIND $RSYNC_DIR -type f -mtime +168 -exec rm -f {} \; 64 | $FIND $RSYNC_DIR -type d -empty -exec rmdir {} \; 65 | $FIND $RSYNC_LOG_DIR -type f -mtime +168 -exec rm -f {} \; 66 | -------------------------------------------------------------------------------- /statistics_all_disk_files/statistics_all_disk_files.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # +------------------------------------------------------------------------+ 4 | # | Quanwen Zhao | 5 | # | guestart@163.com | 6 | # | quanwenzhao.wordpress.com | 7 | # |------------------------------------------------------------------------| 8 | # | Copyright (c) 2016-2018 Quanwen Zhao. All rights reserved. | 9 | # |------------------------------------------------------------------------| 10 | # | DATABASE : Oracle | 11 | # | | 12 | # | FILE : statistics_all_disk_files.sh | 13 | # | | 14 | # | CLASS : LINUX Bourne-Again Shell Scripts | 15 | # | | 16 | # | PURPOSE : This bash script file used to list every file with only | 17 | # | reserving the format of date and count total files number | 18 | # | on each disk on Linux Server. | 19 | # | | 20 | # | PARAMETERS : None. | 21 | # | | 22 | # | MODIFIED : 29/06/2018 (dd/mm/yyyy) | 23 | # | | 24 | # | NOTE : As with any code, ensure to test this script in a | 25 | # | development environment before attempting to run it in | 26 | # | production. | 27 | # +------------------------------------------------------------------------+ 28 | 29 | # +------------------------------------------------------------------------+ 30 | # | GLOBAL VARIABLES ABOUT THE ABSOLUTE PATH OF THE SHELL COMMAND | 31 | # +------------------------------------------------------------------------+ 32 | 33 | export AWK=`which awk` 34 | export CUT=`which cut` 35 | export DU=`which du` 36 | export ECHO=`which echo` 37 | export GREP=`which grep` 38 | export LS=`which ls` 39 | export UNIQ=`which uniq` 40 | export WC=`which wc` 41 | 42 | # +------------------------------------------------------------------------+ 43 | # | GLOBAL VARIABLES ABOUT STRINGS AND ABSOLUTE PATH OF THE SHELL COMMAND | 44 | # +------------------------------------------------------------------------+ 45 | 46 | export DISK_ARRAY='HDB HDC HDD HDE HDF HDG HDH HDI HDJ HDK HDL HDM HDN HDO' 47 | export OUTPUT_FILE='/home/oracle/statistics_all_disk_files.txt' 48 | 49 | # +------------------------------------------------------------------------+ 50 | # | USING THE "FOR DO ... DONE" TO ACCOMPLISH THAT PURPOSE PREVIOUS | 51 | # +------------------------------------------------------------------------+ 52 | 53 | for i in $DISK_ARRAY 54 | do 55 | cd /$i; 56 | if [ `$LS -A | $WC -w` = 0 ]; then 57 | $ECHO -e "+---------+" >> $OUTPUT_FILE; 58 | $ECHO -e "| *"$i"* |" >> $OUTPUT_FILE; 59 | $ECHO -e "+---------+" >> $OUTPUT_FILE; 60 | $ECHO -e "\r" >> $OUTPUT_FILE; 61 | $ECHO "Total Nums: 0" >> $OUTPUT_FILE; 62 | $ECHO -e "\r" >> $OUTPUT_FILE; 63 | else 64 | export FILE_STR=`$DU -h * | $AWK '{print $2}' | $CUT -d'_' -f5 | $GREP -v log | $GREP -v lost+found | $UNIQ` 65 | $ECHO -e "+---------+" >> $OUTPUT_FILE; 66 | $ECHO -e "| *"$i"* |" >> $OUTPUT_FILE; 67 | $ECHO -e "+---------+" >> $OUTPUT_FILE; 68 | $ECHO -e "\r" >> $OUTPUT_FILE; 69 | #$ECHO $FILE_STR >> $OUTPUT_FILE; 70 | num=0; 71 | for j in $FILE_STR 72 | do 73 | $ECHO ${j:0:8} >> $OUTPUT_FILE; 74 | num=$(($num+1)); 75 | $ECHO -e "\r" >> $OUTPUT_FILE; 76 | done 77 | $ECHO "Total Nums: "$num >> $OUTPUT_FILE; 78 | $ECHO -e "\r" >> $OUTPUT_FILE; 79 | fi 80 | done 81 | -------------------------------------------------------------------------------- /rotate_process_file/back_and_clean_alert_log.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # crontab setting on linux is as follows: 4 | 5 | # 30 01 * * * ~/back_and_clean_alert_log.sh >>/dev/null 2>&1 6 | 7 | # +---------------------------------------------------------------------+ 8 | # | | 9 | # | File Name : back_and_clean_alert_log.sh | 10 | # | | 11 | # | Author : Quanwen Zhao | 12 | # | | 13 | # | Description : This bash script file used to backup and clean alert | 14 | # | | 15 | # | log file that located in "$ORACLE_BASE/diag/rdbms/ | 16 | # | | 17 | # | orcl/orcl/trace" directory of oracle db server. | 18 | # | | 19 | # | Assume that my oracle database name is "orcl". | 20 | # | | 21 | # | Call Syntax : . ~/back_and_clean_alert_log.sh | 22 | # | | 23 | # | or | 24 | # | | 25 | # | sh ~/back_and_clean_alert_log.sh | 26 | # | | 27 | # | Last Modified: 08/09/2016 (dd/mm/yyyy) | 28 | # | | 29 | # | Updated: 13/06/2019 (dd/mm/yyyy) | 30 | # | | 31 | # +---------------------------------------------------------------------+ 32 | 33 | # +--------------------------------------------+ 34 | # | | 35 | # | Export environment variable of oracle user | 36 | # | | 37 | # +--------------------------------------------+ 38 | 39 | source ~/.bash_profile; 40 | 41 | # +-----------------------------------------------------------------+ 42 | # | | 43 | # | Define some shell string variables on absolute path of external | 44 | # | | 45 | # | command and directory | 46 | # | | 47 | # +-----------------------------------------------------------------+ 48 | 49 | export DU=`which du` 50 | 51 | export CUT=`which cut` 52 | 53 | export CP=`which cp` 54 | 55 | export DATE=`which date` 56 | 57 | export ECHO=`which echo` 58 | 59 | export TRACE=$ORACLE_BASE/diag/rdbms/orcl/orcl/trace 60 | 61 | 62 | # +----------------------------------------+ 63 | # | | 64 | # | Calculate the size of "alert_orcl.log" | 65 | # | | 66 | # +----------------------------------------+ 67 | 68 | export SIZE=`$DU -m $TRACE/alert_orcl.log | $CUT -f1` 69 | 70 | # +---------------------------------------------------------+ 71 | # | | 72 | # | If the size of "alert_orcl.log" is greater than 150 MB, | 73 | # | | 74 | # | then backup and clean its current content, otherwise do | 75 | # | | 76 | # | nothing. | 77 | # | | 78 | # +---------------------------------------------------------+ 79 | 80 | if [ $SIZE -gt 150 ]; then 81 | 82 | $CP $TRACE/alert_orcl.log $TRACE/alert_orcl_`$DATE +%Y%m%d%H%M%S`.log 83 | 84 | $ECHO "" > $TRACE/alert_orcl.log 85 | 86 | fi 87 | -------------------------------------------------------------------------------- /rotate_process_file/retention_expdp_test_dump_file_2days.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # +-----------------------------------------------------------------------+ 4 | # | Quanwen Zhao | 5 | # | guestart@163.com | 6 | # | quanwenzhao.wordpress.com | 7 | # |-----------------------------------------------------------------------| 8 | # | Copyright (c) 2016-2017 Quanwen Zhao. All rights reserved. | 9 | # |-----------------------------------------------------------------------| 10 | # | DATABASE : Oracle | 11 | # | OS ENV : Linux | 12 | # | File : retention_expdp_test_dump_file_2days.sh | 13 | # | CLASS : LINUX Bourne-Again Shell Scripts | 14 | # | PURPOSE : This bash script file used to delete dmp file of expdp | 15 | # | all of data about user "test" in oracle database | 16 | # | 2 days before on every saturday at 05:00 before dawn. | 17 | # | PARAMETERS : None. | 18 | # | MODIFIED : 22/05/2017 (dd/mm/yyyy) | 19 | # | NOTE : As with any code,ensure to test this script in a | 20 | # | development environment before attempting to run it in | 21 | # | production. | 22 | # +-----------------------------------------------------------------------+ 23 | 24 | # +-----------------------------------------------------------------------+ 25 | # | EXPORT ENVIRONMENT VARIABLE OF ORACLE USER | 26 | # +-----------------------------------------------------------------------+ 27 | 28 | source ~/.bash_profile; 29 | 30 | # +-----------------------------------------------------------------------+ 31 | # | GLOBAL VARIABLES ABOUT THE ABSOLUTE PATH OF THE SHELL COMMAND | 32 | # +-----------------------------------------------------------------------+ 33 | 34 | export DATE=`which date` 35 | export ECHO=`which echo` 36 | export GREP=`which grep` 37 | export LS=`which ls` 38 | export MKDIR=`which mkdir` 39 | export RM=`which rm` 40 | export TEE=`which tee` 41 | 42 | # +-----------------------------------------------------------------------+ 43 | # | CHANGE CURRENT DIRECTORY TO EXPDP DIRECTORY OF ORACLE USER | 44 | # +-----------------------------------------------------------------------+ 45 | 46 | cd /u01/oradata/rman_backup/expdp 47 | 48 | # +-----------------------------------------------------------------------+ 49 | # | GLOBAL VARIABLES ABOUT THE BACKTICK EXECUTION RESULT OF THE SHELL | 50 | # +-----------------------------------------------------------------------+ 51 | 52 | export TODAY=`$DATE +%Y%m%d` 53 | 54 | export YESTERDAY=`$DATE +%Y%m%d -d yesterday` 55 | 56 | export OBSOLETE_EXPDP_TEST_DMP=`$LS expdp_test_*.dmp expdp_test_*.log | $GREP -v $TODAY | $GREP -v $YESTERDAY` 57 | 58 | export OBSOLETE_EXPDP_TEST_DMP_FILE= 59 | 60 | # +-----------------------------------------------------------------------+ 61 | # | GLOBAL VARIABLE ABOUT STRINGS | 62 | # +-----------------------------------------------------------------------+ 63 | 64 | export LOG_FILE_PATH='/u01/oradata/rman_backup/del_expdp_test_log' 65 | 66 | export LOG_FILE=$LOG_FILE_PATH/del_expdp_test_`$DATE +%Y%m%d%H%M%S`.log 67 | 68 | # +-----------------------------------------------------------------------+ 69 | # | IF NOT EXISTS,CREATE DIRECTORY OF GLOBAL VARIABLE 'LOG_FILE_PATH' | 70 | # +-----------------------------------------------------------------------+ 71 | 72 | if [ ! -d $LOG_FILE_PATH ]; then 73 | $MKDIR -p $LOG_FILE_PATH 74 | fi 75 | 76 | # +-----------------------------------------------------------------------+ 77 | # | DELETE ALL OF OBSOLETE EXPDP DMP FILES ( EXCLUDE BE GENERATED TODAY | 78 | # | AT 04:00 AND YESTERDAY'S ) ON EVERYDAY AT 05:00 BEFORE DAWN. | 79 | # +-----------------------------------------------------------------------+ 80 | 81 | for OBSOLETE_EXPDP_TEST_DMP_FILE in $OBSOLETE_EXPDP_TESTE_DMP 82 | do 83 | $ECHO "$RM -rf $OBSOLETE_EXPDP_TEST_DMP_FILE" | $TEE -a $LOG_FILE 84 | $RM -rf $OBSOLETE_EXPDP_TEST_DMP_FILE 85 | done 86 | -------------------------------------------------------------------------------- /shell_demo/check_shell_command_return_value.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # +------------------------------------------------------------------------+ 4 | # | | 5 | # | Quanwen Zhao | 6 | # | | 7 | # | guestart@163.com | 8 | # | | 9 | # | quanwenzhao.wordpress.com | 10 | # | | 11 | # |------------------------------------------------------------------------| 12 | # | | 13 | # | Copyright (c) 2021 - Quanwen Zhao. All rights reserved. | 14 | # | | 15 | # |------------------------------------------------------------------------| 16 | # | | 17 | # | File Name : /tmp/check_shell_command_return_value.sh | 18 | # | | 19 | # | Author : Quanwen Zhao | 20 | # | | 21 | # | Description : This bash script file used to check the return value | 22 | # | | 23 | # | of prior SHELL command that has finished running. | 24 | # | | 25 | # | Call Syntax : . /tmp/check_shell_command_return_value.sh | 26 | # | | 27 | # | or | 28 | # | | 29 | # | sh /tmp/check_shell_command_return_value.sh | 30 | # | | 31 | # | Last Modified: 03/04/2021 (dd/mm/yyyy) | 32 | # | | 33 | # +------------------------------------------------------------------------+ 34 | 35 | export ECHO=`which echo` 36 | export FIND=`which find` 37 | export GREP=`which grep` 38 | export SORT=`which sort` 39 | 40 | $FIND /tmp -type f | $SORT -nr 41 | $ECHO $? 42 | 43 | $FIND /tmp -type f | $SORT -nr | $GREP -v "/tmp" 44 | $ECHO $? 45 | 46 | # As you can see from the following demo showing the different return value "0" and "1" 47 | # when running "find /tmp -type f | sort -nr" and "find /tmp -type f | sort -nr | grep -v "/tmp"". 48 | # Because the former shell command has normally exited but the latter one has abnormally exited. 49 | 50 | # [oracle@sync_back ~]$ find /tmp -type f | sort -nr 51 | # /tmp/tmp_20210403033001_subdir_all.log 52 | # /tmp/tmp_20210403033001_remote_subdir_all.log 53 | # /tmp/tmp_20210403033001_remote_all.log 54 | # /tmp/tmp_20210403033001_local_subdir_all.log 55 | # /tmp/tmp_20210403033001_local_all.log 56 | # /tmp/tmp_20210403033001_compare_all.log 57 | # /tmp/tmp_20210402033001_subdir_all.log 58 | # /tmp/tmp_20210402033001_remote_subdir_all.log 59 | # /tmp/tmp_20210402033001_remote_all.log 60 | # /tmp/tmp_20210402033001_local_subdir_all.log 61 | # /tmp/tmp_20210402033001_local_all.log 62 | # /tmp/tmp_20210402033001_compare_all.log 63 | # [oracle@sync_back ~]$ 64 | # [oracle@sync_back ~]$ echo $? 65 | # 0 66 | # 67 | # [oracle@sync_back ~]$ find /tmp -type f | sort -nr | grep -v "/tmp" 68 | # find: ‘/tmp/systemd-private-907eb49692214e69b9937a753ad79f4a-colord.service-W3iOxH’: Permission denied 69 | # find: ‘/tmp/systemd-private-907eb49692214e69b9937a753ad79f4a-rtkit-daemon.service-58zymA’: Permission denied 70 | # find: ‘/tmp/ssh-2m24EkjO9yjE’: Permission denied 71 | # find: ‘/tmp/systemd-private-907eb49692214e69b9937a753ad79f4a-vmtoolsd.service-waYELc’: Permission denied 72 | # find: ‘/tmp/systemd-private-907eb49692214e69b9937a753ad79f4a-cups.service-TvKFdR’: Permission denied 73 | # find: ‘/tmp/.esd-0’: Permission denied 74 | # [oracle@sync_back ~]$ 75 | # [oracle@sync_back ~]$ echo $? 76 | # 1 77 | -------------------------------------------------------------------------------- /statistics_all_disk_files/statistics_all_disk_files_2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # +------------------------------------------------------------------------+ 4 | # | Quanwen Zhao | 5 | # | guestart@163.com | 6 | # | quanwenzhao.wordpress.com | 7 | # |------------------------------------------------------------------------| 8 | # | Copyright (c) 2016-2018 Quanwen Zhao. All rights reserved. | 9 | # |------------------------------------------------------------------------| 10 | # | DATABASE : Oracle | 11 | # | | 12 | # | FILE : statistics_all_disk_files_2.sh | 13 | # | | 14 | # | CLASS : LINUX Bourne-Again Shell Scripts | 15 | # | | 16 | # | PURPOSE : This bash script file used to list the first and last file| 17 | # | with only reserving the format of date and count total | 18 | # | files number on each disk on Linux Server. | 19 | # | | 20 | # | PARAMETERS : None. | 21 | # | | 22 | # | MODIFIED : 29/06/2018 (dd/mm/yyyy) | 23 | # | | 24 | # | NOTE : As with any code, ensure to test this script in a | 25 | # | development environment before attempting to run it in | 26 | # | production. | 27 | # +------------------------------------------------------------------------+ 28 | 29 | # +------------------------------------------------------------------------+ 30 | # | GLOBAL VARIABLES ABOUT THE ABSOLUTE PATH OF THE SHELL COMMAND | 31 | # +------------------------------------------------------------------------+ 32 | 33 | export AWK=`which awk` 34 | export CUT=`which cut` 35 | export DU=`which du` 36 | export ECHO=`which echo` 37 | export GREP=`which grep` 38 | export LS=`which ls` 39 | export UNIQ=`which uniq` 40 | export WC=`which wc` 41 | 42 | # +------------------------------------------------------------------------+ 43 | # | GLOBAL VARIABLES ABOUT STRINGS AND ABSOLUTE PATH OF THE SHELL COMMAND | 44 | # +------------------------------------------------------------------------+ 45 | 46 | export DISK_ARRAY='HDB HDC HDD HDE HDF HDG HDH HDI HDJ HDK HDL HDM HDN HDO' 47 | export OUTPUT_FILE='/home/oracle/statistics_all_disk_files_2.txt' 48 | 49 | # +------------------------------------------------------------------------+ 50 | # | USING THE "FOR DO ... DONE" TO ACCOMPLISH THAT PURPOSE PREVIOUS | 51 | # +------------------------------------------------------------------------+ 52 | 53 | for i in $DISK_ARRAY 54 | do 55 | cd /$i; 56 | if [ `$LS -A | $WC -w` = 0 ]; then 57 | $ECHO -e "+---------+" >> $OUTPUT_FILE; 58 | $ECHO -e "| *"$i"* |" >> $OUTPUT_FILE; 59 | $ECHO -e "+---------+" >> $OUTPUT_FILE; 60 | $ECHO -e "\r" >> $OUTPUT_FILE; 61 | $ECHO "Total Nums: 0" >> $OUTPUT_FILE; 62 | $ECHO -e "\r" >> $OUTPUT_FILE; 63 | else 64 | export FILE_STR=`$DU -h * | $AWK '{print $2}' | $CUT -d'_' -f5 | $GREP -v log | $GREP -v lost+found | $UNIQ` 65 | $ECHO -e "+---------+" >> $OUTPUT_FILE; 66 | $ECHO -e "| *"$i"* |" >> $OUTPUT_FILE; 67 | $ECHO -e "+---------+" >> $OUTPUT_FILE; 68 | $ECHO -e "\r" >> $OUTPUT_FILE; 69 | export FILE_STR_FIRST=`$ECHO $FILE_STR | $AWK '{print $1}'` 70 | export FILE_STR_LAST=`$ECHO $FILE_STR | $AWK '{print $NF}'` 71 | export FILE_STR_NUMS=`$ECHO $FILE_STR | $AWK '{print NF}'` 72 | #$ECHO $FILE_STR 73 | #num=0; 74 | #for j in $FILE_STR 75 | #do 76 | # $ECHO ${j:0:8} >> $OUTPUT_FILE; 77 | # num=$(($num+1)); 78 | $ECHO $FILE_STR_FIRST" - "$FILE_STR_LAST >> $OUTPUT_FILE; 79 | $ECHO -e "\r" >> $OUTPUT_FILE; 80 | #done 81 | $ECHO "Total Nums: "$FILE_STR_NUMS >> $OUTPUT_FILE; 82 | $ECHO -e "\r" >> $OUTPUT_FILE; 83 | fi 84 | done 85 | -------------------------------------------------------------------------------- /rotate_process_file/back_and_clean_listener_log.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # crontab setting on linux is as follows: 4 | 5 | # 00 01 * * * ~/back_and_clean_listener_log.sh >>/dev/null 2>&1 6 | 7 | # +----------------------------------------------------------------------------+ 8 | # | | 9 | # | File Name : back_and_clean_listener_log.sh | 10 | # | | 11 | # | Author : Quanwen Zhao | 12 | # | | 13 | # | Description : This bash script file used to backup and clean listener | 14 | # | | 15 | # | log file that located in "$ORACLE_BASE/diag/tnslsnr/ | 16 | # | | 17 | # | $HOSTNAME/listener/trace" directory on oracle user of | 18 | # | | 19 | # | Oracle Database Server. | 20 | # | | 21 | # | Call Syntax : . ~/back_and_clean_listener_log.sh | 22 | # | | 23 | # | or | 24 | # | | 25 | # | sh ~/back_and_clean_listener_log.sh | 26 | # | | 27 | # | Last Modified: 22/05/2017 (dd/mm/yyyy) | 28 | # | | 29 | # | Updated: 13/06/2019 (dd/mm/yyyy) | 30 | # | | 31 | # +----------------------------------------------------------------------------+ 32 | 33 | # +----------------------------------------------------------------------------+ 34 | # | | 35 | # | EXPORT ENVIRONMENT VARIABLE OF ORACLE USER | 36 | # | | 37 | # +----------------------------------------------------------------------------+ 38 | 39 | source ~/.bash_profile; 40 | 41 | # +----------------------------------------------------------------------------+ 42 | # | | 43 | # | DEFINE SOME SHELL STRING VARIABLES ON ABSOLUTE PATH OF EXTERNAL COMMAND | 44 | # | | 45 | # | AND DIRECTORY | 46 | # | | 47 | # +----------------------------------------------------------------------------+ 48 | 49 | export CUT=`which cut` 50 | 51 | export DATE=`which date` 52 | 53 | export DU=`which du` 54 | 55 | export HOSTNAME=`which hostname` 56 | 57 | export MV=`which mv` 58 | 59 | export LSNRCTL=$ORACLE_HOME/bin/lsnrctl 60 | 61 | export TRACE=$ORACLE_BASE/diag/tnslsnr/`$HOSTNAME`/listener/trace 62 | 63 | # +----------------------------------------------------------------------------+ 64 | # | | 65 | # | CALCULATE THE SIZE OF LISTENER.LOG | 66 | # | | 67 | # +----------------------------------------------------------------------------+ 68 | 69 | export SIZE=`$DU -m $TRACE/listener.log | $CUT -f1` 70 | 71 | # +----------------------------------------------------------------------------+ 72 | # | | 73 | # | IF THE SIZE OF LISTENER.LOG IS GREATER THAN 512 MB, THEN BACKUP AND CLEAN | 74 | # | | 75 | # | ITS CURRENT CONTENT, OTHERWISE DO NOTHING. | 76 | # | | 77 | # +----------------------------------------------------------------------------+ 78 | 79 | if [ $SIZE -gt 512 ]; then 80 | 81 | $LSNRCTL set log_status off 82 | 83 | $MV $TRACE/listener.log $TRACE/listener_orcl_`$DATE +%Y%m%d%H%M%S`.log 84 | 85 | $LSNRCTL set log_status on 86 | 87 | fi 88 | -------------------------------------------------------------------------------- /shell_demo/check_oracle_instance_nums.sh: -------------------------------------------------------------------------------- 1 | # +------------------------------------------------------------------------+ 2 | # | Quanwen Zhao | 3 | # | guestart@163.com | 4 | # | quanwenzhao.wordpress.com | 5 | # |------------------------------------------------------------------------| 6 | # | | 7 | # | Copyright (c) 2021 - Quanwen Zhao. All rights reserved. | 8 | # | | 9 | # |------------------------------------------------------------------------| 10 | # | | 11 | # | File Name : ~/check_oracle_instance_nums.sh | 12 | # | | 13 | # | Author : Quanwen Zhao | 14 | # | | 15 | # | Description : This bash script file used to check how many instances | 16 | # | | 17 | # | in your Oracle Database Server. | 18 | # | | 19 | # | Call Syntax : . ~/check_oracle_instance_nums.sh | 20 | # | | 21 | # | or | 22 | # | | 23 | # | sh ~/check_oracle_instance_nums.sh | 24 | # | | 25 | # | Last Modified: 16/04/2021 (dd/mm/yyyy) | 26 | # | | 27 | # +------------------------------------------------------------------------+ 28 | 29 | # +------------------------------------------------------------------------+ 30 | # | | 31 | # | Export environment variable of oracle user | 32 | # | | 33 | # +------------------------------------------------------------------------+ 34 | 35 | source ~/.bash_profile; 36 | 37 | # +------------------------------------------------------------------------+ 38 | # | | 39 | # | Define the absolute location of some internal SHELL commands | 40 | # | | 41 | # +------------------------------------------------------------------------+ 42 | 43 | export AWK=`which awk` 44 | export BASENAME=`which basename` 45 | export CAT=`which cat` 46 | export CUT=`which cut` 47 | export FIND=`which find` 48 | export WC=`which wc` 49 | export SORT=`which sort` 50 | 51 | # +------------------------------------------------------------------------+ 52 | # | | 53 | # | Define some shell common variables | 54 | # | | 55 | # +------------------------------------------------------------------------+ 56 | 57 | export SPFILE_LOC_LIST= 58 | export INSTANCE_NUM=`find ${ORACLE_HOME}/dbs -name "spfile*.ora" | wc -l` 59 | export INSTANCE_NAME_TMPFILE=/tmp/instance_name_list.lst 60 | 61 | # +------------------------------------------------------------------------+ 62 | # | | 63 | # | The critical SHELL script for check_oracle_instance_nums.sh | 64 | # | | 65 | # +------------------------------------------------------------------------+ 66 | 67 | > ${INSTANCE_NAME_TMPFILE} 68 | 69 | if [ ${INSTANCE_NUM} -gt 1 ]; then 70 | SPFILE_LOC_LIST=`$FIND ${ORACLE_HOME}/dbs -name "spfile*.ora" | $SORT -n` 71 | for n in ${SPFILE_LOC_LIST} 72 | do 73 | $BASENAME $n | $CUT -d'.' -f1 | $AWK '{print substr($1, length("spfile")+1)}' >> ${INSTANCE_NAME_TMPFILE} 74 | done 75 | else 76 | $BASENAME ${SPFILE_LOC_LIST} | $CUT -d'.' -f1 | $AWK '{print substr($1, length("spfile")+1)}'>> ${INSTANCE_NAME_TMPFILE} 77 | fi 78 | 79 | $CAT ${INSTANCE_NAME_TMPFILE} 80 | 81 | # The following demo is the returned outcome when executing the previous SHELL script on my Oracle Database test server. 82 | # [oracle@testdb ~]$ ./check_oracle_instance_nums.sh 83 | # testdb1 84 | # testdb2 85 | # testdb3 86 | # [oracle@testdb ~]$ 87 | -------------------------------------------------------------------------------- /rman_backup_and_restore_experiment/rman_validate_v2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # +-----------------------------------------------------------------------+ 4 | # | Quanwen Zhao | 5 | # | guestart@163.com | 6 | # | quanwenzhao.wordpress.com | 7 | # |-----------------------------------------------------------------------| 8 | # | Copyright (c) 2016-2017 Quanwen Zhao. All rights reserved. | 9 | # |-----------------------------------------------------------------------| 10 | # | DATABASE : Oracle | 11 | # | OS ENV : CentOS 6.6 X86_64 Bit | 12 | # | File : rman_validate_v2.sh | 13 | # | CLASS : LINUX Bourne-Again Shell Scripts | 14 | # | PURPOSE : This bash script file used to validate rman backupset | 15 | # | that is generated last night via validate command on | 16 | # | Oracle Database Server. | 17 | # | | 18 | # | PARAMETERS : None. | 19 | # | | 20 | # | MODIFIED : 03/17/2017 (mm/dd/yyyy) | 21 | # | | 22 | # | NOTE : As with any code, ensure to test this script in a | 23 | # | development environment before attempting to run it in | 24 | # | production. | 25 | # +-----------------------------------------------------------------------+ 26 | 27 | # +-----------------------------------------------------------------------+ 28 | # | EXPORT ENVIRONMENT VARIABLE OF ORACLE USER | 29 | # +-----------------------------------------------------------------------+ 30 | 31 | source ~/.bash_profile; 32 | 33 | # +-----------------------------------------------------------------------+ 34 | # | GLOBAL VARIABLES ABOUT THE ABSOLUTE PATH OF THE SHELL COMMAND | 35 | # +-----------------------------------------------------------------------+ 36 | 37 | export AWK=`which awk` 38 | export DATE=`which date` 39 | export ECHO=`which echo` 40 | 41 | # +-----------------------------------------------------------------------+ 42 | # | GLOBAL VARIABLES ABOUT STRINGS AND BACKTICK EXECUTION RESULT OF SHELL | 43 | # +-----------------------------------------------------------------------+ 44 | 45 | export BACK_LOG=~/rman_backup/log 46 | export RMAN=$ORACLE_HOME/bin/rman 47 | export SQLPLUS=$ORACLE_HOME/bin/sqlplus 48 | export YESTERDAY=`$DATE +%Y-%m-%d -d yesterday` 49 | export DAY_OF_WEEK=`$DATE +%u` 50 | export BSKEY_LIST= 51 | export BSKEY_LIST_WITH_COMMA= 52 | 53 | # +-----------------------------------------------------------------------+ 54 | # | QUERY ALL OF BS_KEY VALUE OF RMAN BACKUPSET YESTERDAY INTO BSKEY_LIST | 55 | # +-----------------------------------------------------------------------+ 56 | 57 | BSKEY_LIST=` 58 | $SQLPLUS -S /nolog << EOF 59 | connect / as sysdba 60 | set echo off feedback off heading off underline off 61 | select bs_key from v\\$backup_set_details where device_type='DISK' and completion_time > to_date('$YESTERDAY','yyyy-mm-dd') order by 1; 62 | exit; 63 | EOF` 64 | 65 | # +-----------------------------------------------------------------------+ 66 | # | WITH AWK COMMAND TO PROCESS BSKEY_LIST SAVE TO BSKEY_LIST_WITH_COMMA | 67 | # +-----------------------------------------------------------------------+ 68 | 69 | BSKEY_LIST_WITH_COMMA=`$ECHO $BSKEY_LIST | $AWK -F' ' '{ for ( i=1; i ${INSTANCE_NAME_TMPFILE} 38 | # You need manually create it in case the file "/etc/oratab" doesn't exist 39 | # and then add the entry "$ORACLE_SID:$ORACLE_HOME:Y". 40 | if [ ! -f /etc/oratab ]; then 41 | $TOUCH /etc/oratab 42 | $ECHO "# A colon, ':', is used as the field terminator. A new line terminates" >> /etc/oratab 43 | $ECHO "# the entry. Lines beginning with a pound sign, '#', are comments." >> /etc/oratab 44 | $ECHO "#" >> /etc/oratab 45 | $ECHO "# Entries are of the form:" >> /etc/oratab 46 | $ECHO "# \$ORACLE_SID:\$ORACLE_HOME::" >> /etc/oratab 47 | $ECHO "#" >> /etc/oratab 48 | $ECHO "# The first and second fields are the system identifier and home" >> /etc/oratab 49 | $ECHO "# directory of the database respectively. The third field indicates" >> /etc/oratab 50 | $ECHO "# to the dbstart utility that the database should , "Y", or should not," >> /etc/oratab 51 | $ECHO "# "N", be brought up at system boot time." >> /etc/oratab 52 | $ECHO "#" >> /etc/oratab 53 | $ECHO "# Multiple entries with the same \$ORACLE_SID are not allowed." >> /etc/oratab 54 | $ECHO "#" >> /etc/oratab 55 | $ECHO "#" >> /etc/oratab 56 | # Checking how many instance(s) in your Oracle Database server. 57 | if [ ${INSTANCE_NUM} -gt 1 ]; then 58 | SPFILE_LOC_LIST=`$FIND ${ORA_HOME}/dbs -name "spfile*.ora" | $SORT -n` 59 | for n in ${SPFILE_LOC_LIST} 60 | do 61 | $BASENAME $n | $CUT -d'.' -f1 | $AWK '{print substr($1, length("spfile")+1)}' >> ${INSTANCE_NAME_TMPFILE} 62 | $ECHO "`$CAT ${INSTANCE_NAME_TMPFILE}`:${ORA_HOME}:Y" >> /etc/oratab 63 | done 64 | else 65 | $BASENAME ${SPFILE_LOC_LIST} | $CUT -d'.' -f1 | $AWK '{print substr($1, length("spfile")+1)}'>> ${INSTANCE_NAME_TMPFILE} 66 | $ECHO "`$CAT ${INSTANCE_NAME_TMPFILE}`:${ORA_HOME}:Y" >> /etc/oratab 67 | fi 68 | # Changing the file mode bits of file "/etc/oratab" to become "664". 69 | $CHOWN oracle:oinstall /etc/oratab 70 | $CHMOD 664 /etc/oratab 71 | else 72 | # You need to modify the entry "$ORACLE_SID:$ORACLE_HOME:N" to "...:...Y" in the file "/etc/oratab". 73 | $CP /etc/oratab /etc/oratab.bak 74 | $CHOWN oracle:oinstall /etc/oratab.bak 75 | $CHMOD 664 /etc/oratab.bak 76 | $SED -i 's/:N/:Y/g' /etc/oratab 77 | fi 78 | 79 | if [ ! -f ${ORA_HOME}/bin/dbstart ] || [ ! -f ${ORA_HOME}/bin/dbshut ]; then 80 | $ECHO "Error: Missing the script file ${ORA_HOME}/bin/dbstart or ${ORA_HOME}/bin/dbshut!" >> ${ORA_lOGFILE} 81 | else 82 | # In order to prevent dbstart or dbshut from returning the following 2 line of prompt messages. 83 | # Since ORACLE_HOME is not set, cannot auto-stop Oracle Net Listener 84 | # Usage: ${ORACLE_HOME}/bin/dbstart ORACLE_HOME 85 | # or 86 | # Since ORACLE_HOME is not set, cannot auto-stop Oracle Net Listener 87 | # Usage: ${ORACLE_HOME}/bin/dbshut ORACLE_HOME 88 | # You need to set the "$1"'s value of string "ORACLE_HOME_LISTNER=$1" to the value of variable ORACLE_HOME. 89 | # GET_VALUE=`$CAT ${ORA_HOME}/bin/dbstart | $GREP "ORACLE_HOME_LISTNER=$1" | $CUT -d'=' -f2` 90 | # # https://www.cnblogs.com/Cherie/p/3200294.html 91 | # if [ "${GET_VALUE}" == "\$1" ]; then 92 | # $CP ${ORA_HOME}/bin/dbstart ${ORA_HOME}/bin/dbstart.bak 93 | # # https://blog.csdn.net/weixin_40501169/article/details/85610005 94 | # # https://www.cnblogs.com/2bjiujiu/p/9029598.html 95 | # $SED -i "s#ORACLE_HOME_LISTNER=\$1#ORACLE_HOME_LISTNER=${ORA_HOME}#" ${ORA_HOME}/bin/dbstart 96 | # fi 97 | # GET_VALUE=`$CAT ${ORA_HOME}/bin/dbshut | $GREP "ORACLE_HOME_LISTNER=$1" | $CUT -d'=' -f2` 98 | # # https://www.cnblogs.com/Cherie/p/3200294.html 99 | # if [ "${GET_VALUE}" == "\$1" ]; then 100 | # $CP ${ORA_HOME}/bin/dbshut ${ORA_HOME}/bin/dbstart.bak 101 | # # https://blog.csdn.net/weixin_40501169/article/details/85610005 102 | # # https://www.cnblogs.com/2bjiujiu/p/9029598.html 103 | # $SED -i "s#ORACLE_HOME_LISTNER=\$1#ORACLE_HOME_LISTNER=${ORA_HOME}#" ${ORA_HOME}/bin/dbshut 104 | # fi 105 | OPTION=$1 106 | case "${OPTION}" in 107 | start) 108 | $ECHO "$0 : (start oracle database ...)" 109 | $SU - ${ORA_OWNER} -c "${ORA_HOME}/bin/dbstart ${ORA_HOME}" >> ${ORA_LOGFILE} 110 | exit 0 111 | ;; 112 | stop) 113 | $ECHO "$0 : (shutdown oracle database ...)" 114 | $SU - ${ORA_OWNER} -c "${ORA_HOME}/bin/dbshut ${ORA_HOME}" >> ${ORA_LOGFILE} 115 | exit 0 116 | ;; 117 | restart) 118 | $ECHO "$0 : (shutdown oracle database ...)" 119 | $SU - ${ORA_OWNER} -c "${ORA_HOME}/bin/dbshut ${ORA_HOME}" >> ${ORA_LOGFILE} 120 | $ECHO "$0 : (start oracle database ...)" 121 | $SU - ${ORA_OWNER} -c "${ORA_HOME}/bin/dbstart ${ORA_HOME}" >> ${ORA_LOGFILE} 122 | exit 0 123 | ;; 124 | *) 125 | $ECHO "Usage: $0 [start|stop|restart]" 126 | $ECHO "Invalid argument: \"${OPTION}\"" 127 | exit 2 128 | ;; 129 | esac 130 | fi 131 | -------------------------------------------------------------------------------- /dig_listener_log_xml/dig_ip_via_listener_log_xml.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # +-----------------------------------------------------------------------+ 4 | # | | 5 | # | Quanwen Zhao | 6 | # | | 7 | # | guestart@163.com | 8 | # | | 9 | # | https://quanwenzhao.wordpress.com | 10 | # | | 11 | # |-----------------------------------------------------------------------| 12 | # | | 13 | # | Copyright (c) 2019 Quanwen Zhao. All rights reserved. | 14 | # | | 15 | # |-----------------------------------------------------------------------| 16 | # | | 17 | # | Database : Oracle | 18 | # | | 19 | # | Os env : Linux | 20 | # | | 21 | # | File : dig_ip_via_listener_log_xml.sh | 22 | # | | 23 | # | Class : Linux Bash script | 24 | # | | 25 | # | Purpose : This bash script file used to dig/mine all ip addresses | 26 | # | | 27 | # | connecting to oracle database server recently via oracle | 28 | # | | 29 | # | listener log file "log.xml". | 30 | # | | 31 | # | Parameters : None. | 32 | # | | 33 | # | Modified : 08/15/2019 (mm/dd/yyyy) | 34 | # | | 35 | # | Note : As with any code, ensure to test this script in a | 36 | # | | 37 | # | development environment before attempting to run it in | 38 | # | | 39 | # | production. | 40 | # | | 41 | # +-----------------------------------------------------------------------+ 42 | 43 | #source ~/.bash_profile; 44 | 45 | export DATE_TIME=`which date` 46 | #export HOST_NAME=`which hostname` 47 | export DIR_NAME=`which dirname` 48 | 49 | #loc_listener_log=$ORACLE_BASE'/diag/tnslsnr/'`${HOST_NAME}`'/listener/alert' 50 | #loc_listener_log=`${DIR_NAME} $(lsnrctl status | awk '/Listener Log File/ {print $NF}')` 51 | 52 | listener_name=`lsnrctl show current_listener | grep "Current" | awk '{print $NF}'` 53 | 54 | listener_log=`lsnrctl status ${listener_name} | awk '/Listener Log File/ {print $NF}'` 55 | 56 | echo 57 | echo "========================================================================================" 58 | echo "# #" 59 | echo "# Now this Bash shell script will generate dig_ip_via_listener_log_xml_`date +%Y%m%d`.lst #" 60 | echo "# #" 61 | echo "# Please patiently waiting for a while ...... #" 62 | echo "# #" 63 | echo "========================================================================================" 64 | echo 65 | echo 'Begin time: '$(${DATE_TIME} '+%Y-%m-%d %H:%M:%S') 66 | echo 67 | 68 | cat ${listener_log} | grep "HOST=" | grep establish | awk -F'=' '{print $(NF-1)}' | cut -d')' -f1 | sort -n | uniq > ~/dig_listener_log_xml_`date +%Y%m%d`.lst 69 | 70 | # +-----------------------------------------------------------------------+ 71 | # | | 72 | # | Total three methods filtering out IP address via grep or egrep. | 73 | # | | 74 | # | 1. grep -o "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" | 75 | # | | 76 | # | 2. grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | 77 | # | | 78 | # | 3. egrep -o "([0-9]{1,3}\.){3}[0-9]{1,3}" | 79 | # | | 80 | # +-----------------------------------------------------------------------+ 81 | 82 | cat ~/dig_listener_log_xml_`date +%Y%m%d`.lst | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | sort -n | uniq > ~/dig_ip_via_listener_log_xml_`date +%Y%m%d`.lst 83 | 84 | echo "============================================================================================" 85 | echo "# #" 86 | echo "# As you can see, the previously mentioned lst file has been listed by following location. #" 87 | echo "# #" 88 | echo "============================================================================================" 89 | echo 90 | ls -lrth ~/dig_ip_via_listener_log_xml_`date +%Y%m%d`.lst | awk '{print $NF}' 91 | echo 92 | echo 'End time: '$(${DATE_TIME} '+%Y-%m-%d %H:%M:%S') 93 | echo 94 | -------------------------------------------------------------------------------- /rman_backup_and_restore_experiment/ssh_mutual_trust_linux_for_source.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # +-----------------------------------------------------------------------+ 4 | # | Quanwen Zhao | 5 | # | guestart@163.com | 6 | # | quanwenzhao.wordpress.com | 7 | # |-----------------------------------------------------------------------| 8 | # | Copyright (c) 2016-2017 Quanwen Zhao. All rights reserved. | 9 | # |-----------------------------------------------------------------------| 10 | # | DATABASE : Oracle | 11 | # | OS ENV : Linux | 12 | # | File : ssh_mutual_trust_linux_for_source.sh | 13 | # | CLASS : LINUX Bourne-Again Shell Scripts | 14 | # | PURPOSE : This bash script file used to set ssh mutual trust | 15 | # | between source and target linux server. Therefore, every | 16 | # | operation between two, such as ssh and scp, have no | 17 | # | password to interaction. | 18 | # | | 19 | # | PARAMETERS : None. | 20 | # | | 21 | # | MODIFIED : 03/10/2017 (mm/dd/yyyy) | 22 | # | | 23 | # | NOTE : As with any code, ensure to test this script in a | 24 | # | development environment before attempting to run it in | 25 | # | production. | 26 | # +-----------------------------------------------------------------------+ 27 | 28 | # +-----------------------------------------------------------------------+ 29 | # | EXPORT ENVIRONMENT VARIABLE OF ORACLE USER | 30 | # +-----------------------------------------------------------------------+ 31 | 32 | source ~/.bash_profile; 33 | 34 | # +-----------------------------------------------------------------------+ 35 | # | GLOBAL VARIABLES ABOUT STRINGS AND BACKTICK EXECUTION RESULT OF SHELL | 36 | # +-----------------------------------------------------------------------+ 37 | 38 | export DATE=`which date` 39 | export ECHO=`which echo` 40 | export HOSTNAME=`which hostname` 41 | export PING=`which ping` 42 | export SSH_KEYGEN=`which ssh-keygen` 43 | export SSH_COPY_ID=`which ssh-copy-id` 44 | export TEE=`which tee` 45 | 46 | export LOCAL_HOST=`$HOSTNAME` 47 | 48 | # Define Remote Host, For example, REMOTE_HOST='orcl1', According to your situation to set. 49 | # At same time, Please add the host name and IP address of the remote host to hosts file 50 | # that is located in etc subdir of '/' directory in root user. 51 | # For example, as follows: 52 | # 127.0.0.1 localhost localhost.localdomain 53 | # ::1 localhost6 localhost6.localdomain6 54 | # 172.16.10.11 orac11 55 | # 172.16.10.13 orcl13 <<== Remote Host's host name and IP address 56 | 57 | export REMOTE_HOST='orcl13' 58 | 59 | export ALIVEHOST="" 60 | export DEADHOST="" 61 | export EXITCODE="" 62 | 63 | export LOGFILE=/tmp/ssh_mutual_trust_`$DATE +%F-%H-%M-%S`.log 64 | 65 | $ECHO "# +-----------------------------------------------------------------------+" | $TEE -a $LOGFILE 66 | $ECHO "# | CHECKING IF THE REMOTE HOST ARE REACHABLE |" | $TEE -a $LOGFILE 67 | $ECHO -e "# +-----------------------------------------------------------------------+\n" | $TEE -a $LOGFILE 68 | 69 | $PING -c 5 -w 5 $REMOTE_HOST 70 | 71 | EXITCODE=`$ECHO $?` 72 | 73 | if [ $EXITCODE = 0 ] 74 | then 75 | ALIVEHOST="$ALIVEHOST $REMOTE_HOST" 76 | else 77 | DEADHOST="$DEADHOST $REMOTE_HOST" 78 | fi 79 | 80 | if test -z "$DEADHOST" 81 | then 82 | $ECHO Remote host reachability check succeeded. | $TEE -a $LOGFILE 83 | $ECHO The following host is reachable: $ALIVEHOST. | $TEE -a $LOGFILE 84 | $ECHO -e "Proceeding further...\n" | $TEE -a $LOGFILE 85 | else 86 | $ECHO Remote host reachability check failed. | $TEE -a $LOGFILE 87 | $ECHO The following host is not reachable: $DEADHOST. | $TEE -a $LOGFILE 88 | $ECHO -e "Exiting now...\n" | $TEE -a $LOGFILE 89 | exit 1 90 | fi 91 | 92 | $ECHO "# +-----------------------------------------------------------------------+" | $TEE -a $LOGFILE 93 | $ECHO "# | CREATE SSH PRIVATE AND PUBLIC KEY,COPY PUBLIC KEY TO REMOTE HOST |" | $TEE -a $LOGFILE 94 | $ECHO -e "# +-----------------------------------------------------------------------+\n" | $TEE -a $LOGFILE 95 | $ECHO "# +-----------------------------------------------------------------------+" | $TEE -a $LOGFILE 96 | $ECHO "# | The script will setup SSH connectivity from local host to remote host.|" | $TEE -a $LOGFILE 97 | $ECHO "# | After the script is executed, the user can use SSH to run commands on |" | $TEE -a $LOGFILE 98 | $ECHO "# | the remote host or copy files between local host and the remote host |" | $TEE -a $LOGFILE 99 | $ECHO "# | without being prompted for passwords or confirmations. |" | $TEE -a $LOGFILE 100 | $ECHO "# | |" | $TEE -a $LOGFILE 101 | $ECHO "# | NOTE 1: |" | $TEE -a $LOGFILE 102 | $ECHO "# | As part of the setup procedure, this script will use 'ssh' and 'scp' |" | $TEE -a $LOGFILE 103 | $ECHO "# | to copy files between the local host and the remote host. Since the |" | $TEE -a $LOGFILE 104 | $ECHO "# | script does not store passwords, you may be prompted for the pass- |" | $TEE -a $LOGFILE 105 | $ECHO "# | words during the execution of the script whenever 'ssh' or 'scp' is |" | $TEE -a $LOGFILE 106 | $ECHO "# | invoked. |" | $TEE -a $LOGFILE 107 | $ECHO "# | |" | $TEE -a $LOGFILE 108 | $ECHO "# | NOTE 2: |" | $TEE -a $LOGFILE 109 | $ECHO "# | As per ssh requirements, this script will secure the user home |" | $TEE -a $LOGFILE 110 | $ECHO "# | directory and the .ssh directory by revoking group and world write |" | $TEE -a $LOGFILE 111 | $ECHO "# | privileges to those directories. |" | $TEE -a $LOGFILE 112 | $ECHO "# +-----------------------------------------------------------------------+" | $TEE -a $LOGFILE 113 | $ECHO -e "\nThe Local Host is: "$LOCAL_HOST | $TEE -a $LOGFILE 114 | $ECHO -e "The Remote Host is: "$REMOTE_HOST"\n" | $TEE -a $LOGFILE 115 | $SSH_KEYGEN -t rsa | $TEE -a $LOGFILE 116 | $SSH_COPY_ID -i ~/.ssh/id_rsa.pub oracle@$REMOTE_HOST | $TEE -a $LOGFILE 117 | -------------------------------------------------------------------------------- /rman_backup_and_restore_experiment/ssh_mutual_trust_linux_for_target.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # +-----------------------------------------------------------------------+ 4 | # | Quanwen Zhao | 5 | # | guestart@163.com | 6 | # | quanwenzhao.wordpress.com | 7 | # |-----------------------------------------------------------------------| 8 | # | Copyright (c) 2016-2017 Quanwen Zhao. All rights reserved. | 9 | # |-----------------------------------------------------------------------| 10 | # | DATABASE : Oracle | 11 | # | OS ENV : Linux | 12 | # | File : ssh_mutual_trust_linux_for_target.sh | 13 | # | CLASS : LINUX Bourne-Again Shell Scripts | 14 | # | PURPOSE : This bash script file used to set ssh mutual trust | 15 | # | between source and target linux server. Therefore, every | 16 | # | operation between two, such as ssh and scp, have no | 17 | # | password to interaction. | 18 | # | | 19 | # | PARAMETERS : None. | 20 | # | | 21 | # | MODIFIED : 03/10/2017 (mm/dd/yyyy) | 22 | # | | 23 | # | NOTE : As with any code, ensure to test this script in a | 24 | # | development environment before attempting to run it in | 25 | # | production. | 26 | # +-----------------------------------------------------------------------+ 27 | 28 | # +-----------------------------------------------------------------------+ 29 | # | EXPORT ENVIRONMENT VARIABLE OF ORACLE USER | 30 | # +-----------------------------------------------------------------------+ 31 | 32 | source ~/.bash_profile; 33 | 34 | # +-----------------------------------------------------------------------+ 35 | # | GLOBAL VARIABLES ABOUT STRINGS AND BACKTICK EXECUTION RESULT OF SHELL | 36 | # +-----------------------------------------------------------------------+ 37 | 38 | export DATE=`which date` 39 | export ECHO=`which echo` 40 | export HOSTNAME=`which hostname` 41 | export PING=`which ping` 42 | export SSH_KEYGEN=`which ssh-keygen` 43 | export SSH_COPY_ID=`which ssh-copy-id` 44 | export TEE=`which tee` 45 | 46 | export LOCAL_HOST=`$HOSTNAME` 47 | 48 | # Define Remote Host, For example, REMOTE_HOST='orcl1', According to your situation to set. 49 | # At same time, Please add the host name and IP address of the remote host to hosts file 50 | # that is located in etc subdir of '/' directory in root user. 51 | # For example, as follows: 52 | # 127.0.0.1 localhost localhost.localdomain 53 | # ::1 localhost6 localhost6.localdomain6 54 | # 172.16.10.13 orcl13 55 | # 172.16.10.11 orac11 <<== Remote Host's host name and IP address 56 | 57 | export REMOTE_HOST='orac11' 58 | 59 | export ALIVEHOST="" 60 | export DEADHOST="" 61 | export EXITCODE="" 62 | 63 | export LOGFILE=/tmp/ssh_mutual_trust_`$DATE +%F-%H-%M-%S`.log 64 | 65 | $ECHO "# +-----------------------------------------------------------------------+" | $TEE -a $LOGFILE 66 | $ECHO "# | CHECKING IF THE REMOTE HOST ARE REACHABLE |" | $TEE -a $LOGFILE 67 | $ECHO -e "# +-----------------------------------------------------------------------+\n" | $TEE -a $LOGFILE 68 | 69 | $PING -c 5 -w 5 $REMOTE_HOST 70 | 71 | EXITCODE=`$ECHO $?` 72 | 73 | if [ $EXITCODE = 0 ] 74 | then 75 | ALIVEHOST="$ALIVEHOST $REMOTE_HOST" 76 | else 77 | DEADHOST="$DEADHOST $REMOTE_HOST" 78 | fi 79 | 80 | if test -z "$DEADHOST" 81 | then 82 | $ECHO Remote host reachability check succeeded. | $TEE -a $LOGFILE 83 | $ECHO The following host is reachable: $ALIVEHOST. | $TEE -a $LOGFILE 84 | $ECHO -e "Proceeding further...\n" | $TEE -a $LOGFILE 85 | else 86 | $ECHO Remote host reachability check failed. | $TEE -a $LOGFILE 87 | $ECHO The following host is not reachable: $DEADHOST. | $TEE -a $LOGFILE 88 | $ECHO -e "Exiting now...\n" | $TEE -a $LOGFILE 89 | exit 1 90 | fi 91 | 92 | $ECHO "# +-----------------------------------------------------------------------+" | $TEE -a $LOGFILE 93 | $ECHO "# | CREATE SSH PRIVATE AND PUBLIC KEY,COPY PUBLIC KEY TO REMOTE HOST |" | $TEE -a $LOGFILE 94 | $ECHO -e "# +-----------------------------------------------------------------------+\n" | $TEE -a $LOGFILE 95 | $ECHO "# +-----------------------------------------------------------------------+" | $TEE -a $LOGFILE 96 | $ECHO "# | The script will setup SSH connectivity from local host to remote host.|" | $TEE -a $LOGFILE 97 | $ECHO "# | After the script is executed, the user can use SSH to run commands on |" | $TEE -a $LOGFILE 98 | $ECHO "# | the remote host or copy files between local host and the remote host |" | $TEE -a $LOGFILE 99 | $ECHO "# | without being prompted for passwords or confirmations. |" | $TEE -a $LOGFILE 100 | $ECHO "# | |" | $TEE -a $LOGFILE 101 | $ECHO "# | NOTE 1: |" | $TEE -a $LOGFILE 102 | $ECHO "# | As part of the setup procedure, this script will use 'ssh' and 'scp' |" | $TEE -a $LOGFILE 103 | $ECHO "# | to copy files between the local host and the remote host. Since the |" | $TEE -a $LOGFILE 104 | $ECHO "# | script does not store passwords, you may be prompted for the pass- |" | $TEE -a $LOGFILE 105 | $ECHO "# | words during the execution of the script whenever 'ssh' or 'scp' is |" | $TEE -a $LOGFILE 106 | $ECHO "# | invoked. |" | $TEE -a $LOGFILE 107 | $ECHO "# | |" | $TEE -a $LOGFILE 108 | $ECHO "# | NOTE 2: |" | $TEE -a $LOGFILE 109 | $ECHO "# | As per ssh requirements, this script will secure the user home |" | $TEE -a $LOGFILE 110 | $ECHO "# | directory and the .ssh directory by revoking group and world write |" | $TEE -a $LOGFILE 111 | $ECHO "# | privileges to those directories. |" | $TEE -a $LOGFILE 112 | $ECHO "# +-----------------------------------------------------------------------+" | $TEE -a $LOGFILE 113 | $ECHO -e "\nThe Local Host is: "$LOCAL_HOST | $TEE -a $LOGFILE 114 | $ECHO -e "The Remote Host is: "$REMOTE_HOST"\n" | $TEE -a $LOGFILE 115 | $SSH_KEYGEN -t rsa | $TEE -a $LOGFILE 116 | $SSH_COPY_ID -i ~/.ssh/id_rsa.pub oracle@$REMOTE_HOST | $TEE -a $LOGFILE 117 | -------------------------------------------------------------------------------- /rsync/README.md: -------------------------------------------------------------------------------- 1 | # Welcome to use RSYNC 2 | 3 | ### 1. What is RSYNC ? 4 | 5 | `Rsync` is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. 6 | It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied. It is famous for 7 | its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in 8 | the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use. 9 | 10 | Rsync finds files that need to be transferred using a "quick check" algorithm (by default) that looks for files that have changed in size or in last-modified time. 11 | Any changes in the other preserved attributes (as requested by options) are made on the destination file directly when the quick check indicates that the file’s data does 12 | not need to be updated. 13 | 14 | ### 2. How to use RSYNC ? 15 | 16 | Here we use `RSYNC` to synchronize oracle backup files from REMOTE server to local. Assuming that the hostname of REMOTE oracle database server is `prodb1` and the hostname 17 | of local server is `sync_back`. The following steps are entire process using RSYNC to sync oracle backup files. 18 | 19 | - Setting `SSH` mutual trust configuration on the LOCAL and REMOTE server 20 | - Creating rsa secret key on the LOCAL server 21 | ```bash 22 | [oracle@sync_back ~]$ ssh-keygen -t rsa 23 | Generating public/private rsa key pair. 24 | Enter file in which to save the key (/home/oracle/.ssh/id_rsa): 25 | Created directory '/home/oracle/.ssh'. 26 | Enter passphrase (empty for no passphrase): 27 | Enter same passphrase again: 28 | Your identification has been saved in /home/oracle/.ssh/id_rsa. 29 | Your public key has been saved in /home/oracle/.ssh/id_rsa.pub. 30 | The key fingerprint is: 31 | 2c:08:27:4e:5a:4a:b7:aa:49:52:47:ae:e8:0a:52:70 oracle@ysyk_back 32 | The key's randomart image is: 33 | +--[ RSA 2048]----+ 34 | | | 35 | | | 36 | |..E.o | 37 | |.O.*.. . | 38 | |o +.+ . S | 39 | | +.o . | 40 | |=o. | 41 | |B. | 42 | |=. | 43 | +-----------------+ 44 | [oracle@sync_back ~]$ cd .ssh/ 45 | [oracle@sync_back .ssh]$ ls 46 | id_rsa id_rsa.pub 47 | ``` 48 | - Copying the public key file of LOCAL server to the REMOTE oracle database server 49 | ```bash 50 | [oracle@sync_back ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub oracle@xx.xxx.x.xx 51 | The authenticity of host 'xx.xxx.x.xx (xx.xxx.x.xx)' can't be established. 52 | RSA key fingerprint is 15:28:06:14:da:da:d3:5c:04:79:50:48:3e:b4:dc:bb. 53 | Are you sure you want to continue connecting (yes/no)? yes 54 | /bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed 55 | /bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys 56 | oracle@xx.xxx.x.xx's password: 57 | 58 | Number of key(s) added: 1 59 | 60 | Now try logging into the machine, with: "ssh 'oracle@xx.xxx.x.xx'" 61 | and check to make sure that only the key(s) you wanted were added. 62 | 63 | [oracle@sync_back ~]$ ssh oracle@xx.xxx.x.xx 64 | [oracle@prodb1 ~]$ 65 | [oracle@prodb1 ~]$ exit 66 | logout 67 | Connection to xx.xxx.x.xx closed. 68 | [oracle@sync_back ~]$ 69 | ``` 70 | - Checking the installing method of `RSYNC` on the REMOTE and LOCAL server (Generally speaking, after finished installing Linux OS will automatically install rsync) 71 | ```bash 72 | [root@prodb1 ~]# rpm -qa | grep rsync 73 | rsync-3.0.6-12.el6.x86_64 74 | 75 | [root@sync_back ~]# rpm -qa | grep rsync 76 | rsync-3.0.9-17.el7.x86_64 77 | ``` 78 | - Configuring `rsyncd.conf` on the REMOTE oracle database server (see rsyncd.conf) 79 | - Configuring `rsyncd.motd` on the REMOTE oracle database server (see rsyncd.motd) 80 | - Configuring `rsyncd.secrets` on the REMOTE oracle database server (see rsyncd.secrets) 81 | - Configuring `rsyncd.conf` on the LOCAL server (see rsyncd.conf) 82 | - Running `RSYNC` as a daemon process on the REMOTE oracle database server (or invoking it in /etc/rc.local in order to be able to automatically run it after restarting server) 83 | ```bash 84 | [root@prodb1 ~]# /usr/bin/rsync --daemon --port=873 --config=/etc/rsyncd.conf 85 | [root@prodb1 ~]# 86 | [root@prodb1 ~]# cat /etc/rc.local 87 | #!/bin/sh 88 | # 89 | # This script will be executed *after* all the other init scripts. 90 | # You can put your own initialization stuff in here if you don't 91 | # want to do the full Sys V style init stuff. 92 | 93 | touch /var/lock/subsys/local 94 | 95 | # Startup rsyncd process 96 | /usr/bin/rsync --daemon --port=873 --config=/etc/rsyncd.conf >/dev/null 2>&1 97 | ``` 98 | - Running `RSYNC` as a daemon process on the LOCAL server (or invoking it in /etc/rc.loal in order to be able to automatically run it after restarting server) 99 | ```bash 100 | [root@sync_back ~]# /bin/rsync --daemon --port=873 --config=/etc/rsyncd.conf 101 | [root@sync_back ~]# 102 | [root@sync_back ~]# cat /etc/rc.local 103 | #!/bin/bash 104 | # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES 105 | # 106 | # It is highly advisable to create own systemd services or udev rules 107 | # to run scripts during boot instead of using this file. 108 | # 109 | # In contrast to previous versions due to parallel execution during boot 110 | # this script will NOT be run after all other services. 111 | # 112 | # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure 113 | # that this script will be executed during boot. 114 | 115 | touch /var/lock/subsys/local 116 | 117 | # Startup rsyncd process 118 | /bin/rsync --daemon --port=873 --config=/etc/rsyncd.conf >/dev/null 2>&1 119 | ``` 120 | - Executing the Linux SHELL script rsync_backup_with_log_refresh.sh on the LOCAL server at 03:30 every day 121 | ```bash 122 | [oracle@sync_back ~]$ crontab -l 123 | 30 03 * * * ~/rsync_script/rsync_backup_with_log_refresh.sh 124 | ``` 125 | 126 | ### 3. License 127 | 128 | `RSYNC` is licensed under the **GNU** (a recursive acronym for "GNU's Not Unix!"), the Version `3.0` of `GENERAL PUBLIC LICENSE`. 129 | You may obtain a copy of the License at GPL 3.0. 130 | -------------------------------------------------------------------------------- /rman_validate/rman_validate_v2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # +-----------------------------------------------------------------------+ 4 | # | | 5 | # | Quanwen Zhao | 6 | # | | 7 | # | guestart@163.com | 8 | # | | 9 | # | quanwenzhao.wordpress.com | 10 | # | | 11 | # |-----------------------------------------------------------------------| 12 | # | | 13 | # | Copyright (c) 2016-2017 Quanwen Zhao. All rights reserved. | 14 | # | | 15 | # |-----------------------------------------------------------------------| 16 | # | | 17 | # | DATABASE : Oracle | 18 | # | | 19 | # | OS ENV : CentOS 6.6 X86_64 Bit | 20 | # | | 21 | # | File : rman_validate_v2.sh | 22 | # | | 23 | # | CLASS : LINUX Bourne-Again Shell Scripts | 24 | # | | 25 | # | PURPOSE : This bash script file used to validate rman backupset | 26 | # | | 27 | # | that is generated last night via validate command on | 28 | # | | 29 | # | Oracle Database Server. | 30 | # | | 31 | # | PARAMETERS : None. | 32 | # | | 33 | # | MODIFIED : 17/03/2017 (dd/mm/yyyy) | 34 | # | | 35 | # | NOTE : As with any code, ensure to test this script in a | 36 | # | | 37 | # | development environment before attempting to run it in | 38 | # | | 39 | # | production. | 40 | # | | 41 | # +-----------------------------------------------------------------------+ 42 | 43 | # +-----------------------------------------------------------------------+ 44 | # | | 45 | # | EXPORT ENVIRONMENT VARIABLE OF ORACLE USER | 46 | # | | 47 | # +-----------------------------------------------------------------------+ 48 | 49 | source ~/.bash_profile; 50 | 51 | # +-----------------------------------------------------------------------+ 52 | # | | 53 | # | GLOBAL VARIABLES ABOUT THE ABSOLUTE PATH OF THE SHELL COMMAND | 54 | # | | 55 | # +-----------------------------------------------------------------------+ 56 | 57 | export AWK=`which awk` 58 | 59 | export DATE=`which date` 60 | 61 | export ECHO=`which echo` 62 | 63 | # +-----------------------------------------------------------------------+ 64 | # | | 65 | # | GLOBAL VARIABLES ABOUT STRINGS AND BACKTICK EXECUTION RESULT OF SHELL | 66 | # | | 67 | # +-----------------------------------------------------------------------+ 68 | 69 | export BACK_LOG=~/rman_backup/log 70 | 71 | export RMAN=$ORACLE_HOME/bin/rman 72 | 73 | export SQLPLUS=$ORACLE_HOME/bin/sqlplus 74 | 75 | export YESTERDAY=`$DATE +%Y-%m-%d -d yesterday` 76 | 77 | export DAY_OF_WEEK=`$DATE +%u` 78 | 79 | export BSKEY_LIST= 80 | 81 | export BSKEY_LIST_WITH_COMMA= 82 | 83 | # +-----------------------------------------------------------------------+ 84 | # | | 85 | # | QUERY ALL OF BS_KEY VALUE OF RMAN BACKUPSET YESTERDAY INTO BSKEY_LIST | 86 | # | | 87 | # +-----------------------------------------------------------------------+ 88 | 89 | BSKEY_LIST=` 90 | $SQLPLUS -S /nolog << EOF 91 | connect / as sysdba 92 | set echo off feedback off heading off underline off 93 | select bs_key from v\\$backup_set_details where device_type='DISK' and completion_time > to_date('$YESTERDAY','yyyy-mm-dd') order by 1; 94 | exit; 95 | EOF` 96 | 97 | # +-----------------------------------------------------------------------+ 98 | # | | 99 | # | WITH AWK COMMAND TO PROCESS BSKEY_LIST SAVE TO BSKEY_LIST_WITH_COMMA | 100 | # | | 101 | # +-----------------------------------------------------------------------+ 102 | 103 | BSKEY_LIST_WITH_COMMA=`$ECHO $BSKEY_LIST | $AWK -F' ' '{ for ( i=1; i>/dev/null 2>&1 6 | 7 | # +------------------------------------------------------------------------+ 8 | # | | 9 | # | Quanwen Zhao | 10 | # | | 11 | # | guestart@163.com | 12 | # | | 13 | # | quanwenzhao.wordpress.com | 14 | # | | 15 | # |------------------------------------------------------------------------| 16 | # | | 17 | # | Copyright (c) 2016 Quanwen Zhao. All rights reserved. | 18 | # | | 19 | # |------------------------------------------------------------------------| 20 | # | | 21 | # | File Name : ~/rman_backup/rman_backup.sh | 22 | # | | 23 | # | Author : Quanwen Zhao | 24 | # | | 25 | # | Description : This bash script file used to backup one week via rman | 26 | # | | 27 | # | utility on Oracle Database Server. | 28 | # | | 29 | # | Call Syntax : . ~/rman_backup/rman_backup.sh | 30 | # | | 31 | # | or | 32 | # | | 33 | # | sh ~/rman_backup/rman_backup.sh | 34 | # | | 35 | # | Last Modified: 11/10/2016 (dd/mm/yyyy) | 36 | # | | 37 | # | Last Updated : 30/03/2021 (dd/mm/yyyy) | 38 | # | | 39 | # +------------------------------------------------------------------------+ 40 | 41 | # +------------------------------------------------------------------------+ 42 | # | | 43 | # | Export environment variable of oracle user | 44 | # | | 45 | # +------------------------------------------------------------------------+ 46 | 47 | source ~/.bash_profile; 48 | 49 | # +------------------------------------------------------------------------+ 50 | # | | 51 | # | Define some shell variables | 52 | # | | 53 | # +------------------------------------------------------------------------+ 54 | 55 | export BACK_PATH=~/rman_backup 56 | 57 | export BACK_LOG=~/rman_backup/log 58 | 59 | export DATE=`which date` 60 | 61 | export RMAN_BIN=$ORACLE_HOME/bin 62 | 63 | export FIND=`which find` 64 | 65 | export DATE_W=`$DATE +%u` 66 | 67 | # +------------------------------------------------------------------------+ 68 | # | | 69 | # | Create a directory of current date | 70 | # | | 71 | # +------------------------------------------------------------------------+ 72 | 73 | if [ ! -d "$BACK_PATH/`$DATE +%m-%d`" ]; then 74 | 75 | mkdir -p $BACK_PATH/`$DATE +%m-%d` 76 | 77 | fi 78 | 79 | # +------------------------------------------------------------------------+ 80 | # | | 81 | # | One week rman backup of incremental level 0 on Friday 22:30, and | 82 | # | | 83 | # | incremental level 1 on Satruday ~ Thursday 22:30 | 84 | # | | 85 | # +------------------------------------------------------------------------+ 86 | 87 | case $DATE_W in 88 | 89 | 5) 90 | 91 | $RMAN_BIN/rman nocatalog log $BACK_LOG/level0_`$DATE +%Y-%m-%d`.log < 2 |

Linux Shell Scripts

3 | 4 |

ADG:

5 |
 6 | check_dg_redo_apply.sql - Checking redo data apply on physical standby database of Oracle Active Data Guard
 7 | check_dg_redo_apply.sh - The shell script calling the previous "check_dg_redo_apply.sql"
 8 | 
9 |

BATCH REMOVE:

10 |
11 | batch_remove_listener_xml_on_2018.sh - Removing listener log xml file that located in "$ORACLE_BASE/diag/tnslsnr/$HOSTNAME/listener/alert" directory generated by 2018
12 | 
13 |

DIG LISTENER LOG:

14 |
15 | dig_ip_via_listener_log_xml.sh - Digging real IP Address connecting to oracle database server recently via oracle listener log file "log.xml"
16 | 
17 |

EXP:

18 |
19 | exp_test_and_del_yesterday.sh - Exporting (logical backup with exp command) today's dmp files with specific user(s) and then deleting yesterday's
20 | exp_test_and_del_yesterday_2.sh - The 2nd version of "exp_test_and_del_yesterday.sh", by the way adding four number of new parameters - "direct, buffer, feedback and recordlength" at the end of EXP command
21 | 
22 |

EXPDP:

23 |
24 | expdp_test_and_del_yesterday.sh - Exporting (logical backup with expdp command) today's dmp files with specific user(s) and then deleting yesterday's
25 | expdp_test_and_del_yesterday_2.sh - The 2nd version of "expdp_test_and_del_yesterday.sh", by the way adding a new parameter compression at the end of EXPDP command
26 | 
27 |

Linux Logo:

28 |
29 | buddha_bless_never_downtime.sh - Showing a pattern consisting of several special keyboard characters for "Buddha bless, Never downtime" 
30 | 
31 |

Oracle Logo Banner:

32 |
33 | oracle_logo.sh - Showing banner logo of oracle database server
34 | oracle_logo_2.sh - The 2nd version showing banner logo of oracle database server
35 | oracle_logo_3.sh - The 3rd version showing banner logo of oracle database server
36 | 
37 |

Oracle Service:

38 |
39 | automatically_open_oracle.sh - Invoking this SHELL script in /etc/rc.local in order to be able to automatically startup oracle database after restarting server
40 | oracle - Being able to run the service "oracle" for automatically open the Oracle Database in case of Linux (OS) restarts
41 | 
42 |

RMAN Backup:

43 |
44 | rman_backup.sh - Doing rman backup one week via rman utility on oracle database server
45 | rman_backup_ASM.sh - Doing rman backup one week to ASM disk via rman utility on oracle database server
46 | rman backup on Windows - Doing rman backup one week on Windows
47 | 
48 |

RMAN Backup and Restore Experiment:

49 |
50 | rman_backup_and_restore_experiment - The section of RMAN Backup and Restore Experiment
51 | 
52 |

RMAN Validate:

53 |
54 | rman_validate - The section of RMAN Validate
55 | 
56 |

Rotate Process File:

57 |
58 | back_and_clean_alert_log.sh - Backup and clean alert log file that located in "$ORACLE_BASE/diag/rdbms/orcl/orcl/trace" directory of oracle database server
59 | back_and_clean_listener_log.sh - Backup and clean listener  log file that located in "$ORACLE_BASE/diag/tnslsnr/$HOSTNAME/listener/trace" directory on oracle user of oracle database server
60 | retention_expdp_test_dump_file_2days.sh - Deleting all of expdp's dmp file about user "test" on oracle database 2 days before
61 | rotate_reserve_base_dmp.sh - Periodically removing some earliest so far 7 number of "xxxx_base_xxxx.dmp" file, which located in directory "/u01/oradata" on oracle user for keeping sufficient disk space in reserve
62 | 
63 |

RSYNC:

64 |
65 | rsync_backup_with_log_refresh.sh - Rsyncing oracle backup files from REMOTE server to local
66 | 
67 |

SCP:

68 |
69 | scp_expdp_parallel_local_to_remote.sh - Copying several files that is gerenated by oracle datapump tool with expdp command from local to another linux server via scp
70 | 
71 |

SHELL Demo:

72 |
73 | check_oracle_instance_nums.sh - Checking how many instances in your Oracle Database Server
74 | check_shell_command_return_value.sh - Checking the return value of prior SHELL command that has finished running
75 | test_mkdir.sh - Creating a directory after obtaining the previous location by "basename"
76 | 
77 |

SSH:

78 |
79 | local_trust_ssh_remote.txt - Configuring SSH mutual trust both two linux servers
80 | 
81 |

Statistics All Disk Files:

82 |
83 | statistics_all_disk_files.sh - Listing the first file and last with only reserving the format of date and count total files number on each disk on linux server
84 | statistics_all_disk_files_2.sh - The 2nd version listing the first file and last with only reserving the format of date and count total files number on each disk on linux server
85 | 
86 | 87 | 88 | -------------------------------------------------------------------------------- /rotate_process_file/rotate_reserve_base_dmp.sh: -------------------------------------------------------------------------------- 1 | # [oracle@huba-master-02 ~]$ df -h 2 | # Filesystem Size Used Avail Use% Mounted on 3 | # /dev/sda2 212G 5.6G 195G 3% / 4 | # tmpfs 63G 80K 63G 1% /dev/shm 5 | # /dev/sda1 190M 32M 149M 18% /boot 6 | # /dev/sdb1 47T 42T 2.5T 95% /u01/oradata <<== 7 | 8 | # [oracle@huba-master-02 ~]$ cd /u01/oradata 9 | # [oracle@huba-master-02 ~]$ 10 | # [oracle@huba-master-02 oradata]$ ls -lrth * 11 | # total 42T 12 | # -rw-r-----. 1 oracle oracle 99G Aug 09 2018 xxxx_base_20180809040001_01.dmp 13 | # -rw-r-----. 1 oracle oracle 30G Aug 09 2018 xxxx_base_20180809040001_02.dmp 14 | # -rw-r-----. 1 oracle oracle 31G Aug 09 2018 xxxx_base_20180809040001_03.dmp 15 | # -rw-r--r--. 1 oracle oracle 15K Aug 09 2018 xxxx_base_20180809040001.log 16 | # -rw-r-----. 1 oracle oracle 99G Aug 10 2018 xxxx_base_20180810040001_01.dmp 17 | # -rw-r-----. 1 oracle oracle 31G Aug 10 2018 xxxx_base_20180810040001_02.dmp 18 | # -rw-r-----. 1 oracle oracle 31G Aug 10 2018 xxxx_base_20180810040001_03.dmp 19 | # -rw-r--r--. 1 oracle oracle 15K Aug 10 2018 xxxx_base_20180810040001.log 20 | # ...... 21 | # -rw-r--r--. 1 oracle oracle 15K Jun 12 04:36 xxxx_base_20190612040001.log 22 | # -rw-r-----. 1 oracle oracle 7.9G Jun 12 04:36 xxxx_base_20190612040001_03.dmp 23 | # -rw-r-----. 1 oracle oracle 19G Jun 12 04:36 xxxx_base_20190612040001_02.dmp 24 | # -rw-r-----. 1 oracle oracle 21G Jun 12 04:36 xxxx_base_20190612040001_01.dmp 25 | # -rw-r--r--. 1 oracle oracle 15K Jun 13 04:34 xxxx_base_20190613040001.log 26 | # -rw-r-----. 1 oracle oracle 8.0G Jun 13 04:34 xxxx_base_20190613040001_03.dmp 27 | # -rw-r-----. 1 oracle oracle 22G Jun 13 04:34 xxxx_base_20190613040001_02.dmp 28 | # -rw-r-----. 1 oracle oracle 19G Jun 13 04:34 xxxx_base_20190613040001_01.dmp 29 | 30 | # [oracle@huba-master-02 ~]$ crontab -l 31 | # 00 05 * * 5 ~/rotate_reserve_base_dmp.sh 32 | 33 | #!/bin/bash 34 | 35 | # +-------------------------------------------------------------------------+ 36 | # | | 37 | # | File Name : rotate_reserve_base_dmp.sh | 38 | # | | 39 | # | Author : Quanwen Zhao | 40 | # | | 41 | # | Description : This bash script file used to periodically remove some | 42 | # | | 43 | # | earliest so far 7 number of "xxxx_base_xxxx.dmp" file, | 44 | # | | 45 | # | which located in directory "/u01/oradata" on oracle user | 46 | # | | 47 | # | for keeping sufficient disk space in reserve. | 48 | # | | 49 | # | Call Syntax : . rotate_reserve_base_dmp.sh | 50 | # | | 51 | # | or | 52 | # | | 53 | # | sh ~/rotate_reserve_base_dmp.sh | 54 | # | | 55 | # | Last Modified: 06/12/2019 (mm/dd/yyyy) | 56 | # | | 57 | # | Updated: 06/13/2019 (mm/dd/yyyy) | 58 | # | | 59 | # +-------------------------------------------------------------------------+ 60 | 61 | # +--------------------------------------------+ 62 | # | | 63 | # | EXPORT ENVIRONMENT VARIABLE OF ORACLE USER | 64 | # | | 65 | # +--------------------------------------------+ 66 | 67 | source ~/.bash_profile; 68 | 69 | # +-------------------------------------------------------------------------+ 70 | # | | 71 | # | DEFINE SOME SHELL STRING VARIABLES ON ABSOLUTE PATH OF EXTERNAL COMMAND | 72 | # | | 73 | # | AND DIRECTORY | 74 | # | | 75 | # +-------------------------------------------------------------------------+ 76 | 77 | export AWK=`which awk` 78 | 79 | export DF=`which df` 80 | 81 | export EXPR=`which expr` 82 | 83 | export GREP=`which grep` 84 | 85 | export HEAD=`which head` 86 | 87 | export LS=`which ls` 88 | 89 | export RM=`which rm` 90 | 91 | export SORT=`which sort` 92 | 93 | # +----------------------------------------------------------+ 94 | # | | 95 | # | CALCULATE THE AVAILABLE SIZE OF DIRECTORY "/u01/oradata" | 96 | # | | 97 | # +----------------------------------------------------------+ 98 | 99 | # export AVAI_SIZE=`$DF | $GREP "/u01/oradata" | $AWK '{print $(NF-2)}'` 100 | 101 | # +--------------------------------------------------------+ 102 | # | | 103 | # | CALCULATE THE USED PERCENT OF DIRECTORY "/u01/oradata" | 104 | # | | 105 | # +--------------------------------------------------------+ 106 | 107 | export USED_PERCENT=`$DF -h | $GREP "/u01/oradata" | $AWK '{print $(NF-1)}' | $AWK -F '%' '{print $1}'` 108 | 109 | # +------------------------------------------------+ 110 | # | | 111 | # | CHANGE THE CURRENT DIRECTORY TO "/u01/oradata" | 112 | # | | 113 | # +------------------------------------------------+ 114 | 115 | cd /u01/oradata 116 | 117 | # +--------------------------------------------------------------------------+ 118 | # | | 119 | # | IF THE AVAILABLE SIZE OF "/u01/oradata" IS LESS THAN 2.0 TB, THEN REMOVE | 120 | # | | 121 | # | SOME EARLIEST SO FAR 7 number of "xxxx_base_xxxx.dmp" FILE, OTHERWISE DO | 122 | # | | 123 | # | NOTHING. | 124 | # | | 125 | # +--------------------------------------------------------------------------+ 126 | 127 | export EARLIEST_SO_FAR_7_NUMBER_DATE_LIST=`$LS -lrth . | $GREP log | $AWK '{print $NF}' | $AWK -F '.' '{print $1}' | $AWK -F '_' '{print $NF}' | $SORT -n | $HEAD -7` 128 | 129 | #for i in ${EARLIEST_SO_FAR_7_NUMBER_DATE_LIST} 130 | #do 131 | # if [ `$EXPR $AVAI_SIZE / 1024 / 1024` -lt 2048 ]; then 132 | # $RM -rf expdp_szd_base_v2_$i* 133 | # fi 134 | #done 135 | 136 | # +--------------------------------------------------------------------------+ 137 | # | | 138 | # | IF THE USED PERCENT OF "/u01/oradata" IS GREATER THAN "95%", THEN REMOVE | 139 | # | | 140 | # | SOME EARLIEST SO FAR 7 number of "xxxx_base_xxxx.dmp" FILE, OTHERWISE DO | 141 | # | | 142 | # | NOTHING. | 143 | # | | 144 | # +--------------------------------------------------------------------------+ 145 | 146 | for i in ${EARLIEST_SO_FAR_7_NUMBER_DATE_LIST} 147 | do 148 | if [ $USED_PERCENT -gt 95 ]; then 149 | $RM -rf expdp_szd_base_v2_$i* 150 | fi 151 | done 152 | -------------------------------------------------------------------------------- /recognize_dg_arch/oracle_dg_arch_recognize.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | systempwd=$1 4 | 5 | function f_oracmd { 6 | typeset _oracmd="$@" 7 | su - oracle -c "sqlplus -S / as sysdba"<") 93 | hostname_remote=$(echo ${tns_remote} | awk -F 'HOST=' '{print $2}' | awk -F ')' '{print $1}') 94 | regex="\b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\b" 95 | check_step=$(echo ${hostname_remote} | egrep $regex | wc -l) 96 | if [ ${check_step} -eq 0 ]; then 97 | ipaddress_remote=$(ping ${hostname_remote} -c 1 | grep from | awk -F ':' '{print $1}' | awk -F '(' '{print $2}' | awk -F ')' '{print $1}') 98 | else 99 | ipaddress_remote=${hostname_remote} 100 | fi 101 | listener_port_remote=$(echo ${tns_remote} | awk -F 'PORT=' '{print $2}' | awk -F ')' '{print $1}') 102 | dbname_remote=$(f_oracmd2 "${tns}" "select value from v\$parameter where name = 'db_name';") 103 | db_unq_name_remote=$(f_oracmd2 "${tns}" "select value from v\$parameter where name = 'db_unique_name';") 104 | 105 | clu_db_remote=$(f_oracmd2 "${tns}" "select value from v\$parameter where name = 'cluster_database';") 106 | db_role_remote=$(f_oracmd2 "${tns}" "select database_role from v\$database;") 107 | 108 | if [ "${clu_db_remote}" = "TRUE" ]; then 109 | echo "**********The Remote Oracle Database Info**********" 110 | echo "SCAN IP: ${ipaddress_remote}" 111 | echo "LISTENER PORT: ${listener_port_remote}" 112 | echo "DATABASE NAME: ${dbname_remote}" 113 | echo "DATABASE UNIQUE NAME: ${db_unq_name_remote}" 114 | echo "DATABASE TYPE: Real Application Cluster" 115 | echo "DATABASE ROLE: ${db_role_remote}" 116 | echo -e "***************************************************\n" 117 | else 118 | echo "**********The Remote Oracle Database Info**********" 119 | echo "IP ADDRESS: ${ipaddress_remote}" 120 | echo "LISTENER PORT: ${listener_port_remote}" 121 | echo "DATABASE NAME: ${dbname_remote}" 122 | echo "DATABASE UNIQUE NAME: ${db_unq_name_remote}" 123 | echo "DATABASE TYPE: Single Instance" 124 | echo "DATABASE ROLE: ${db_role_remote}" 125 | echo -e "***************************************************\n" 126 | fi 127 | fi 128 | done 129 | fi 130 | elif [ "${clu_db}" = "FALSE" ] && [ "${db_role}" = "PRIMARY" -o "${db_role}" = "PHYSICAL STANDBY" ]; then 131 | ip_address=$(f_oracmd "select utl_inaddr.get_host_address from dual;") 132 | listener_port=$(sed '/^$/d' ${orac_home}/network/admin/listener.ora | sed 's/ //g' | sed ':a;N;$!ba;s/\=\n/\=/g' | sed ':a;N;$!ba;s/\n(/(/g' | sed ':a;N;$!ba;s/\n)/)/g' | grep "\" | awk -F 'PORT=' '{print $2}' | awk -F ')' '{print $1}') 133 | echo "**********The Local Oracle Database Info**********" 134 | echo "IP ADDRESS: ${ip_address}" 135 | echo "LISTENER PORT: ${listener_port}" 136 | echo "DATABASE NAME: ${dbname}" 137 | echo "DATABASE UNIQUE NAME: ${db_unq_name}" 138 | echo "DATABASE TYPE: Single Instance" 139 | echo "DATABASE ROLE: ${db_role}" 140 | echo -e "**************************************************\n" 141 | if [ -z "${dg_config}" ]; then 142 | echo "The primary database of oracle rac does not meet the data guard architecture." 143 | elif [ ! -z "${dg_config}" ] && [ ! -z "${log_arch_dest}" ]; then 144 | for i in $(echo ${dg_config_value} | sed "s/,/ /g") 145 | do 146 | if [ "${i}" != "${db_unq_name}" ]; then 147 | tns=${i} 148 | tns_remote=$(sed '/^$/d' ${orac_home}/network/admin/tnsnames.ora | sed 's/ //g' | sed ':a;N;$!ba;s/\=\n/\=/g' | sed ':a;N;$!ba;s/\n(/(/g' | sed ':a;N;$!ba;s/\n)/)/g' | grep -w "\<${tns}\>") 149 | hostname_remote=$(echo ${tns_remote} | awk -F 'HOST=' '{print $2}' | awk -F ')' '{print $1}') 150 | regex="\b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\b" 151 | check_step=$(echo ${hostname_remote} | egrep $regex | wc -l) 152 | if [ ${check_step} -eq 0 ]; then 153 | ipaddress_remote=$(ping ${hostname_remote} -c 1 | grep from | awk -F ':' '{print $1}' | awk -F '(' '{print $2}' | awk -F ')' '{print $1}') 154 | else 155 | ipaddress_remote=${hostname_remote} 156 | fi 157 | listener_port_remote=$(echo ${tns_remote} | awk -F 'PORT=' '{print $2}' | awk -F ')' '{print $1}') 158 | dbname_remote=$(f_oracmd2 "${tns}" "select value from v\$parameter where name = 'db_name';") 159 | db_unq_name_remote=$(f_oracmd2 "${tns}" "select value from v\$parameter where name = 'db_unique_name';") 160 | 161 | db_role_remote=$(f_oracmd2 "${tns}" "select database_role from v\$database;") 162 | 163 | echo "**********The Remote Oracle Database Info**********" 164 | echo "IP ADDRESS: ${ipaddress_remote}" 165 | echo "LISTENER PORT: ${listener_port_remote}" 166 | echo "DATABASE NAME: ${dbname_remote}" 167 | echo "DATABASE UNIQUE NAME: ${db_unq_name_remote}" 168 | echo "DATABASE TYPE: Single Instance" 169 | echo "DATABASE ROLE: ${db_role_remote}" 170 | echo -e "***************************************************\n" 171 | fi 172 | done 173 | fi 174 | fi 175 | 176 | -- the approach running this shell script: switching to root user of target server and executing the script, e.g. 177 | ./oracle_dg_arch.recognize.sh sys (sys is a parameter called the shell script and it is a password by user system within oracle database) 178 | 179 | [root@testdb2 ~]# ./oracle_dg_arch.recognize.sh sys 180 | **********The Local Oracle Database Info********** 181 | IP ADDRESS: 192.168.12.32 182 | LISTENER PORT: 1521 183 | DATABASE NAME: orcl11 184 | DATABASE UNIQUE NAME: orcl11dg49 185 | DATABASE TYPE: Single Instance 186 | DATABASE ROLE: PRIMARY 187 | ************************************************** 188 | 189 | **********The Remote Oracle Database Info********** 190 | IP ADDRESS: 192.168.1.194 191 | LISTENER PORT: 1521 192 | DATABASE NAME: orcl11 193 | DATABASE UNIQUE NAME: orcl11 194 | DATABASE TYPE: Single Instance 195 | DATABASE ROLE: PHYSICAL STANDBY 196 | *************************************************** 197 | -------------------------------------------------------------------------------- /scp/scp_expdp_parallel_local_to_remote.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # The crontab setting on oracle user of local server is as follows: 4 | 5 | # 00 05 * * * /u01/oradata01/rman_backup/scp_expdp_parallel_local_to_remote.sh >/dev/null 2>&1 6 | 7 | # +------------------------------------------------------------------------+ 8 | # | | 9 | # | Quanwen Zhao | 10 | # | | 11 | # | guestart@163.com | 12 | # | | 13 | # | quanwenzhao.wordpress.com | 14 | # | | 15 | # |------------------------------------------------------------------------| 16 | # | | 17 | # | Copyright (c) 2016-2019 Quanwen Zhao. All rights reserved. | 18 | # | | 19 | # |------------------------------------------------------------------------| 20 | # | | 21 | # | DATABASE : Oracle | 22 | # | | 23 | # | FILE : scp_expdp_parallel_local_to_remote.sh | 24 | # | | 25 | # | CLASS : LINUX Bourne-Again Shell Script | 26 | # | | 27 | # | PURPOSE : This bash script file used to copy several files that | 28 | # | | 29 | # | is gerenated by oracle datapump tool with expdp command | 30 | # | | 31 | # | from local to another linux server via scp (secure copy) | 32 | # | | 33 | # | which is a remote file copy program, and the premise is | 34 | # | | 35 | # | to configure SSH mutual trust function between local and | 36 | # | | 37 | # | remote server, if it the two hosts configured SSH mutual | 38 | # | | 39 | # | trust function each other, you can directly use SSH | 40 | # | | 41 | # | command to connect to another host from this one. Other- | 42 | # | | 43 | # | wise you will need to enter current user's password from | 44 | # | | 45 | # | local host, which will produce interaction. And if using | 46 | # | | 47 | # | shell script it's the most taboo to produce interaction. | 48 | # | | 49 | # | PARAMETERS : None. | 50 | # | | 51 | # | MODIFIED : 01/28/2019 (dd/mm/yyyy) | 52 | # | | 53 | # | NOTE : As with any code, ensure to test this script in a | 54 | # | | 55 | # | development environment before attempting to run it in | 56 | # | | 57 | # | production. | 58 | # | | 59 | # +------------------------------------------------------------------------+ 60 | 61 | # +------------------------------------------------------------------------+ 62 | # | | 63 | # | EXPORT ENVIRONMENT VARIABLE OF ORACLE USER | 64 | # | | 65 | # +------------------------------------------------------------------------+ 66 | 67 | source ~/.bash_profile 68 | 69 | # +------------------------------------------------------------------------+ 70 | # | | 71 | # | GLOBAL VARIABLES ABOUT THE ABSOLUTE PATH OF THE SHELL COMMAND | 72 | # | | 73 | # +------------------------------------------------------------------------+ 74 | 75 | export AWK=`which awk` 76 | 77 | export CUT=`which cut` 78 | 79 | export DATE=`which date` 80 | 81 | export DF=`which df` 82 | 83 | export DU=`which du` 84 | 85 | export ECHO=`which echo` 86 | 87 | export EXPR=`which expr` 88 | 89 | export GREP=`which grep` 90 | 91 | export LS=`which ls` 92 | 93 | export RM=`which rm` 94 | 95 | export SCP=`which scp` 96 | 97 | export SCRIPT=`which script` 98 | 99 | export SSH=`which ssh` 100 | 101 | export TEE=`which tee` 102 | 103 | export UNIQ=`which uniq` 104 | 105 | # +------------------------------------------------------------------------+ 106 | # | | 107 | # | CHANGE CURRENT DIRECTORY TO EXPDP DIRECTORY OF ORACLE USER WITH CD | 108 | # | | 109 | # +------------------------------------------------------------------------+ 110 | 111 | cd /u01/oradata/rman_backup/expdp 112 | 113 | # +------------------------------------------------------------------------+ 114 | # | | 115 | # | GLOBAL VARIABLES ABOUT THE BACKTICK EXECUTION RESULT OF THE SHELL | 116 | # | | 117 | # +------------------------------------------------------------------------+ 118 | 119 | export CURRENT_DATE=`$DATE +%Y%m%d` 120 | 121 | export EXPDP_DMP=`$LS *.dmp | $CUT -d'_' -f5 | $UNIQ` 122 | 123 | export EXPDP_TOTAL_SIZE_M=`$DU -m *\`$DATE +%Y%m%d\`* | $CUT -f1 | $AWK '{sum += $1};END {print sum}'` 124 | 125 | # +------------------------------------------------------------------------+ 126 | # | | 127 | # | GLOBAL VARIABLES ABOUT STRINGS AND ABSOLUTE PATH OF THE SHELL COMMAND | 128 | # | | 129 | # +------------------------------------------------------------------------+ 130 | 131 | # REMOTE DISK ARRAY IS "/u01/oradata". 132 | # $ df -h 133 | # Filesystem Size Used Avail Use% Mounted on 134 | # /dev/sda2 212G 5.6G 195G 3% / 135 | # tmpfs 63G 72K 63G 1% /dev/shm 136 | # /dev/sda1 190M 32M 149M 18% /boot 137 | # /dev/sdb1 47T 42T 2.5T 95% /u01/oradata <<== 138 | # 139 | # $ cd /u01/oradata/ 140 | # $ ls -lrth |less 141 | # total 42T 142 | # ...... 143 | # -rw-r--r--. 1 oracle oracle 16K Jan 29 04:27 xxxx_base_20190129040001.log 144 | # -rw-r-----. 1 oracle oracle 31G Jan 29 04:27 xxxx_base_20190129040001_03.dmp 145 | # -rw-r-----. 1 oracle oracle 31G Jan 29 04:27 xxxx_base_20190129040001_02.dmp 146 | # -rw-r-----. 1 oracle oracle 99G Jan 29 04:27 xxxx_base_20190129040001_01.dmp 147 | # -rw-r--r--. 1 oracle oracle 16K Jan 30 04:28 xxxx_base_20190130040001.log 148 | # -rw-r-----. 1 oracle oracle 31G Jan 30 04:28 xxxx_base_20190130040001_03.dmp 149 | # -rw-r-----. 1 oracle oracle 31G Jan 30 04:28 xxxx_base_20190130040001_02.dmp 150 | # -rw-r-----. 1 oracle oracle 99G Jan 30 04:28 xxxx_base_20190130040001_01.dmp 151 | # ...... 152 | 153 | export REMOTE_DISK_ARRAY='/u01/oradata' 154 | 155 | export SCP_LOG_PATH='/u01/oradata01/rman_backup/scp_expdp_base_log' 156 | 157 | export SCP_LOG_FILE=$SCP_LOG_PATH/scp_expdp_base_`$DATE +%Y%m%d%H%M%S`.log 158 | 159 | # +------------------------------------------------------------------------+ 160 | # | | 161 | # | GLOBAL FUNCTIONS, ASSUME THAT REMOTE SERVER'S IP IS "192.168.1.2" AND | 162 | # | | 163 | # | LOCAL SERVER IS "192.168.1.1" | 164 | # | | 165 | # +------------------------------------------------------------------------+ 166 | 167 | function scp_expdp_parallel () { 168 | 169 | AVAIL_DISK_SIZE_M=`$SSH oracle@192.168.1.2 $DF -m | $GREP $REMOTE_DISK_ARRAY | $AWK '{print $4}'` 170 | 171 | if [ `$EXPR $AVAIL_DISK_SIZE_M / 1024` -gt `$EXPR $EXPDP_TOTAL_SIZE_M / 1024` ]; then 172 | 173 | for j in $EXPDP_DMP; 174 | 175 | do 176 | 177 | EXPDP_DATE=`$ECHO $j | $CUT -c 1-8` 178 | 179 | if [ $EXPDP_DATE -eq $CURRENT_DATE ]; then 180 | 181 | $SCRIPT -a $SCP_LOG_FILE -c "$SCP -p *$j* oracle@192.168.1.2:$REMOTE_DISK_ARRAY" 182 | 183 | if [ `$ECHO $?` -ne 0 ]; then 184 | 185 | $ECHO -e "\nRemote copy all of dmp and log files that are generated today failed. Please check error information from log file.\n" | $TEE -a $SCP_LOG_FILE 186 | 187 | fi 188 | 189 | fi 190 | 191 | done 192 | 193 | exit; 194 | 195 | else 196 | 197 | $ECHO -e "\nInsufficient disk space!!!"; 198 | 199 | fi 200 | } 201 | 202 | # +------------------------------------------------------------------------+ 203 | # | | 204 | # | CALL FUNCTIONS | 205 | # | | 206 | # +------------------------------------------------------------------------+ 207 | 208 | scp_expdp_parallel 209 | 210 | # As you can see there're scp related log file and its stuff on it on local server. 211 | # 212 | # [oracle@xxxx ~]$ cd /u01/oradata01/rman_backup/ 213 | # [oracle@xxxx rman_backup]$ 214 | # [oracle@xxxx rman_backup]$ cd scp_expdp_base_log/ 215 | # [oracle@xxxx scp_expdp_base_log]$ 216 | # [oracle@xxxx scp_expdp_base_log]$ ls -lrth * 217 | # ...... 218 | # -rw-r--r-- 1 oracle oinstall 117K Jan 29 08:56 scp_expdp_base_20190129083124.log 219 | # -rw-r--r-- 1 oracle oinstall 117K Jan 30 05:24 scp_expdp_base_20190130050001.log 220 | # ...... 221 | # [oracle@xxxx scp_expdp_base_log]$ 222 | # [oracle@xxxx scp_expdp_base_log]$ cat scp_expdp_base_20190129083124.log 223 | # Script started on Tue 29 Jan 2019 05:00:02 AM CST 224 | # xxxx_base_20190129040001_01.dmp 100% 99GB 110.7MB/s 15:11 225 | # xxxx_base_20190129040001_02.dmp 100% 31GB 110.9MB/s 04:46 226 | # xxxx_base_20190129040001_03.dmp 100% 30GB 111.0MB/s 04:40 227 | # xxxx_base_20190129040001.log 100% 15KB 12.0MB/s 00:00 228 | # 229 | # Script done on Tue 29 Jan 2019 05:24:41 AM CST 230 | # [oracle@xxxx scp_expdp_base_log]$ 231 | # [oracle@xxxx scp_expdp_base_log]$ cat scp_expdp_base_20190130050001.log 232 | # Script started on Wed 30 Jan 2019 05:00:02 AM CST 233 | # xxxx_base_20190130040001_01.dmp 100% 99GB 110.6MB/s 15:12 234 | # xxxx_base_20190130040001_02.dmp 100% 30GB 110.7MB/s 04:41 235 | # xxxx_base_20190130040001_03.dmp 100% 31GB 110.8MB/s 04:44 236 | # xxxx_base_20190130040001.log 100% 15KB 4.7MB/s 00:00 237 | # 238 | # Script done on Wed 30 Jan 2019 05:24:41 AM CST 239 | -------------------------------------------------------------------------------- /oracle_service/README.md: -------------------------------------------------------------------------------- 1 | # The Two Approach of Startup Oracle Instance(s) Automatically After Restarting Server 2 | 3 | ### 1. Creating a Linux SHELL script `oracle` in directory `/etc/init.d/` and doing the further configuration 4 | 5 | - #### About how to create `oracle`, see oracle 6 | - #### Doing the further configuration to `oracle` 7 | - ##### Changing file mode bits to `oracle` 8 | ```bash 9 | [root@test init.d]# pwd 10 | /etc/init.d 11 | [root@test init.d]# ls -lrht oracle 12 | -rw-r--r-- 1 root root 5.4K Apr 17 10:40 oracle 13 | [root@test init.d]# chmod 755 oracle 14 | [root@test init.d]# 15 | [root@test init.d]# ls -lrht oracle 16 | -rwxr-xr-x 1 root root 5.4K Apr 17 10:40 oracle 17 | ``` 18 | - ##### Adding this new service `oracle` for management by `chkconfig` 19 | ```bash 20 | [root@test init.d]# chkconfig --add oracle 21 | [root@test init.d]# 22 | ``` 23 | - ##### Checking list the service `oracle` which chkconfig knows about, and whether it's stopped or started in each runlevel 24 | ```bash 25 | [root@test init.d]# chkconfig --list oracle 26 | 27 | Note: This output shows SysV services only and does not include native 28 | systemd services. SysV configuration data might be overridden by native 29 | systemd configuration. 30 | 31 | If you want to list systemd services use 'systemctl list-unit-files'. 32 | To see services enabled on particular target use 33 | 'systemctl list-dependencies [target]'. 34 | 35 | oracle 0:off 1:off 2:on 3:on 4:on 5:on 6:off 36 | ``` 37 | - ##### You can also restart, stop or start the service `oracle` via `service` command 38 | ```bash 39 | [root@test ~]# service oracle restart 40 | /etc/init.d/oracle : (shutdown oracle database ...) 41 | /etc/init.d/oracle : (start oracle database ...) 42 | [root@test ~]# 43 | [root@test ~]# service oracle stop 44 | /etc/init.d/oracle : (shutdown oracle database ...) 45 | [root@test ~]# 46 | [root@test ~]# su - oracle 47 | [oracle@test ~]$ ps -ef | grep ora_ 48 | oracle 20991 20823 0 09:42 pts/6 00:00:00 grep --color=auto ora_ 49 | [oracle@test ~]$ 50 | [oracle@test ~]$ lsnrctl status 51 | 52 | LSNRCTL for Linux: Version 19.3.0.0.0 - Production on 25-APR-2021 09:42:57 53 | 54 | Copyright (c) 1991, 2019, Oracle. All rights reserved. 55 | 56 | Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=test)(PORT=1521))) 57 | TNS-12541: TNS:no listener 58 | TNS-12560: TNS:protocol adapter error 59 | TNS-00511: No listener 60 | Linux Error: 111: Connection refused 61 | [oracle@test ~]$ 62 | [oracle@test ~]$ exit 63 | [root@test ~]# service oracle start 64 | /etc/init.d/oracle : (start oracle database ...) 65 | [root@test ~]# 66 | [root@test ~]# su - oracle 67 | [oracle@test ~]$ ps -ef | grep ora_ 68 | oracle 21316 1 0 09:45 ? 00:00:00 ora_pmon_testdb 69 | oracle 21318 1 0 09:45 ? 00:00:00 ora_clmn_testdb 70 | oracle 21320 1 0 09:45 ? 00:00:00 ora_psp0_testdb 71 | oracle 21323 1 2 09:45 ? 00:00:01 ora_vktm_testdb 72 | oracle 21327 1 0 09:45 ? 00:00:00 ora_gen0_testdb 73 | oracle 21329 1 15 09:45 ? 00:00:13 ora_mman_testdb 74 | oracle 21333 1 0 09:45 ? 00:00:00 ora_gen1_testdb 75 | oracle 21336 1 0 09:45 ? 00:00:00 ora_diag_testdb 76 | oracle 21338 1 0 09:45 ? 00:00:00 ora_ofsd_testdb 77 | oracle 21341 1 0 09:45 ? 00:00:00 ora_dbrm_testdb 78 | oracle 21343 1 1 09:45 ? 00:00:00 ora_vkrm_testdb 79 | oracle 21345 1 0 09:45 ? 00:00:00 ora_svcb_testdb 80 | oracle 21347 1 0 09:45 ? 00:00:00 ora_pman_testdb 81 | oracle 21349 1 2 09:45 ? 00:00:02 ora_dia0_testdb 82 | oracle 21351 1 0 09:45 ? 00:00:00 ora_dbw0_testdb 83 | oracle 21353 1 0 09:45 ? 00:00:00 ora_dbw1_testdb 84 | oracle 21356 1 0 09:45 ? 00:00:00 ora_dbw2_testdb 85 | oracle 21358 1 0 09:45 ? 00:00:00 ora_dbw3_testdb 86 | oracle 21360 1 0 09:45 ? 00:00:00 ora_dbw4_testdb 87 | oracle 21362 1 0 09:45 ? 00:00:00 ora_dbw5_testdb 88 | oracle 21364 1 0 09:45 ? 00:00:00 ora_dbw6_testdb 89 | oracle 21366 1 0 09:45 ? 00:00:00 ora_dbw7_testdb 90 | oracle 21368 1 0 09:45 ? 00:00:00 ora_dbw8_testdb 91 | oracle 21370 1 0 09:45 ? 00:00:00 ora_dbw9_testdb 92 | oracle 21372 1 0 09:45 ? 00:00:00 ora_lgwr_testdb 93 | oracle 21374 1 0 09:45 ? 00:00:00 ora_ckpt_testdb 94 | oracle 21376 1 0 09:45 ? 00:00:00 ora_lg00_testdb 95 | oracle 21378 1 0 09:45 ? 00:00:00 ora_smon_testdb 96 | oracle 21380 1 0 09:45 ? 00:00:00 ora_lg01_testdb 97 | oracle 21382 1 0 09:45 ? 00:00:00 ora_smco_testdb 98 | oracle 21384 1 0 09:45 ? 00:00:00 ora_lg02_testdb 99 | oracle 21386 1 0 09:45 ? 00:00:00 ora_reco_testdb 100 | oracle 21388 1 0 09:45 ? 00:00:00 ora_w000_testdb 101 | oracle 21390 1 0 09:45 ? 00:00:00 ora_lreg_testdb 102 | oracle 21392 1 0 09:45 ? 00:00:00 ora_lg03_testdb 103 | oracle 21394 1 0 09:45 ? 00:00:00 ora_pxmn_testdb 104 | oracle 21396 1 0 09:45 ? 00:00:00 ora_w001_testdb 105 | oracle 21400 1 4 09:45 ? 00:00:03 ora_mmon_testdb 106 | oracle 21402 1 0 09:45 ? 00:00:00 ora_mmnl_testdb 107 | oracle 21404 1 0 09:45 ? 00:00:00 ora_d000_testdb 108 | oracle 21406 1 0 09:45 ? 00:00:00 ora_s000_testdb 109 | oracle 21408 1 0 09:45 ? 00:00:00 ora_tmon_testdb 110 | oracle 21414 1 0 09:45 ? 00:00:00 ora_m000_testdb 111 | oracle 21416 1 0 09:45 ? 00:00:00 ora_m001_testdb 112 | oracle 21423 1 0 09:45 ? 00:00:00 ora_tt00_testdb 113 | oracle 21425 1 0 09:45 ? 00:00:00 ora_arc0_testdb 114 | oracle 21427 1 0 09:45 ? 00:00:00 ora_tt01_testdb 115 | oracle 21429 1 0 09:45 ? 00:00:00 ora_arc1_testdb 116 | oracle 21431 1 0 09:45 ? 00:00:00 ora_arc2_testdb 117 | oracle 21433 1 0 09:45 ? 00:00:00 ora_arc3_testdb 118 | oracle 21435 1 0 09:45 ? 00:00:00 ora_tt02_testdb 119 | oracle 21440 1 0 09:45 ? 00:00:00 ora_aqpc_testdb 120 | oracle 21443 1 2 09:45 ? 00:00:01 ora_cjq0_testdb 121 | oracle 21511 1 0 09:45 ? 00:00:00 ora_p000_testdb 122 | oracle 21513 1 0 09:45 ? 00:00:00 ora_p001_testdb 123 | oracle 21515 1 0 09:45 ? 00:00:00 ora_p002_testdb 124 | oracle 21517 1 0 09:45 ? 00:00:00 ora_p003_testdb 125 | oracle 21519 1 0 09:45 ? 00:00:00 ora_p004_testdb 126 | oracle 21521 1 0 09:45 ? 00:00:00 ora_p005_testdb 127 | oracle 21523 1 0 09:45 ? 00:00:00 ora_p006_testdb 128 | oracle 21525 1 0 09:45 ? 00:00:00 ora_p007_testdb 129 | oracle 21527 1 0 09:45 ? 00:00:00 ora_p008_testdb 130 | oracle 21529 1 0 09:45 ? 00:00:00 ora_p009_testdb 131 | oracle 21531 1 0 09:45 ? 00:00:00 ora_p00a_testdb 132 | oracle 21533 1 0 09:45 ? 00:00:00 ora_p00b_testdb 133 | oracle 21535 1 0 09:45 ? 00:00:00 ora_p00c_testdb 134 | oracle 21537 1 0 09:45 ? 00:00:00 ora_p00d_testdb 135 | oracle 21539 1 0 09:45 ? 00:00:00 ora_p00e_testdb 136 | oracle 21541 1 0 09:45 ? 00:00:00 ora_p00f_testdb 137 | oracle 21543 1 0 09:45 ? 00:00:00 ora_p00g_testdb 138 | oracle 21545 1 0 09:45 ? 00:00:00 ora_p00h_testdb 139 | oracle 21547 1 0 09:45 ? 00:00:00 ora_p00i_testdb 140 | oracle 21549 1 0 09:45 ? 00:00:00 ora_p00j_testdb 141 | oracle 21551 1 0 09:45 ? 00:00:00 ora_p00k_testdb 142 | oracle 21553 1 0 09:45 ? 00:00:00 ora_p00l_testdb 143 | oracle 21556 1 0 09:45 ? 00:00:00 ora_w002_testdb 144 | oracle 21559 1 0 09:45 ? 00:00:00 ora_p00m_testdb 145 | oracle 21561 1 0 09:45 ? 00:00:00 ora_p00n_testdb 146 | oracle 21563 1 0 09:45 ? 00:00:00 ora_p00o_testdb 147 | oracle 21565 1 0 09:45 ? 00:00:00 ora_p00p_testdb 148 | oracle 21567 1 0 09:45 ? 00:00:00 ora_p00q_testdb 149 | oracle 21569 1 0 09:45 ? 00:00:00 ora_p00r_testdb 150 | oracle 21571 1 0 09:45 ? 00:00:00 ora_p00s_testdb 151 | oracle 21573 1 0 09:45 ? 00:00:00 ora_p00t_testdb 152 | oracle 21575 1 0 09:45 ? 00:00:00 ora_p00u_testdb 153 | oracle 21578 1 0 09:45 ? 00:00:00 ora_p00v_testdb 154 | oracle 21580 1 0 09:45 ? 00:00:00 ora_p00w_testdb 155 | oracle 21582 1 0 09:45 ? 00:00:00 ora_p00x_testdb 156 | oracle 21584 1 0 09:45 ? 00:00:00 ora_p00y_testdb 157 | oracle 21586 1 0 09:45 ? 00:00:00 ora_p00z_testdb 158 | oracle 21588 1 0 09:45 ? 00:00:00 ora_p010_testdb 159 | oracle 21590 1 0 09:45 ? 00:00:00 ora_p011_testdb 160 | oracle 21592 1 0 09:45 ? 00:00:00 ora_p012_testdb 161 | oracle 21594 1 0 09:45 ? 00:00:00 ora_p013_testdb 162 | oracle 21596 1 0 09:45 ? 00:00:00 ora_p014_testdb 163 | oracle 21598 1 0 09:45 ? 00:00:00 ora_p015_testdb 164 | oracle 21600 1 0 09:45 ? 00:00:00 ora_p016_testdb 165 | oracle 21602 1 0 09:45 ? 00:00:00 ora_p017_testdb 166 | oracle 21604 1 0 09:45 ? 00:00:00 ora_p018_testdb 167 | oracle 21606 1 0 09:45 ? 00:00:00 ora_p019_testdb 168 | oracle 21612 1 0 09:45 ? 00:00:00 ora_p01a_testdb 169 | oracle 21620 1 0 09:45 ? 00:00:00 ora_p01b_testdb 170 | oracle 21636 1 0 09:45 ? 00:00:00 ora_p01c_testdb 171 | oracle 21669 1 0 09:45 ? 00:00:00 ora_p01d_testdb 172 | oracle 21690 1 0 09:45 ? 00:00:00 ora_p01e_testdb 173 | oracle 21747 1 0 09:45 ? 00:00:00 ora_p01f_testdb 174 | oracle 21752 1 0 09:45 ? 00:00:00 ora_p01g_testdb 175 | oracle 21754 1 0 09:45 ? 00:00:00 ora_p01h_testdb 176 | oracle 21783 1 0 09:45 ? 00:00:00 ora_p01i_testdb 177 | oracle 21838 1 0 09:45 ? 00:00:00 ora_p01j_testdb 178 | oracle 21841 1 0 09:45 ? 00:00:00 ora_p01k_testdb 179 | oracle 21845 1 0 09:45 ? 00:00:00 ora_p01l_testdb 180 | oracle 21866 1 0 09:45 ? 00:00:00 ora_p01m_testdb 181 | oracle 21875 1 0 09:45 ? 00:00:00 ora_p01n_testdb 182 | oracle 21890 1 0 09:45 ? 00:00:00 ora_p01o_testdb 183 | oracle 21906 1 0 09:45 ? 00:00:00 ora_p01p_testdb 184 | oracle 21929 1 0 09:45 ? 00:00:00 ora_p01q_testdb 185 | oracle 21968 1 0 09:45 ? 00:00:00 ora_p01r_testdb 186 | oracle 21970 1 0 09:45 ? 00:00:00 ora_p01s_testdb 187 | oracle 21973 1 0 09:45 ? 00:00:00 ora_p01t_testdb 188 | oracle 21977 1 0 09:45 ? 00:00:00 ora_p01u_testdb 189 | oracle 21979 1 0 09:45 ? 00:00:00 ora_p01v_testdb 190 | oracle 21981 1 0 09:45 ? 00:00:00 ora_p01w_testdb 191 | oracle 21996 1 0 09:45 ? 00:00:00 ora_p01x_testdb 192 | oracle 22006 1 0 09:45 ? 00:00:00 ora_p01y_testdb 193 | oracle 22008 1 0 09:45 ? 00:00:00 ora_p01z_testdb 194 | oracle 22010 1 0 09:45 ? 00:00:00 ora_p020_testdb 195 | oracle 22012 1 0 09:45 ? 00:00:00 ora_p021_testdb 196 | oracle 22014 1 0 09:45 ? 00:00:00 ora_p022_testdb 197 | oracle 22016 1 0 09:45 ? 00:00:00 ora_p023_testdb 198 | oracle 22018 1 0 09:45 ? 00:00:00 ora_p024_testdb 199 | oracle 22020 1 0 09:45 ? 00:00:00 ora_p025_testdb 200 | oracle 22022 1 0 09:45 ? 00:00:00 ora_p026_testdb 201 | oracle 22024 1 0 09:45 ? 00:00:00 ora_p027_testdb 202 | oracle 22026 1 0 09:45 ? 00:00:00 ora_p028_testdb 203 | oracle 22028 1 0 09:45 ? 00:00:00 ora_p029_testdb 204 | oracle 22031 1 0 09:45 ? 00:00:00 ora_p02a_testdb 205 | oracle 22033 1 0 09:45 ? 00:00:00 ora_p02b_testdb 206 | oracle 22035 1 0 09:45 ? 00:00:00 ora_p02c_testdb 207 | oracle 22037 1 0 09:45 ? 00:00:00 ora_p02d_testdb 208 | oracle 22039 1 0 09:45 ? 00:00:00 ora_p02e_testdb 209 | oracle 22041 1 0 09:45 ? 00:00:00 ora_p02f_testdb 210 | oracle 22043 1 0 09:45 ? 00:00:00 ora_p02g_testdb 211 | oracle 22045 1 0 09:45 ? 00:00:00 ora_p02h_testdb 212 | oracle 22047 1 0 09:45 ? 00:00:00 ora_p02i_testdb 213 | oracle 22049 1 0 09:45 ? 00:00:00 ora_p02j_testdb 214 | oracle 22051 1 0 09:45 ? 00:00:00 ora_p02k_testdb 215 | oracle 22053 1 0 09:45 ? 00:00:00 ora_p02l_testdb 216 | oracle 22055 1 0 09:45 ? 00:00:00 ora_p02m_testdb 217 | oracle 22057 1 0 09:45 ? 00:00:00 ora_p02n_testdb 218 | oracle 22059 1 0 09:45 ? 00:00:00 ora_p02o_testdb 219 | oracle 22061 1 0 09:45 ? 00:00:00 ora_p02p_testdb 220 | oracle 22063 1 0 09:45 ? 00:00:00 ora_p02q_testdb 221 | oracle 22065 1 0 09:45 ? 00:00:00 ora_p02r_testdb 222 | oracle 22067 1 0 09:45 ? 00:00:00 ora_p02s_testdb 223 | oracle 22069 1 0 09:45 ? 00:00:00 ora_p02t_testdb 224 | oracle 22071 1 0 09:45 ? 00:00:00 ora_p02u_testdb 225 | oracle 22073 1 0 09:45 ? 00:00:00 ora_p02v_testdb 226 | oracle 22075 1 0 09:45 ? 00:00:00 ora_p02w_testdb 227 | oracle 22082 1 0 09:45 ? 00:00:00 ora_p02x_testdb 228 | oracle 22084 1 0 09:45 ? 00:00:00 ora_p02y_testdb 229 | oracle 22086 1 0 09:45 ? 00:00:00 ora_p02z_testdb 230 | oracle 22088 1 0 09:45 ? 00:00:00 ora_p030_testdb 231 | oracle 22090 1 0 09:45 ? 00:00:00 ora_p031_testdb 232 | oracle 22092 1 0 09:45 ? 00:00:00 ora_p032_testdb 233 | oracle 22094 1 0 09:45 ? 00:00:00 ora_p033_testdb 234 | oracle 22096 1 0 09:45 ? 00:00:00 ora_p034_testdb 235 | oracle 22098 1 0 09:45 ? 00:00:00 ora_p035_testdb 236 | oracle 22100 1 0 09:45 ? 00:00:00 ora_p036_testdb 237 | oracle 22102 1 0 09:45 ? 00:00:00 ora_p037_testdb 238 | oracle 22104 1 0 09:45 ? 00:00:00 ora_p038_testdb 239 | oracle 22106 1 0 09:45 ? 00:00:00 ora_p039_testdb 240 | oracle 22108 1 0 09:45 ? 00:00:00 ora_p03a_testdb 241 | oracle 22110 1 0 09:45 ? 00:00:00 ora_p03b_testdb 242 | oracle 22112 1 0 09:45 ? 00:00:00 ora_p03c_testdb 243 | oracle 22114 1 0 09:45 ? 00:00:00 ora_p03d_testdb 244 | oracle 22116 1 0 09:45 ? 00:00:00 ora_p03e_testdb 245 | oracle 22118 1 0 09:45 ? 00:00:00 ora_p03f_testdb 246 | oracle 22120 1 0 09:45 ? 00:00:00 ora_p03g_testdb 247 | oracle 22122 1 0 09:45 ? 00:00:00 ora_p03h_testdb 248 | oracle 22125 1 0 09:45 ? 00:00:00 ora_p03i_testdb 249 | oracle 22127 1 0 09:45 ? 00:00:00 ora_p03j_testdb 250 | oracle 22129 1 0 09:45 ? 00:00:00 ora_p03k_testdb 251 | oracle 22131 1 0 09:45 ? 00:00:00 ora_p03l_testdb 252 | oracle 22133 1 0 09:45 ? 00:00:00 ora_p03m_testdb 253 | oracle 22135 1 0 09:45 ? 00:00:00 ora_p03n_testdb 254 | oracle 22137 1 0 09:45 ? 00:00:00 ora_p03o_testdb 255 | oracle 22139 1 0 09:45 ? 00:00:00 ora_p03p_testdb 256 | oracle 22141 1 0 09:45 ? 00:00:00 ora_p03q_testdb 257 | oracle 22143 1 0 09:45 ? 00:00:00 ora_p03r_testdb 258 | oracle 22145 1 0 09:45 ? 00:00:00 ora_p03s_testdb 259 | oracle 22147 1 0 09:45 ? 00:00:00 ora_w003_testdb 260 | oracle 22149 1 0 09:45 ? 00:00:00 ora_p03t_testdb 261 | oracle 22151 1 0 09:45 ? 00:00:00 ora_p03u_testdb 262 | oracle 22153 1 0 09:45 ? 00:00:00 ora_p03v_testdb 263 | oracle 22155 1 0 09:45 ? 00:00:00 ora_p03w_testdb 264 | oracle 22157 1 0 09:45 ? 00:00:00 ora_p03x_testdb 265 | oracle 22159 1 0 09:45 ? 00:00:00 ora_p03y_testdb 266 | oracle 22161 1 0 09:45 ? 00:00:00 ora_p03z_testdb 267 | oracle 22163 1 0 09:45 ? 00:00:00 ora_p040_testdb 268 | oracle 22165 1 0 09:45 ? 00:00:00 ora_p041_testdb 269 | oracle 22167 1 0 09:45 ? 00:00:00 ora_p042_testdb 270 | oracle 22169 1 0 09:45 ? 00:00:00 ora_p043_testdb 271 | oracle 22171 1 0 09:45 ? 00:00:00 ora_p044_testdb 272 | oracle 22173 1 0 09:45 ? 00:00:00 ora_p045_testdb 273 | oracle 22175 1 0 09:45 ? 00:00:00 ora_p046_testdb 274 | oracle 22177 1 0 09:45 ? 00:00:00 ora_p047_testdb 275 | oracle 22179 1 0 09:45 ? 00:00:00 ora_p048_testdb 276 | oracle 22181 1 0 09:45 ? 00:00:00 ora_p049_testdb 277 | oracle 22183 1 0 09:45 ? 00:00:00 ora_p04a_testdb 278 | oracle 22185 1 0 09:45 ? 00:00:00 ora_p04b_testdb 279 | oracle 22187 1 0 09:45 ? 00:00:00 ora_p04c_testdb 280 | oracle 22189 1 0 09:45 ? 00:00:00 ora_p04d_testdb 281 | oracle 22191 1 0 09:45 ? 00:00:00 ora_p04e_testdb 282 | oracle 22193 1 0 09:45 ? 00:00:00 ora_p04f_testdb 283 | oracle 22208 1 5 09:45 ? 00:00:03 ora_m002_testdb 284 | oracle 22233 1 0 09:45 ? 00:00:00 ora_qm02_testdb 285 | oracle 22237 1 0 09:45 ? 00:00:00 ora_q002_testdb 286 | oracle 22239 1 0 09:45 ? 00:00:00 ora_q003_testdb 287 | oracle 22242 1 0 09:45 ? 00:00:00 ora_w004_testdb 288 | oracle 22304 20823 0 09:46 pts/6 00:00:00 grep --color=auto ora_ 289 | [oracle@test ~]$ 290 | [oracle@test ~]$ lsnrctl status 291 | 292 | LSNRCTL for Linux: Version 19.3.0.0.0 - Production on 25-APR-2021 09:51:45 293 | 294 | Copyright (c) 1991, 2019, Oracle. All rights reserved. 295 | 296 | Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=test)(PORT=1521))) 297 | STATUS of the LISTENER 298 | ------------------------ 299 | Alias LISTENER 300 | Version TNSLSNR for Linux: Version 19.3.0.0.0 - Production 301 | Start Date 25-APR-2021 09:45:00 302 | Uptime 0 days 0 hr. 6 min. 44 sec 303 | Trace Level off 304 | Security ON: Local OS Authentication 305 | SNMP OFF 306 | Listener Parameter File /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora 307 | Listener Log File /opt/oracle/diag/tnslsnr/ncet/listener/alert/log.xml 308 | Listening Endpoints Summary... 309 | (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=test)(PORT=1521))) 310 | The listener supports no services 311 | The command completed successfully 312 | ``` 313 | 314 | ### 2. Creating a Linux SHELL script `automatically_open_oracle.sh` in home directory of `oracle` user and then invoking it in directory `/etc/rc.loal` 315 | 316 | - #### About how to create `automatically_open_oracle.sh`, see automatically_open_oracle.sh 317 | - #### Invoking `automatically_open_oracle.sh` in directory `/etc/rc.loal` 318 | ```bash 319 | [root@test ~]# cat /etc/rc.local 320 | #!/bin/sh 321 | # 322 | # This script will be executed *after* all the other init scripts. 323 | # You can put your own initialization stuff in here if you don't 324 | # want to do the full Sys V style init stuff. 325 | # 326 | touch /var/lock/subsys/local 327 | 328 | # Automatically Startup Oracle Database Instance after restarting server 329 | # sh /home/oracle/automatically_open_oracle.sh 330 | ``` 331 | 332 | ### 3. License 333 | 334 | `oracle_service` is licensed under the **GNU** (a recursive acronym for "GNU's Not Unix!"), the Version `3.0` of `GENERAL PUBLIC LICENSE`. 335 | You may obtain a copy of the License at GPL 3.0. 336 | --------------------------------------------------------------------------------