Acquisition scripting for database upgrade version information

Source: Internet
Author: User
Tags dba sqlplus

"Introduction to the Environment"

System environment: Linux + 11g+ Cluster/standalone

"Background description"

Requirements: Every quarter there is a database vulnerability scan repair thing, understand that the scan method is based on the database version to determine whether the current database version to fix the corresponding vulnerability. Only the general vulnerability information is Dbms/ojvm/grid type of vulnerability. If the database is currently maintained, it is easier to get the database version information yourself, but most of the time it is difficult to collect information when you are assisted in upgrading. Need to take database version information and system information quickly to write the scheme or to determine whether the current database needs to upgrade and risk judgment.

"Monitoring and optimization process and ideas"

For the problem described above:

1, host information data collection. ----Direct capture using host commands

Host name (scheme), System version (scheme and patch set download), IP information (determine host IP information), system space (whether to meet backup and upgrade space)

2, data collection of information. ----Using Oracle query Information

Opatch version information, database lsinventory information, database one-of-patch information, audit path (backup software to exclude audit log files)

3, data structure classification. ----standalone, cluster

"Test Results and scripts"

Pass the test script. The results are as follows:

1, host data information: The following:

2, Database information: The following:

"Collect Data script information"

The main implementation features of the script are as follows:

1, using the shell for data processing, the specific script explained as follows:

Cat >oracle_message.sh

######################################################################

# oracle_message.sh

# This script is update check data

# Author CZT

######################################################################

#!/bin/bash

Oracle_user= ' Ps-ef |grep "Ora_pmon_" |grep-v grep |head-1 |awk ' {print $} '

Grid_user= ' Ps-ef |grep "Asm_pmon_" |grep-v grep |head-1 |awk ' {print $} '

process_names= ' Ps-ef |grep "Ora_pmon_" |grep-v grep |awk ' {print $NF} '

process_asms= ' Ps-ef |grep "Asm_pmon_" |grep-v grep |awk ' {print $NF} '

Instance_names= ' echo ${process_names} |sed ' s/ora_pmon_//g '

Instance_names= ' echo ${process_names} |sed ' s/ora_pmon_//g '

Instance_asm= ' echo ${process_asms} |sed ' s/asm_pmon_//g '

V_date= ' Date ' +%y-%m-%d%h:%m:%s ' to set environment variables for Oracle and grid

function get_value_of_parameter{

PARAMETER_NAME=${2}

typeset connect_cmd= ' Connect/as sysdba '

typeset sql_exit_opt= "Whenever SQLError EXIT Sql.sqlcode"

Typeset sql_opt= "Set echo off feedback off heading off underline off"

typeset sql_cmd_cluster= ' Select value from V\ $system _parameter where name= ' "' ${parameter_name} '"

Database_cluster= ' Su-${oracle_user}-C "Export oracle_sid=${1};sqlplus-s/nolog <<!

${connect_cmd}

${SQL_EXIT_OPT}

${SQL_OPT}

${sql_cmd_cluster};

!" `

echo $database _cluster} " to determine whether a database is a cluster function

