-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathasmfiles2
executable file
·619 lines (572 loc) · 28.2 KB
/
asmfiles2
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
#!/bin/env python
##################################################################################################
# Name: asmfiles #
# Author: Randy Johnson #
# Description: ASM Storage by Diskgroup, by Database, by Type, by File #
# #
# usage: asmfiles [options] #
# #
# options: #
# -h, --help show this help message and exit #
# -a All files report #
# -c csv report format #
# -d Database report #
# -f DBFILTER Database filter (case sensitive) #
# -g Diskgroup report #
# -r Replay using picked results #
# -s print SQL query #
# -t File type report #
# -v print version info #
# #
# Todo's #
# - Automatically set Oracle Home, Oracle Sid to local ASM instance. #
# #
# History: #
# #
# Date Ver. Who Change Description #
# ---------- ---- ---------------- ------------------------------------------------------------- #
# 06/25/2014 1.00 Randy Johnson Initial write. #
# 10/05/2014 2.00 Randy Johnson Several changes to reports. #
# 10/05/2014 2.10 Randy Johnson Report enhancements. #
# 01/31/2015 2.20 Randy Johnson Added as second part to the File Type report that breaks down #
# by disk group. #
# 03/15/2015 2.30 Randy Johnson Increased the field length for Diskgroup. #
# 07/21/2015 3.00 Randy Johnson Updated for Python 2.4-3.4 compatibility. Changed order of #
# precedence between -r and -s options. #
# 08/01/2015 3.10 Randy Johnson Added prompts for username, password, tnsname. #
# 08/18/2015 3.20 Randy Johnson If not connecting remotely via ConnStr, now determines the #
# ORACLE_SID for local +ASM instance and sets ORACLE_SID and #
# ORACLE_HOME based on local +ASM instance. #
# 01/12/2016 3.30 Randy Johnson Added username to the pickle file to avoid permissions issues #
# 04/13/2016 3.40 Randy Johnson Added CSV Report format. #
##################################################################################################
# --------------------------------------
# ---- Import Python Modules -----------
# --------------------------------------
from datetime import datetime
from getpass import getuser
from locale import LC_ALL
from locale import format
from locale import setlocale
from math import floor
from math import log
from math import pow
from optparse import OptionParser
from os import environ
from os import path
from os.path import basename
from os.path import isfile
from signal import SIG_DFL
from signal import SIGPIPE
from signal import signal
from signal import SIGPIPE
from signal import SIG_DFL
from subprocess import Popen
from subprocess import PIPE
from subprocess import STDOUT
from sys import argv
from sys import exit
from sys import version_info
from Oracle import FormatNumber
from Oracle import ParseConnectString
from Oracle import PrintError
from Oracle import RunSqlplus
from Oracle import SetOracleEnv
if (version_info[0] >= 3):
import pickle
else:
import cPickle as pickle
# --------------------------------------
# ---- Function Definitions ------------
# --------------------------------------
# Def : ConvertSize()
# Desc: Reduces the size of a number from Bytes .. Yeta Bytes
# Args: s = numeric_string
# tSep = thousands_separation_character (default is ',')
# dSep = decimal_separation_character (default is '.')
# Retn: formatted string
#---------------------------------------------------------------------------
def ConvertSize(bytes):
size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
s = 0
if (bytes > 0):
i = int(floor(log(bytes,1024)))
p = pow(1024,i)
s = round(bytes/p,2)
if (s > 0):
return '%s %s' % (s,size_name[i])
else:
return '0B'
# End ConvertSize
# --------------------------------------
# ---- End Function Definitions --------
# --------------------------------------
# --------------------------------------
# ---- Main Program --------------------
# --------------------------------------
if (__name__ == '__main__'):
Cmd = basename(argv[0]).split('.')[0]
CmdDesc = 'ASM Space Usage'
Version = '3.40'
VersionDate = 'Tue Apr 18 11:17:49 CDT 2017'
DevState = 'Production'
Banner = CmdDesc + ': Release ' + Version + ' ' + DevState + '. Last updated: ' + VersionDate
Sql = ''
SqlHeader = '/***** ' + CmdDesc.upper() + ' *****/'
Filter = ''
Colsep = '!~!'
ErrChk = False
ArgParser = OptionParser()
InStr = ''
TnsName = ''
Username = ''
Password = ''
ConnStr = ''
Colsep = '!~!'
Now = datetime.now()
FileList = []
DgDict = {}
DbDict = {}
TypeDict = {}
TypeDict = {}
FileDict = {}
Username = getuser()
PickleFile = '/tmp/' + Cmd + '.' + Username + '.pkl'
Ps = '/bin/ps'
setlocale(LC_ALL, 'en_US')
# For handling termination in stdout pipe; ex: when you run: oerrdump | head
signal(SIGPIPE, SIG_DFL)
ArgParser.add_option("-a", dest="AllFiles", default=False, action="store_true", help="All files report")
ArgParser.add_option("-c", dest="Csv", default=False, action="store_true", help="csv report format")
ArgParser.add_option("-d", dest="DbRpt", default=False, action="store_true", help="Database report")
ArgParser.add_option("-f", dest="DbFilter", default='', type=str, help="Database filter (case sensitive)")
ArgParser.add_option("-g", dest="DgRpt", default=False, action="store_true", help="Diskgroup report")
ArgParser.add_option("-r", dest="Replay", default=False, action="store_true", help="Replay using picked results")
ArgParser.add_option("-t", dest="TypeRpt", default=False, action="store_true", help="File type report")
ArgParser.add_option("--s", dest="Show", default=False, action="store_true", help="print SQL query")
ArgParser.add_option("--v", dest="ShowVer", default=False, action="store_true", help="print version info")
Options, args = ArgParser.parse_args()
argc = len(args)
if (argc > 0):
Filter = args[argc-1].lower()
AllFiles = Options.AllFiles
Csv = Options.Csv
DbFilter = Options.DbFilter
DbRpt = Options.DbRpt
DgRpt = Options.DgRpt
TypeRpt = Options.TypeRpt
Replay = Options.Replay
ShowVer = Options.ShowVer
Show = Options.Show
if (ShowVer == True):
print('\n%s' % Banner)
exit()
Sql += "set feedback off\n"
Sql += "set echo off\n"
Sql += "set timing off\n"
Sql += "set heading off\n"
Sql += "set pagesize 0\n"
Sql += "set linesize 2000\n"
Sql += "\n"
Sql += "SELECT " + SqlHeader + "\n"
Sql += " CONCAT('+' || disk_group_name, SYS_CONNECT_BY_PATH(alias_name, '/')) ||'" + Colsep + "'||\n"
Sql += " bytes ||'" + Colsep + "'||\n"
Sql += " space ||'" + Colsep + "'||\n"
Sql += " NVL(type, '<DIRECTORY>') ||'" + Colsep + "'||\n"
Sql += " creation_date ||'" + Colsep + "'||\n"
Sql += " creation_time ||'" + Colsep + "'||\n"
Sql += " modification_date ||'" + Colsep + "'||\n"
Sql += " modification_time ||'" + Colsep + "'||\n"
Sql += " disk_group_name ||'" + Colsep + "'||\n"
Sql += " system_created\n"
Sql += " FROM (SELECT g.name disk_group_name,\n"
Sql += " a.parent_index pindex,\n"
Sql += " a.name alias_name,\n"
Sql += " a.reference_index rindex,\n"
Sql += " a.system_created system_created,\n"
Sql += " f.bytes bytes,\n"
Sql += " f.space space,\n"
Sql += " f.type type,\n"
Sql += " TO_CHAR(f.creation_date, 'YYYY-MM-DD') creation_date,\n"
Sql += " TO_CHAR(f.creation_date, 'HH24:MI:SS') creation_time,\n"
Sql += " TO_CHAR(f.modification_date, 'YYYY-MM-DD') modification_date,\n"
Sql += " TO_CHAR(f.modification_date, 'HH24:MI:SS') modification_time\n"
Sql += " FROM v$asm_file f,\n"
Sql += " v$asm_alias a,\n"
Sql += " v$asm_diskgroup g\n"
Sql += " WHERE (f.group_number(+) = a.group_number and f.file_number(+) = a.file_number)\n"
Sql += " AND g.group_number(+) = f.group_number\n"
Sql += " )\n"
Sql += " WHERE type IS NOT NULL\n"
Sql += " START WITH (MOD(pindex, POWER(2, 24))) = 0 CONNECT BY PRIOR rindex = pindex;"
### # If performance becomes an issue then use this query to filter by database.
### # ---------------------------------------------------------------------------
### Sql += "set feedback off\n"
### Sql += "set echo off\n"
### Sql += "set timing off\n"
### Sql += "set heading off\n"
### Sql += "set pagesize 0\n"
### Sql += "set linesize 2000\n"
### Sql += "\n"
### Sql += "SELECT CONCAT('+' || rpt.diskgroup_name, rpt.filename) ||'!~!'||\n"
### Sql += " rpt.bytes ||'!~!'||\n"
### Sql += " rpt.space ||'!~!'||\n"
### Sql += " NVL(rpt.type, '<DIRECTORY>') ||'!~!'||\n"
### Sql += " rpt.creation_date ||'!~!'||\n"
### Sql += " rpt.creation_time ||'!~!'||\n"
### Sql += " rpt.modification_date ||'!~!'||\n"
### Sql += " rpt.modification_time ||'!~!'||\n"
### Sql += " rpt.diskgroup_name ||'!~!'||\n"
### Sql += " rpt.system_created\n"
### Sql += " FROM (SELECT dtl.diskgroup_name,\n"
### Sql += " SYS_CONNECT_BY_PATH(dtl.alias_name, '/') filename,\n"
### Sql += " dtl.bytes,\n"
### Sql += " dtl.space,\n"
### Sql += " NVL(dtl.type, '<DIRECTORY>') type,\n"
### Sql += " dtl.creation_date,\n"
### Sql += " dtl.creation_time,\n"
### Sql += " dtl.modification_date,\n"
### Sql += " dtl.modification_time,\n"
### Sql += " -- dtl.diskgroup_name,\n"
### Sql += " dtl.system_created\n"
### Sql += " FROM (SELECT g.name diskgroup_name,\n"
### Sql += " a.parent_index pindex,\n"
### Sql += " a.name alias_name,\n"
### Sql += " a.reference_index rindex,\n"
### Sql += " a.system_created system_created,\n"
### Sql += " f.bytes bytes,\n"
### Sql += " f.space space,\n"
### Sql += " f.type type,\n"
### Sql += " TO_CHAR(f.creation_date, 'YYYY-MM-DD') creation_date,\n"
### Sql += " TO_CHAR(f.creation_date, 'HH24:MI:SS') creation_time,\n"
### Sql += " TO_CHAR(f.modification_date, 'YYYY-MM-DD') modification_date,\n"
### Sql += " TO_CHAR(f.modification_date, 'HH24:MI:SS') modification_time\n"
### Sql += " FROM v$asm_file f,\n"
### Sql += " v$asm_alias a,\n"
### Sql += " v$asm_diskgroup g\n"
### Sql += " WHERE (f.group_number(+) = a.group_number and f.file_number(+) = a.file_number)\n"
### Sql += " AND g.group_number(+) = f.group_number\n"
### Sql += " ) dtl\n"
### Sql += " WHERE type IS NOT NULL\n"
### Sql += " START WITH (MOD(pindex, POWER(2, 24))) = 0 CONNECT BY PRIOR rindex = pindex\n"
### Sql += " ) rpt\n"
###
### if (DbFilter != ''):
### Sql += " WHERE rpt.filename like '" + '/' + DbFilter + "/%';"
### else:
### Sql += ';'
Sql = Sql.strip()
if(Show == True):
print('-----------cut-----------cut-----------cut-----------cut-----------cut-----------')
print(Sql)
print('-----------cut-----------cut-----------cut-----------cut-----------cut-----------')
exit()
# Set the default report to Disk Group Report
if (DbRpt == False and DgRpt == False and TypeRpt == False and AllFiles == False):
DgRpt = True
if (Replay == True):
if (isfile(PickleFile) == True):
try:
hPickleFile = open(PickleFile,'rb')
except:
print('Cannot open the replay file for read:', PickleFile)
exit(1)
try:
FileList = pickle.load(hPickleFile)
except:
print('Cannot parse the replay file:', PickleFile)
exit(1)
else:
print('No replay file found:', PickleFile)
exit(1)
else:
# Parse the connect string if any, prompt for username, password if needed.
if (len(args) > 0 and Show == False):
InStr = args[0]
ConnStr = ParseConnectString(InStr)
else:
# Discover all running database instances and add them to the list.
Proc = Popen([Ps, '-ef'], bufsize=1, stdin=PIPE, stdout=PIPE, stderr=STDOUT, shell=False, universal_newlines=True, close_fds=True)
# Stderr is just a placeholder. We redirected stderr to stdout as follows 'stderr=STDOUT'.
(Stdout,Stderr) = Proc.communicate()
Stdout = Stdout.strip()
AsmSid = ''
for Line in Stdout.split('\n'):
(Splt) = Line.split()
Uid, Pid, Ppid, C, Stime, Tty, Time, Cmd = Splt[0], Splt[1], Splt[2], Splt[3], Splt[4], Splt[5], Splt[6] , Splt[7]
if ((Cmd.find('asm_pmon_+ASM', 0, 13)) >= 0):
AsmSid = Cmd[9:]
else:
if ((Cmd.find('ora_pmon_+ASM', 0, 13)) >= 0):
AsmSid = Cmd[9:]
else:
continue
# Set the ORACLE_HOME just in case it isn't set already.
if (AsmSid != ''):
(OracleSid, OracleHome) = SetOracleEnv(AsmSid)
# Execute the query
if (ConnStr != ''):
(Stdout) = RunSqlplus(Sql, ErrChk, ConnStr)
else:
(Stdout) = RunSqlplus(Sql, ErrChk)
Stdout = Stdout.strip()
if (Stdout == ''):
print('\nNo ASM files found.')
exit()
for fileinfo in Stdout.split('\n'):
try:
#+DATA/DBM/DATAFILE/RMAN_CATALOG.1308.817853599!~!15736832!~!33554432!~!DATAFILE!~!2013-06-11!~!21:33:18!~!2013-06-11!~!21:33:18!~!DATA!~!Y
Filepath = fileinfo.split(Colsep)[0]
Database = Filepath.split('/')[1]
SizBytes = int(fileinfo.split(Colsep)[1])
StoBytes = int(fileinfo.split(Colsep)[2])
FileType = fileinfo.split(Colsep)[3]
CrtDate = fileinfo.split(Colsep)[4]
CrtTime = fileinfo.split(Colsep)[5]
ModDate = fileinfo.split(Colsep)[6]
ModTime = fileinfo.split(Colsep)[7]
Diskgroup = fileinfo.split(Colsep)[8]
CrtSys = fileinfo.split(Colsep)[9]
except:
print(Stdout)
print('')
print('Invalid record format.')
exit(1)
# File List
# ----------------------
FileList.append([Diskgroup, Database, Filepath, SizBytes, StoBytes, FileType, CrtDate, CrtTime, ModDate, ModTime, CrtSys])
# Save Replay Information
# --------------------------
try:
hPickleFile = open(PickleFile,'wb')
except:
print('Cannot open the replay file for write:', PickleFile)
pickle.dump(FileList, hPickleFile)
hPickleFile.close()
for Filespec in FileList:
Diskgroup = Filespec[0]
Database = Filespec[1]
Filepath = Filespec[2]
SizBytes = Filespec[3]
StoBytes = Filespec[4]
FileType = Filespec[5]
CrtDate = Filespec[6]
CrtTime = Filespec[7]
ModDate = Filespec[8]
ModTime = Filespec[9]
CrtSys = Filespec[10]
# File dictionary
# ----------------------
FileDict[Filepath] = {
'Diskgroup' : Diskgroup,
'Database' : Database,
'SizBytes' : SizBytes,
'StoBytes' : StoBytes,
'FileType' : FileType,
'CrtDate' : CrtDate,
'CrtTime' : CrtTime,
'ModDate' : ModDate,
'ModTime' : ModTime,
'CrtSys' : CrtSys
}
# Database dictionary
# ----------------------
if Database in DbDict:
if Diskgroup in DbDict[Database]:
DbDict[Database][Diskgroup]['TotSizBytes'] = DbDict[Database][Diskgroup]['TotSizBytes'] + SizBytes
DbDict[Database][Diskgroup]['TotStoBytes'] = DbDict[Database][Diskgroup]['TotStoBytes'] + StoBytes
else:
DbDict[Database][Diskgroup] = {}
DbDict[Database][Diskgroup]['TotSizBytes'] = SizBytes
DbDict[Database][Diskgroup]['TotStoBytes'] = StoBytes
else:
DbDict[Database] = {}
DbDict[Database][Diskgroup] = {'TotSizBytes':SizBytes, 'TotStoBytes':StoBytes}
# Diskgroup dictionary
# ----------------------
if Diskgroup in DgDict:
if Database in DgDict[Diskgroup]:
DgDict[Diskgroup][Database]['TotSizBytes'] = DgDict[Diskgroup][Database]['TotSizBytes'] + SizBytes
DgDict[Diskgroup][Database]['TotStoBytes'] = DgDict[Diskgroup][Database]['TotStoBytes'] + StoBytes
else:
DgDict[Diskgroup][Database] = {}
DgDict[Diskgroup][Database]['TotSizBytes'] = SizBytes
DgDict[Diskgroup][Database]['TotStoBytes'] = StoBytes
else:
DgDict[Diskgroup] = {}
DgDict[Diskgroup][Database] = {'TotSizBytes':SizBytes, 'TotStoBytes':StoBytes}
# TypeDict dictionary
# ----------------------
if FileType in TypeDict:
if Diskgroup in TypeDict[FileType]:
if Database in TypeDict[FileType][Diskgroup]:
TypeDict[FileType][Diskgroup][Database]['TotSizBytes'] += SizBytes
TypeDict[FileType][Diskgroup][Database]['TotStoBytes'] += StoBytes
else:
TypeDict[FileType][Diskgroup][Database] = {}
TypeDict[FileType][Diskgroup][Database]['TotSizBytes'] = SizBytes
TypeDict[FileType][Diskgroup][Database]['TotStoBytes'] = StoBytes
else:
TypeDict[FileType][Diskgroup] = {}
TypeDict[FileType][Diskgroup][Database] = {}
TypeDict[FileType][Diskgroup][Database]['TotSizBytes'] = SizBytes
TypeDict[FileType][Diskgroup][Database]['TotStoBytes'] = StoBytes
else:
TypeDict[FileType] = {}
TypeDict[FileType][Diskgroup] = {}
TypeDict[FileType][Diskgroup][Database] = {}
TypeDict[FileType][Diskgroup][Database]['TotSizBytes'] = SizBytes
TypeDict[FileType][Diskgroup][Database]['TotStoBytes'] = StoBytes
# ----------------------
# Print Reports
# ----------------------
# Print File Report
# ----------------------
if (AllFiles == True):
print('')
print("File Name Report")
print("==================")
print('')
if (Csv):
print('"FILENAME","MODIFICATION TIME","SIZE (BYTES)","STORAGE (BYTES)"')
else:
print("Filename Modification Time Size (bytes) Storage (bytes)")
print("---------------------------------------------------------------------------------------------------------- ------------------- -------------------- --------------------")
for FileKey in sorted(FileDict.keys()):
Diskgroup = FileDict[FileKey]['Diskgroup']
Database = FileDict[FileKey]['Database' ]
SizBytes = FileDict[FileKey]['SizBytes' ]
StoBytes = FileDict[FileKey]['StoBytes' ]
FileType = FileDict[FileKey]['FileType' ]
CrtDate = FileDict[FileKey]['CrtDate' ]
CrtTime = FileDict[FileKey]['CrtTime' ]
ModDate = FileDict[FileKey]['ModDate' ]
ModTime = FileDict[FileKey]['ModTime' ]
CrtSys = FileDict[FileKey]['CrtSys' ]
SizBytes = FormatNumber(SizBytes)
StoBytes = FormatNumber(StoBytes)
if (DbFilter == ''):
if (Csv):
print('"%s","%s","%s","%s","%s"' % (FileKey, ModDate, ModTime, SizBytes, StoBytes))
else:
print('%-106s %-10s %-8s %20s %20s' % (FileKey, ModDate, ModTime, SizBytes, StoBytes))
else:
if (DbFilter == Database):
if (Csv):
print('"%s","%s","%s","%s","%s"' % (FileKey, ModDate, ModTime, SizBytes, StoBytes))
else:
print('%-106s %-10s %-8s %20s %20s' % (FileKey, ModDate, ModTime, SizBytes, StoBytes))
# Print Database Report
# -----------------------
if (DbRpt == True):
print('')
print('Database Report')
print('==================')
print('')
if (Csv):
print('"Database","Total Size","Total Storage"')
else:
print("Database Total Size Total Storage")
print("-------------------- --------------- ---------------")
for DbKey in sorted(DbDict.keys()):
TotalSizeBytes = 0
TotalStorageBytes = 0
for DgKey in sorted(DbDict[DbKey].keys()):
TotalSizeBytes += DbDict[DbKey][DgKey]['TotSizBytes']
TotalStorageBytes += DbDict[DbKey][DgKey]['TotStoBytes']
if (DbFilter != ''):
if (DbKey == DbFilter):
if (Csv):
print('"%s","%15s","%15s"' % (DbKey, TotalSizeBytes, TotalStorageBytes))
else:
print('%-20s %15s %15s' % (DbKey, ConvertSize(TotalSizeBytes), ConvertSize(TotalStorageBytes)))
else:
if (Csv):
print('"%s","%s","%s"' % (DbKey, TotalSizeBytes, TotalStorageBytes))
else:
print('%-20s %15s %15s' % (DbKey, ConvertSize(TotalSizeBytes), ConvertSize(TotalStorageBytes)))
# Print Diskgroup Report
# -----------------------
if (DgRpt == True):
print('')
print('Diskgroup Report')
print('==================')
print('')
if (Csv):
print('"Diskgroup","Database","Total Size","Total Storage"')
else:
print('Diskgroup Database Total Size Total Storage')
print('-------------------- -------------------- --------------- ---------------')
for DgKey in sorted(DgDict.keys()):
for DbKey in sorted(DgDict[DgKey].keys()):
if (DbFilter != ''):
if (DbKey == DbFilter):
TotalSizeBytes = DgDict[DgKey][DbKey]['TotSizBytes']
TotalStorageBytes = DgDict[DgKey][DbKey]['TotStoBytes']
if (Csv):
print('"%s","%s","%s","%s"' % (DgKey, DbKey, TotalSizeBytes, TotalStorageBytes))
else:
print('%-20s %-20s %15s %15s' % (DgKey, DbKey, ConvertSize(TotalSizeBytes), ConvertSize(TotalStorageBytes)))
else:
TotalSizeBytes = DgDict[DgKey][DbKey]['TotSizBytes']
TotalStorageBytes = DgDict[DgKey][DbKey]['TotStoBytes']
if (Csv):
print('"%s","%s","%s","%s"' % (DgKey, DbKey, TotalSizeBytes, TotalStorageBytes))
else:
print('%-20s %-20s %15s %15s' % (DgKey, DbKey, ConvertSize(TotalSizeBytes), ConvertSize(TotalStorageBytes)))
# Print File Type Report
# -----------------------
if (TypeRpt == True):
print('')
print("File Type Report")
print("==================")
print('')
if (Csv):
print('"File Type","Total Size","Total Storage"')
else:
print("File Type Total Size Total Storage")
print("------------------------- --------------- ---------------")
for TypeKey in sorted(TypeDict.keys()):
TotalSizeBytes = 0
TotalStorageBytes = 0
for DgKey in sorted(TypeDict[TypeKey].keys()):
for DbKey in sorted(TypeDict[TypeKey][DgKey].keys()):
if (DbFilter != ''):
if (DbKey == DbFilter):
TotalSizeBytes += TypeDict[TypeKey][DgKey][DbKey]['TotSizBytes']
TotalStorageBytes += TypeDict[TypeKey][DgKey][DbKey]['TotStoBytes']
else:
TotalSizeBytes += TypeDict[TypeKey][DgKey][DbKey]['TotSizBytes']
TotalStorageBytes += TypeDict[TypeKey][DgKey][DbKey]['TotStoBytes']
if (TotalSizeBytes > 0 or TotalStorageBytes > 0):
if (Csv):
print('"%s","%s","%s"' % (TypeKey, TotalSizeBytes, TotalStorageBytes))
else:
print('%-25s %15s %15s' % (TypeKey, ConvertSize(TotalSizeBytes), ConvertSize(TotalStorageBytes)))
print('')
if (Csv):
print('"File Type","Diskgroup","Total Size","Total Storage"')
else:
print("File Type Diskgroup Total Size Total Storage")
print("------------------------- -------------------- --------------- ---------------")
for TypeKey in sorted(TypeDict.keys()):
for DgKey in sorted(TypeDict[TypeKey].keys()):
TotalSizeBytes = 0
TotalStorageBytes = 0
for DbKey in sorted(TypeDict[TypeKey][DgKey].keys()):
if (DbFilter != ''):
if (DbKey == DbFilter):
TotalSizeBytes += TypeDict[TypeKey][DgKey][DbKey]['TotSizBytes']
TotalStorageBytes += TypeDict[TypeKey][DgKey][DbKey]['TotStoBytes']
else:
TotalSizeBytes += TypeDict[TypeKey][DgKey][DbKey]['TotSizBytes']
TotalStorageBytes += TypeDict[TypeKey][DgKey][DbKey]['TotStoBytes']
if (TotalSizeBytes > 0 or TotalStorageBytes > 0):
if (Csv):
print('"%s","%s","%s","%s"' % (TypeKey, DgKey, TotalSizeBytes, TotalStorageBytes))
else:
print('%-25s %-20s %15s %15s' % (TypeKey, DgKey, ConvertSize(TotalSizeBytes), ConvertSize(TotalStorageBytes)))
exit(0)
# --------------------------------------
# ---- End Main Program ----------------
# --------------------------------------