-
Notifications
You must be signed in to change notification settings - Fork 16
/
arclogstat
executable file
·271 lines (240 loc) · 11.6 KB
/
arclogstat
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
#!/bin/env python
##################################################################################################
# Name: archlogstat #
# Author: Randy Johnson #
# Description: Report information on archived redo logs. #
# #
# Usage: archlogstat [options] #
# #
# Options: #
# -h, --help show this help message and exit #
# -c RMAN> list copy of archivelog ... #
# -b RMAN> list backup of archivelog ... #
# -d include deleted archivelogs in the report. #
# -n NAME where upper(name) like '%sssss%' #
# -m MEDIA RMAN> list backup ... device type disk/sbt (default=ALL #
# -f FIRSTSCN where first_change# >= nnnnn #
# -l LASTSCN where next_change# <= nnnnn #
# -r RMAN> list copy/backup of archivelog ... #
# --s print SQL query. #
# --v print version info. #
# #
# History: #
# #
# Date Ver. Who Change Description #
# ---------- ---- ---------------- ------------------------------------------------------------- #
# 09/25/2016 1.00 Randy Johnson Initial write. #
##################################################################################################
# --------------------------------------
# ---- Import Python Modules -----------
# --------------------------------------
from optparse import OptionParser
from os import environ
from os.path import basename
from sys import argv
from sys import exit
from sys import version_info
from signal import SIGPIPE
from signal import SIG_DFL
from signal import signal
from Oracle import RunSqlplus
from Oracle import RunRman
from Oracle import SetOracleEnv
from Oracle import ParseConnectString
from Oracle import PrintError
# --------------------------------------
# ---- Main Program --------------------
# --------------------------------------
if (__name__ == '__main__'):
Cmd = basename(argv[0]).split('.')[0]
CmdDesc = 'Archivelog Status'
Version = '1.00'
VersionDate = 'Sun Sep 25 14:04:25 CDT 2016'
DevState = 'Production'
Banner = CmdDesc + ': Release ' + Version + ' ' + DevState + '. Last updated: ' + VersionDate
Rcv = ''
Sql = ''
SqlHeader = '/***** ' + CmdDesc.upper() + ' *****/'
ErrChk = False
ArgParser = OptionParser()
ConnStr = ''
# For handling termination in stdout pipe; ex: when you run: oerrdump | head
signal(SIGPIPE, SIG_DFL)
ArgParser.add_option('-c', dest='ListCopy', action='store_true', default=False, help="RMAN> list copy of archivelog ...")
ArgParser.add_option('-b', dest='ListBackup', action='store_true', default=False, help="RMAN> list backup of archivelog ...")
ArgParser.add_option('-d', dest='Deleted', action='store_true', default=False, help="include deleted archivelogs in the report.")
ArgParser.add_option('-n', dest='Name', default='', type=str, help="where upper(name) like '%sssss%'")
ArgParser.add_option('-m', dest='Media', default='', type=str, help="RMAN> list backup ... device type disk/sbt (default=ALL")
ArgParser.add_option('-f', dest='FirstScn', default='', type=str, help="where first_change# >= nnnnn")
ArgParser.add_option('-l', dest='LastScn', default='', type=str, help="where next_change# <= nnnnn")
ArgParser.add_option('--s', dest='Show', action='store_true', default=False, help="print SQL query.")
ArgParser.add_option('--v', dest='ShowVer', action='store_true', default=False, help="print version info.")
# Parse command line arguments
Options, args = ArgParser.parse_args()
ListCopy = Options.ListCopy
ListBackup = Options.ListBackup
Media = Options.Media
Deleted = Options.Deleted
Name = Options.Name
FirstScn = Options.FirstScn
LastScn = Options.LastScn
Show = Options.Show
ShowVer = Options.ShowVer
if (ListCopy == True or ListBackup == True):
Rman = True
else:
Rman = False
#if (ListBackup == False and ListCopy == False):
# ListBackup = True
# ListCopy = True
if (Media == ''):
Media = 'ALL'
else:
Media = Media.upper()
if (Media == 'TAPE'):
Media = 'SBT'
if (LastScn != ''):
LastScn = str(int(LastScn) + 1)
if (ShowVer == True):
print('\n%s' % Banner)
exit()
if (Name != '' and Rman == True):
if (FirstScn != '' or LastScn != ''):
print('Name option (-n) cannot be used with FirstScn (-f) or LastScn (-l) option when searching the backups.')
exit(1)
if (Rman == True):
if ((FirstScn == '' and LastScn != '') or (LastScn == '' and FirstScn != '')):
print('FirstScn (-f) and LastScn (-l) options must be used together when searching the backups.')
exit(1)
if (Rman == True):
if (ListCopy == True):
Rcv += "LIST COPY OF ARCHIVELOG"
if ((FirstScn == '' or LastScn == '') and (Name == '')):
Rcv += ' ALL'
else:
if (FirstScn != ''):
Rcv += " FROM SCN " + FirstScn
if (LastScn != ''):
Rcv += " UNTIL SCN " + LastScn
if (Name != ''):
Rcv += " LIKE '%" + Name + "%'"
Rcv += ";"
if (ListBackup == True):
if (Media == 'ALL' or Media == 'DISK'):
if (ListCopy == True):
Rcv += "\n"
Rcv += "LIST BACKUP OF ARCHIVELOG"
if ((FirstScn == '' or LastScn == '') and (Name == '')):
Rcv += ' ALL'
else:
if (FirstScn != ''):
Rcv += " FROM SCN " + FirstScn
if (LastScn != ''):
Rcv += " UNTIL SCN " + LastScn
if (Name != ''):
Rcv += " LIKE '%" + Name + "%'"
Rcv += " DEVICE TYPE DISK;"
if (Media == 'ALL' or Media == 'SBT'):
if (ListCopy == True or Media == 'ALL' or Media == 'DISK'):
Rcv += "\n"
#if (Media == 'ALL'):
# Rcv += "\n"
Rcv += "LIST BACKUP OF ARCHIVELOG"
if ((FirstScn == '' or LastScn == '') and (Name == '')):
Rcv += ' ALL'
#Rcv += "LIST BACKUP OF ARCHIVELOG"
if (FirstScn != ''):
Rcv += " FROM SCN " + FirstScn
if (LastScn != ''):
Rcv += " UNTIL SCN " + LastScn
if (Name != ''):
Rcv += " LIKE '%" + Name + "%'"
Rcv += " DEVICE TYPE SBT;"
if(Show):
print('-----------cut-----------cut-----------cut-----------cut-----------cut-----------')
print(Rcv)
print('-----------cut-----------cut-----------cut-----------cut-----------cut-----------')
exit()
# Check/setup the Oracle environment
if (not('ORACLE_SID' in list(environ.keys()))):
print('ORACLE_SID is required.')
exit(1)
else:
# Set the ORACLE_HOME just in case it isn't set already.
if (not('ORACLE_HOME' in list(environ.keys()))):
(OracleSid, OracleHome) = SetOracleEnv(environ['ORACLE_SID'])
# 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)
# Execute the report
print("\nReport Status of Archivelogs in RMAN:")
if (ListCopy == True):
print(" - List Copy of archivelog ...")
if (ListBackup == True):
if (Media == 'ALL' or Media == 'DISK'):
print(" - List Backup of archivelog device type DISK")
if (Media == 'ALL' or Media == 'SBT'):
print(" - List Backup of archivelog device type SBT")
if (ConnStr != ''):
(Stdout) = RunRman(Rcv, ErrChk, ConnStr)
else:
(Stdout) = RunRman(Rcv, ErrChk)
else:
Sql += "column name format a80 heading 'Name'\n"
Sql += "column first_change# format 999999999999999 heading 'First SCN'\n"
Sql += "column next_change# format 999999999999999 heading 'Last SCN'\n"
Sql += "column sequence# format 9999999999 heading 'Sequence'\n"
Sql += "column backup_count format 999 heading 'Backup Count'\n"
Sql += "column deleted format a7 heading 'Deleted'\n"
Sql += "column is_recovery_dest_file format a8 heading 'FRA File'\n"
Sql += "\n"
Sql += " SELECT " + SqlHeader + "\n"
Sql += " name\n"
Sql += " , first_change#\n"
Sql += " , next_change# - 1 next_change#\n"
Sql += " , sequence#\n"
Sql += " , backup_count\n"
Sql += " , initcap(deleted) deleted\n"
Sql += " , initcap(is_recovery_dest_file) is_recovery_dest_file\n"
Sql += " FROM v$archived_log\n"
Sql += " WHERE 1=1\n"
if (Deleted != True):
Sql += " AND upper(deleted) = 'NO'\n"
if (FirstScn != ''):
Sql += " AND first_change# >= " + FirstScn + "\n"
if (LastScn != ''):
Sql += " AND next_change# <= " + LastScn + "\n"
if (Name != ''):
Sql += " AND upper(name) LIKE '%" + Name.upper() + "%'\n"
Sql += "ORDER BY first_change#;"
if(Show):
print('-----------cut-----------cut-----------cut-----------cut-----------cut-----------')
print(Sql)
print('-----------cut-----------cut-----------cut-----------cut-----------cut-----------')
exit()
# Check/setup the Oracle environment
if (not('ORACLE_SID' in list(environ.keys()))):
print('ORACLE_SID is required.')
exit(1)
else:
# Set the ORACLE_HOME just in case it isn't set already.
if (not('ORACLE_HOME' in list(environ.keys()))):
(OracleSid, OracleHome) = SetOracleEnv(environ['ORACLE_SID'])
# 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)
# Execute the report
print("\nReport Status of Archivelogs in V$ARCHIVED_LOG:")
if (ConnStr != ''):
(Stdout) = RunSqlplus(Sql, ErrChk, ConnStr)
else:
(Stdout) = RunSqlplus(Sql, ErrChk)
# Print the report
if (Stdout != ''):
print('\n%s' % Stdout)
exit(0)
# --------------------------------------
# ---- End Main Program ----------------
# --------------------------------------