51
51
52
52
53
53
def _validate_data_set_name (ds ):
54
+ """Validate data set name.
55
+
56
+ Parameters
57
+ ----------
58
+ ds : str
59
+ The source dataset.
60
+
61
+ Returns
62
+ -------
63
+ str
64
+ Parsed dataset.
65
+ """
54
66
arg_defs = dict (ds = dict (arg_type = "data_set" ))
55
67
parser = BetterArgParser (arg_defs )
56
68
parsed_args = parser .parse_args ({"ds" : ds })
57
69
return parsed_args .get ("ds" )
58
70
59
71
60
72
def mvs_file_backup (dsn , bk_dsn = None , tmphlq = None ):
61
- """Create a backup data set for an MVS data set
62
-
63
- Arguments:
64
- dsn {str} -- The name of the data set to backup.
65
- It could be an MVS PS/PDS/PDSE/VSAM(KSDS), etc.
66
- bk_dsn {str} -- The name of the backup data set.
67
-
68
- Raises:
69
- BackupError: When backup data set exists.
70
- BackupError: When creation of backup data set fails.
73
+ """Create a backup data set for an MVS data set.
74
+
75
+ Parameters
76
+ ----------
77
+ dsn : str
78
+ The name of the data set to backup.
79
+ It could be an MVS PS/PDS/PDSE/VSAM(KSDS), etc.
80
+ bk_dsn : str
81
+ The name of the backup data set.
82
+
83
+ Returns
84
+ -------
85
+ str
86
+ The backup dataset
87
+
88
+ Raises
89
+ ------
90
+ BackupError
91
+ When backup data set exists.
92
+ BackupError
93
+ When creation of backup data set fails.
71
94
"""
72
95
dsn = _validate_data_set_name (dsn ).upper ()
73
96
if is_member (dsn ):
@@ -98,7 +121,7 @@ def mvs_file_backup(dsn, bk_dsn=None, tmphlq=None):
98
121
99
122
# In case the backup ds is a member we trust that the PDS attributes are ok to fit the src content.
100
123
# This should not delete a PDS just to create a backup member.
101
- # Otherwise, we allocate the appropiate space for the backup ds based on src.
124
+ # Otherwise, we allocate the appropriate space for the backup ds based on src.
102
125
if is_member (bk_dsn ):
103
126
try :
104
127
cp_rc = datasets .copy (dsn , bk_dsn )
@@ -122,20 +145,29 @@ def mvs_file_backup(dsn, bk_dsn=None, tmphlq=None):
122
145
123
146
124
147
def uss_file_backup (path , backup_name = None , compress = False ):
125
- """Create a backup file for a USS file or path
126
-
127
- Arguments:
128
- path {str} -- The name of the USS file or path to backup.
129
- backup_name {str} -- The name of the backup file.
130
-
131
- Keyword Arguments:
132
- compress {bool} -- Determines if the backup be compressed. (default: {False})
133
-
134
- Raises:
135
- BackupError: When creating compressed backup fails.
136
-
137
- Returns:
138
- str -- Name of the backup file.
148
+ """Create a backup file for a USS file or path.
149
+
150
+ Parameters
151
+ ----------
152
+ path : str
153
+ The name of the USS file or path to backup.
154
+ backup_name : str
155
+ The name of the backup file.
156
+
157
+ Keyword Parameters
158
+ ------------------
159
+ compress : bool
160
+ Determines if the backup be compressed. (default: {False})
161
+
162
+ Returns
163
+ -------
164
+ str
165
+ Name of the backup file.
166
+
167
+ Raises
168
+ ------
169
+ BackupError
170
+ When creating compressed backup fails.
139
171
"""
140
172
abs_path = os .path .abspath (path )
141
173
@@ -188,14 +220,24 @@ def uss_file_backup(path, backup_name=None, compress=False):
188
220
189
221
190
222
def _copy_ds (ds , bk_ds ):
191
- """Copy the contents of a data set to another
192
-
193
- Arguments:
194
- ds {str} -- The source data set to be copied from. Should be SEQ or VSAM
195
- bk_dsn {str} -- The destination data set to copy to.
196
-
197
- Raises:
198
- BackupError: When copying data fails
223
+ """Copy the contents of a data set to another.
224
+
225
+ Parameters
226
+ ----------
227
+ ds : str
228
+ The source data set to be copied from. Should be SEQ or VSAM.
229
+ bk_dsn : str
230
+ The destination data set to copy to.
231
+
232
+ Returns
233
+ -------
234
+ int
235
+ Return code.
236
+
237
+ Raises
238
+ ------
239
+ BackupError
240
+ When copying data fails.
199
241
"""
200
242
module = AnsibleModuleHelper (argument_spec = {})
201
243
_allocate_model (bk_ds , ds )
@@ -220,14 +262,24 @@ def _copy_ds(ds, bk_ds):
220
262
221
263
222
264
def _allocate_model (ds , model ):
223
- """Allocate a data set using allocation information of a model data set
224
-
225
- Arguments:
226
- ds {str} -- The name of the data set to be allocated.
227
- model {str} -- The name of the data set whose allocation parameters should be used.
228
-
229
- Raises:
230
- BackupError: When allocation fails
265
+ """Allocate a data set using allocation information of a model data set.
266
+
267
+ Parameters
268
+ ----------
269
+ ds : str
270
+ The name of the data set to be allocated.
271
+ model : str
272
+ The name of the data set whose allocation parameters should be used.
273
+
274
+ Returns
275
+ -------
276
+ int
277
+ Return code.
278
+
279
+ Raises
280
+ ------
281
+ BackupError
282
+ When allocation fails.
231
283
"""
232
284
module = AnsibleModuleHelper (argument_spec = {})
233
285
alloc_cmd = """ ALLOC -
@@ -247,13 +299,51 @@ def _allocate_model(ds, model):
247
299
248
300
249
301
def _copy_pds (ds , bk_dsn ):
302
+ """Copy a dataset.
303
+
304
+ Parameters
305
+ ----------
306
+ ds : str
307
+ The name of the data set to be allocated.
308
+ bk_dsn : str
309
+ The destination data set to copy to.
310
+
311
+ Returns
312
+ -------
313
+ str
314
+ Copied dataset.
315
+ """
250
316
dds = dict (OUTPUT = bk_dsn , INPUT = ds )
251
317
copy_cmd = " COPY OUTDD=OUTPUT,INDD=((INPUT,R))"
252
318
return iebcopy (copy_cmd , dds = dds )
253
319
254
320
255
321
class BackupError (Exception ):
256
322
def __init__ (self , message , rc = None , stdout = None , stderr = None ):
323
+ """Error during backup.
324
+
325
+ Parameters
326
+ ----------
327
+ message : str
328
+ Human readable string describing the exception.
329
+ rc : int
330
+ Return code.
331
+ stdout : str
332
+ Standard output.
333
+ stderr : str
334
+ Standard error.
335
+
336
+ Attributes
337
+ ----------
338
+ msg : str
339
+ Human readable string describing the exception.
340
+ rc : int
341
+ Return code.
342
+ stdout : str
343
+ Standard output.
344
+ stderr : str
345
+ Standard error.
346
+ """
257
347
self .msg = 'An error occurred during backup: "{0}"' .format (message )
258
348
self .rc = rc
259
349
self .stdout = stdout
0 commit comments