function get_dba_registry_history{

typeset connect_cmd= ' Connect/as sysdba '

typeset sql_exit_opt= "Whenever SQLError EXIT Sql.sqlcode"

Typeset sql_opt= "Set linesize pagesize echo off feedback off"

typeset sql_cmd_registry= ' select * from Dba_registry_history '

typeset sql_cmd_version= ' select * from v\ $version '

typeset sql_cmd_audit= ' show parameter audit_file_dest '

Su-${oracle_user}-C "Export oracle_sid=${1};sqlplus-s/nolog <<!

Col Action Format A20

Col namespace format A10

Col version Format A28

Col Comments Format A40

Col action_time format A30

Col bundle_series format A15

${connect_cmd}

${SQL_EXIT_OPT}

${SQL_OPT}

${sql_cmd_registry};

${sql_cmd_version};

${sql_cmd_audit};

!"} "" Query Database dictionary information function

function get_asm_registry_history{

typeset connect_cmd= ' Connect/as sysasm '

typeset sql_exit_opt= "Whenever SQLError EXIT Sql.sqlcode"

Typeset sql_opt= "Set linesize pagesize echo off feedback off"

typeset sql_cmd_audit= ' show parameter audit_file_dest '

Su-${grid_user}-C "Export oracle_sid=${1};sqlplus-s/nolog <<!

Col Action Format A20

Col namespace format A10

Col version Format A28

Col Comments Format A40

Col action_time format A30

Col bundle_series format A15

${connect_cmd}

${SQL_EXIT_OPT}

${SQL_OPT}

${sql_cmd_audit};

!"} "" query +asm instance Audit path information function

function get_value_of_system{

Echo-e '

==========================

Hostname

==========================

Hostname

Echo-e '

==========================

Systemrelease

==========================

cat/etc/*release*;

Echo-e '

==========================

System Space

==========================

Df-h;

Echo-e ' (4) SYSTEM HOSTS '

Echo-e '

==========================

System hosts

==========================

Cat/etc/hosts;} "" The collection of host information data functions

function get_value_of_database{

Oracle_base= ' cat/home/oracle/.bash_profile|grep-wi ' export oracle_base ' |awk-f "[=:]" ' {Print $NF} '

Oracle_home= ' cat/home/oracle/.bash_profile|grep-wi ' export oracle_home ' |awk-f "[=:]" ' {Print $NF} '

Echo-e '

==========================

Opatch version

==========================

Su-${oracle_user}-C "${oracle_home}/opatch/opatch version"

Echo-e '

==========================

Opatch lsinventory

==========================

Su-${oracle_user}-C "${oracle_home}/opatch/opatch LSINV"

Echo-e '

==========================

Opatch lspatches

==========================

Su-${oracle_user}-C "${oracle_home}/opatch/opatch lspatches"

}

# # #judge The current user if root,need to root run the script

If [' WhoAmI ' = "root"];then " the script is executed using the root user )

ECHO-E ' * * * Start of LogFile * * *

Echo-e ' Oracle Database Upgrade Statistics geting ' $v _date

# # #check System State

Echo-e '---------------------------------------------SYSTEM State-------------------------------------'

# # #get System State

Get_value_of_system

# # #judge The system has many instance

For instance in ${instance_names}

Do

# # #judge the database cluster

V_database_cluster= ' Get_value_of_parameter ${instance} "Cluster_database" '

if ["${v_database_cluster}" = = "TRUE"];then

Echo-e '

==========================

The Database is RAC

==========================

# # #check Database state

Echo-e '--------------------------------------DATABASE State------------------------------------'

Echo-e '

=============================================================================

The Database is RAC determines the cluster architecture

=============================================================================

# # #get Database Opatch State

Get_value_of_database "" Call Collection database information function

Echo-e '

==========================

Dba Registry History

==========================

Get_dba_registry_history ${instance} " Call collection database information function

Get_asm_registry_history ${instance_asm} " calls acquisition of ASM instance Audit path function

Else

# # #check Database state

Echo-e '--------------------------------------------DATABASE State------------------------------------'

Echo-e '

=============================================================================

The Database is Standlone "" is judged as a stand-alone architecture

=============================================================================

# # #get Database Opatch State

Get_value_of_database

Echo-e '

==========================

Dba Registry History

==========================

Get_dba_registry_history ${instance}

Fi

Done

Echo-e '                                                                                                                                       '                                                                                                              

ECHO-E ' * * * End of LogFile * * *

Else

echo "Use root run the script"

Fi

"Problem thinking"

1, there is a system version limit, the script for the Linux Solaris system to collect data;

2, there is a database version limit, applicable to the 11G version of the database acquisition data;

3, there is an environment variable limit, the profile of Oracle user and grid user needs to adopt standard notation to set variables.

"Summary":

1, in the External Assistance Database vulnerability verification, the use of this script to collect information more quickly, to write a scheme and a faster understanding of the database environment to provide security for database upgrade operations.

2, this script involves the use of root user script to invoke the Oracle and grid user variables, the user's variable setting standards have greater requirements.

Acquisition script for database upgrade version information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.