-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdbinfo.py
executable file
·89 lines (79 loc) · 3.15 KB
/
dbinfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python2
import os, sys
from subprocess import Popen, PIPE
from backupcommon import Configuration, scriptpath
def printhelp():
print "Usage: dbinfo.py <config>"
sys.exit(2)
if len(sys.argv) != 2:
printhelp()
# Read configuration
configsection = sys.argv[1]
Configuration.init(configsection)
gimanaged = Configuration.get('gimanaged').upper() == 'TRUE'
if not gimanaged:
print "gimanaged option is not set to TRUE for this database"
sys.exit(2)
# Set oracle home, if it is not configured separately, take it from environment
oraclehome = Configuration.get('oraclehome','generic')
if os.environ.get('ORACLE_SID'):
del os.environ['ORACLE_SID']
os.environ['ORACLE_HOME'] = oraclehome
os.environ['NLS_DATE_FORMAT'] = 'yyyy-mm-dd hh24:mi:ss'
# Get software version
p = Popen([os.path.join(scriptpath(), "get_oracle_version.sh"), oraclehome], stdout=PIPE, stderr=None, stdin=None)
oracleversion,dataerr = p.communicate()
if oracleversion < "11.1":
print "Detected Oracle software version %s is too old" % oracleversion
sys.exit(1)
# srvctl config database
print "== Database configuration =="
p = Popen([os.path.join(oraclehome, 'bin', 'srvctl'), 'config', 'database', '-d', configsection], stdout=PIPE, stderr=None, stdin=None)
datain,dataerr = p.communicate()
print datain
def printserviceinfo(si):
if len(si) > 0 and si['enabled']:
if oracleversion < "12.1":
s = "srvctl add service -d %s -s %s -j %s -B %s -r %s" % (configsection, si.get('name',''), si.get('clb',''), si.get('rlb',''), si.get('preferred',''))
if si['available']:
s+= " -a %s" % si['available']
print s
if si['edition']:
print "srvctl add service -d %s -s %s -t %s" % (configsection, si.get('name',''), si.get('edition',''))
else:
s = "srvctl add service -database %s -service %s -preferred %s" % (configsection, si.get('name',''), si.get('preferred',''))
if si.get('available', None):
s+= " -available %s" % si['available']
if si.get('edition', None):
s+= " -edition %s" % si['edition']
if si.get('pluggable', None):
s+= " -pdb %s" % si['pluggable']
print s
# srvctl config service
print "== Service configuration =="
p = Popen([os.path.join(oraclehome, 'bin', 'srvctl'), 'config', 'service', '-d', configsection], stdout=PIPE, stderr=None, stdin=None)
datain,dataerr = p.communicate()
print datain
print "== Service configuration parsed =="
services = {}
currentservice = {}
for line in datain.splitlines():
s = line.split(': ')
if s[0] == 'Service name':
printserviceinfo(currentservice)
currentservice = { 'name': s[1], 'enabled': False }
elif s[0] == 'Edition':
currentservice['edition'] = s[1]
elif s[0] == 'Preferred instances':
currentservice['preferred'] = s[1]
elif s[0] == 'Available instances':
currentservice['available'] = s[1]
elif s[0] == 'Service is enabled':
currentservice['enabled'] = True
elif s[0] == 'Connection Load Balancing Goal':
currentservice['clb'] = s[1]
elif s[0] == 'Runtime Load Balancing Goal':
currentservice['rlb'] = s[1]
elif s[0] == 'Pluggable database name':
currentservice['pluggable'] = s[1]
printserviceinfo(currentservice)