-
Notifications
You must be signed in to change notification settings - Fork 1
/
snapomatic.oracle
executable file
·374 lines (334 loc) · 13.1 KB
/
snapomatic.oracle
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#! /usr/bin/python3
import sys
pythonversion=sys.version_info
if pythonversion[0] != 3 or (pythonversion[1] < 6 or pythonversion[1] > 11):
print("This script requires Python 3.6 through 3.11")
sys.exit(1)
sys.path.append(sys.path[0] + "/NTAPlib")
import setOracleBackup
import startOracleInstance
import stopOracleInstance
import mountOracleInstance
import openOracleInstance
import discoverOracle
import discoverPaths
import discoverASM
import userio
import smCache
mycache=smCache.smCache()
snapomaticversion='DEV'
validoptions={'backup': {'sid':'multistr', \
'stop':'bool',\
'start':'bool',\
'debug':'bool',\
'force':'bool'},
'protect' : {'sid':'multistr', \
'nobackupmode': 'bool', \
'datafiles': 'bool', \
'snapshot': 'str', \
'prefix': 'str', \
'logs': 'bool', \
'maxcount': 'bool', \
'maxage': 'bool', \
'datafiles': 'bool', \
'debug':'bool'},\
'start' : {'sid':'multistr', \
'mount': 'bool', \
'nomount': 'bool', \
'debug':'bool'},\
'stop' : {'sid':'multistr', \
'debug':'bool',\
'abort':'bool'},\
'open' : {'sid':'multistr', \
'debug':'bool'},\
'mount' : {'sid':'multistr', \
'debug':'bool'},\
'discover' : {'sid':'str', \
'debug':'bool'}}
requiredoptions={'backup' : ['sid',['start','stop']], \
'start' : ['sid'],\
'stop' : ['sid'],\
'protect' : ['sid',['snapshot','prefix']], \
'mount' : ['sid'],\
'open' : ['sid'],\
'discover' : ['sid']}\
mutex=[['start','stop'],['mount','nomount'],['name'],['prefix'],['datafilesonly','logsonly']]
usage="Version " + snapomaticversion + "\n" + \
"backup [--sid]\n" + \
" (name(s) of database SIDs\n\n" + \
" [--start or --stop]\n" + \
" (start or stop backup mode)\n\n" \
" [--force]\n" + \
" (ignore current backup state of datafiles)\n\n" \
" [--debug]\n" + \
" (show debug output)\n\n" + \
"protect [--sid]\n" + \
" (name(s) of database SIDs\n\n" + \
" [--nobackupmode]\n" + \
" (Do not use backup mode; use snapshot-optimized logic)\n\n" \
" [--datafilesonly]\n" + \
" (Protect datafiles only)\n\n" \
" [--logsonly]\n" + \
" (Protect redo/arch/ctrl only)\n\n" \
" [--snapshot||prefix]\n" + \
" (Name or prefix for snapshot)\n\n" + \
" [--label|]\n" + \
" (Snapmirror label for the snapshot)\n\n" + \
" [--maxcount]\n" + \
" (Optional. Maximum number of snapshots to retain)\n\n" + \
" [--maxage]\n" + \
" (Optional. Maximum age of snapshots to retain.\n" + \
" [--debug]\n" + \
" (show debug output)\n\n" + \
" [--restdebug]\n" + \
" (show REST API debug output)\n\n" + \
"start [--sid]\n" + \
" (name(s) of database SIDs\n\n" + \
" [--mount]\n" + \
" (startup in mount mode)\n\n" \
" [--nomount]\n" + \
" (startup in nomount mode)\n\n" \
" [--debug]\n" + \
" (show debug output)\n\n" + \
"stop [--sid]\n" + \
" (name(s) of database SIDs\n\n" + \
" [--abort]\n" + \
" (perform shutdown abort. Default is shutdown immediate)\n\n" \
" [--debug]\n" + \
" (show debug output)\n\n" + \
"mount [--sid]\n" + \
" (name(s) of database SIDs\n\n" + \
" [--debug]\n" + \
" (show debug output)\n\n" + \
"open [--sid]\n" + \
" (name(s) of database SIDs\n\n" + \
" [--debug]\n" + \
" (show debug output)\n\n" + \
"discover [--sid]\n" + \
" (name(s) of database SID\n\n" + \
" [--debug]\n" + \
" (show debug output)\n"
myopts=userio.validateoptions(sys.argv,validoptions,mutex=mutex,usage=usage,required=requiredoptions)
sidlist=myopts.sid
if myopts.debug:
debug=25
else:
debug=0
if myopts.mode == 'backup':
if myopts.force:
force=True
else:
force=False
if myopts.start:
command=True
elif myopts.stop:
command=False
else:
userio.fail("Missing a --start or --stop")
for sid in sidlist:
change=setOracleBackup.setOracleBackup(sid,debug=debug,force=force)
if change.go(command):
userio.message("Success: " + sid + ":backup mode " + str(command))
else:
userio.warn(change.reason)
if myopts.mode == 'start':
if myopts.mount:
start='mount'
elif myopts.nomount:
start='nomount'
else:
start=None
for sid in sidlist:
change=startOracleInstance.startOracleInstance(sid,start=start,debug=debug)
if change.go():
userio.message("Success: " + sid + " started")
else:
userio.warn(change.reason)
if myopts.mode == 'stop':
abort=myopts.abort
for sid in sidlist:
change=stopOracleInstance.stopOracleInstance(sid,debug=debug,abort=abort)
if change.go():
userio.message("Success: " + sid + " stopped")
else:
userio.warn(change.reason)
if myopts.mode == 'mount':
for sid in sidlist:
change=mountOracleInstance.mountOracleInstance(sid,debug=debug)
if change.go():
userio.message("Success: " + sid + " mounted")
else:
userio.warn(change.reason)
if myopts.mode == 'open':
for sid in sidlist:
change=openOracleInstance.openOracleInstance(sid,debug=debug)
if change.go():
userio.message("Success: " + sid + " opened")
else:
userio.warn(change.reason)
if myopts.mode == 'discover':
sid=sidlist
info=discoverOracle.discoverOracle(sid,debug=debug)
if info.go():
grid=[['Datafile','File#','Size','Backup']]
itemlist=list(info.datafiles.keys())
itemlist.sort()
for item in itemlist:
grid.append([item,info.datafiles[item]['fileno'],info.datafiles[item]['size'],str(info.datafiles[item]['backup'])])
userio.grid(grid)
userio.linefeed()
grid=[['Archive log destination']]
itemlist=list(info.arch.keys())
itemlist.sort()
for item in itemlist:
grid.append([item])
userio.grid(grid)
userio.linefeed()
grid=[['Redo log','Group#','Thread#','Size']]
itemlist=list(info.redo.keys())
itemlist.sort()
for item in itemlist:
grid.append([item,info.redo[item]['group'],info.redo[item]['thread'],info.redo[item]['size']])
userio.grid(grid)
userio.linefeed()
grid=[['Control file']]
itemlist=list(info.ctrl.keys())
itemlist.sort()
for item in itemlist:
grid.append([item])
userio.grid(grid)
userio.linefeed()
grid=[['Parameter','Value']]
itemlist=list(info.pfile.keys())
itemlist.sort()
for item in itemlist:
grid.append([item,info.pfile[item]])
userio.grid(grid)
userio.linefeed()
else:
userio.warn(info.reason)
if myopts.mode == 'protect':
sid=sidlist
discoveredSID={}
undiscoveredSID=[]
for sid in sidlist:
info=discoverOracle.discoverOracle(sid,debug=debug)
if info.go():
if debug & 1:
grid=[['Datafile','File#','Size','Backup']]
itemlist=list(info.datafiles.keys())
itemlist.sort()
for item in itemlist:
grid.append([item,info.datafiles[item]['fileno'],info.datafiles[item]['size'],str(info.datafiles[item]['backup'])])
userio.grid(grid)
userio.linefeed()
grid=[['Archive log destination']]
itemlist=list(info.arch.keys())
itemlist.sort()
for item in itemlist:
grid.append([item])
userio.grid(grid)
userio.linefeed()
grid=[['Redo log','Group#','Thread#','Size']]
itemlist=list(info.redo.keys())
itemlist.sort()
for item in itemlist:
grid.append([item,info.redo[item]['group'],info.redo[item]['thread'],info.redo[item]['size']])
userio.grid(grid)
userio.linefeed()
grid=[['Control file']]
itemlist=list(info.ctrl.keys())
itemlist.sort()
for item in itemlist:
grid.append([item])
userio.grid(grid)
userio.linefeed()
grid=[['Parameter','Value']]
itemlist=list(info.pfile.keys())
itemlist.sort()
for item in itemlist:
grid.append([item,info.pfile[item]])
userio.grid(grid)
userio.linefeed()
discoveredSID[sid]=info
else:
userio.warn(info.reason)
undiscoveredSID.append(sid)
datafilevol4snapshot={}
for sid in discoveredSID.keys():
newdatafilefs=list(discoveredSID[sid].datafiles.keys())
mypaths=discoverPaths.discoverPaths(newdatafilefs,cache=mycache,debug=debug)
mypaths.go()
if len(mypaths.unknown):
userio.warn("Unable to resolve paths for " + sid + ":" + ','.join(mypaths.unknown))
undiscoveredSID.append(sid)
else:
for device in mypaths.allvolumes.keys():
datafilevol4snapshot[device]=mypaths.allvolumes[device]
for sid in undiscoveredSID:
del discoveredSID[sid]
logvol4snapshot={}
for sid in discoveredSID.keys():
newlogfs=list(discoveredSID[sid].arch.keys()) + list(discoveredSID[sid].redo.keys()) + list(discoveredSID[sid].ctrl.keys())
mypaths=discoverPaths.discoverPaths(newlogfs,cache=mycache,debug=debug)
mypaths.go()
if len(mypaths.unknown):
userio.warn("Unable to resolve paths for " + sid + ":".join(mypaths.unknown))
del discoveredSID[sid]
undiscoveredSID.append[sid]
else:
for device in mypaths.allvolumes.keys():
logvol4snapshot[device]=mypaths.allvolumes[device]
undiscoveredSID=set(undiscoveredSID)
commonsvms=set(datafilevol4snapshot.keys()).intersection(set(logvol4snapshot.keys()))
for svm in commonsvms:
commonvolumes=set(datafilevol4snapshot[svm]).intersection(set(logvol4snapshot[svm]))
if len(commonvolumes) > 0:
userio.fail("Datafiles/log file volume collision detected, exiting...")
backupmode=[]
if myopts.nobackupmode:
for sid in discoveredSID.keys():
userio.message("Bypassing backup mode for " + sid)
else:
for sid in discoveredSID.keys():
change=setOracleBackup.setOracleBackup(sid,debug=debug)
if change.go(True):
userio.message(sid + " is now in backup mode ")
backupmode.append(sid)
else:
userio.warn(change.reason)
if len(discoveredSID) < 1:
userio.fail("No requested databases exist")
cgrequired=False
if len(datafilevol4snapshot.keys()) > 1:
cgrequired=True
else:
for svm in datafilevol4snapshot.keys():
if len(datafilevol4snapshot[svm]) > 1:
cgrequired=True
break
if cgrequired:
userio.message("Multiple datafile volumes detected, CG required")
else:
userio.message("Single volume for datafiles detected, CG not required")
cgrequired=False
if len(logvol4snapshot.keys()) > 1:
cgrequired=True
else:
for svm in logvol4snapshot.keys():
if len(logvol4snapshot[svm]) > 1:
cgrequired=True
break
if cgrequired:
userio.message("Multiple log volumes detected, CG required")
else:
userio.message("Single volume for log detected, CG not required")
print(datafilevol4snapshot)
if not myopts.nobackupmode:
for sid in discoveredSID.keys():
change=setOracleBackup.setOracleBackup(sid,debug=debug)
if change.go(False):
userio.message(sid + " removed from backup mode ")
else:
userio.warn(change.reason)
print(logvol4snapshot)