/
subclient.py
3310 lines (2575 loc) · 121 KB
/
subclient.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
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
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
# --------------------------------------------------------------------------
# Copyright Commvault Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# --------------------------------------------------------------------------
"""Main file for performing subclient operations.
Subclients and Subclient are 2 classes defined in this file.
Subclients: Class for representing all the subclients associated with a backupset / instance
Subclient: Base class consisting of all the common properties and operations for a Subclient
Subclients:
===========
__init__(class_object) -- initialise object of subclients object associated with
the specified backup set/instance.
__str__() -- returns all the subclients associated with the backupset
__repr__() -- returns the string for the instance of the Subclients class
__len__() -- returns the number of subclients associated with the Agent
for the selected Client
__getitem__() -- returns the name of the subclient for the given subclient Id
or the details for the given subclient name
_get_subclients() -- gets all the subclients associated with the backupset specified
_process_add_request() -- to post the add client request
default_subclient() -- returns the name of the default subclient
all_subclients() -- returns dict of all the subclients on commcell
has_subclient() -- checks if a subclient exists with the given name or not
add() -- adds a new subclient to the backupset
add_oracle_logical_dump_subclient() -- add subclient for oracle logical dump
add_postgresql_subclient() -- Adds a new postgresql subclient to the backupset.
add_mysql_subclient() -- Adds a new mysql subclient to the instance.
add_virtual_server_subclient() -- adds a new virtual server subclient to the backupset
add_onedrive_subclient() -- adds a new onedrive subclient to the instance
get(subclient_name) -- returns the subclient object of the input subclient name
delete(subclient_name) -- deletes the subclient (subclient name) from the backupset
refresh() -- refresh the subclients associated with the Backupset / Instance
Subclient:
==========
__init__() -- initialise instance of the Subclient class,
associated to the specified backupset
__getattr__() -- provides access to restore helper methods
__repr__() -- return the subclient name, the instance is associated with
_get_subclient_id() -- method to get subclient id, if not specified in __init__ method
_get_subclient_properties() -- get the properties of this subclient
_set_subclient_properties() -- sets the properties of this sub client .
_process_backup_request() -- runs the backup request provided, and processes the response
_browse_and_find_json() -- returns the appropriate JSON request to pass for either
Browse operation or Find operation
_process_browse_response() -- processes response received for both Browse and Find request
_common_backup_options() -- Generates the advanced job options dict
_json_task() -- setter for task property
_json_restore_subtask() -- setter for sub task property
_association_json() -- setter for association property
update_properties() -- To update the subclient properties
description() -- update the description of the subclient
content() -- update the content of the subclient
enable_backup() -- enables the backup for the subclient
enable_trueup() -- enables true up option for the subclient
enable_trueup_days() -- enables true up option and sets days for backup
enable_backup_at_time() -- enables backup for the subclient at the input time specified
disable_backup() -- disables the backup for the subclient
set_proxy_for_snap() -- method to set Use proxy option for intellisnap subclient
unset_proxy_for_snap() -- method to unset Use proxy option for intellisnap subclient
backup() -- run a backup job for the subclient
browse() -- gets the content of the backup for this subclient
at the path specified
browse_in_time() -- gets the content of the backup for this subclient
at the input path in the time range specified
find() -- searches a given file/folder name in the subclient content
list_media() -- List media required to browse and restore backed up data from the backupset
restore_in_place() -- Restores the files/folders specified in the
input paths list to the same location
restore_out_of_place() -- Restores the files/folders specified in the input paths list
to the input client, at the specified destionation location
set_backup_nodes() -- Set Backup Nodes for NFS Share Pseudo client's subclient.
find_latest_job() -- Finds the latest job for the subclient
which includes current running job also.
refresh() -- refresh the properties of the subclient
Subclient Instance Attributes:
==============================
**properties** -- returns the properties of the subclient
**name** -- returns the name of the subclient
**display_name** -- returns the display name of the subclient
**description** -- returns the description of the subclient
**snapshot_engine_name** -- returns snapshot engine name associated
with the subclient
**is_default_subclient** -- returns True if the subclient is default
subclient else returns False
**is_blocklevel_backup_enabled** -- returns True if block level backup is enabled
"""
from __future__ import absolute_import
from __future__ import unicode_literals
import math
import time
import copy
from base64 import b64encode
from .job import Job
from .job import JobController
from .schedules import Schedules
from .exception import SDKException
from .schedules import SchedulePattern
class Subclients(object):
"""Class for getting all the subclients associated with a client."""
def __init__(self, class_object):
"""Initialize the Subclients object for the given backupset.
Args:
class_object (object) -- instance of the Agent / Instance / Backupset class
Returns:
object - instance of the Subclients class
Raises:
SDKException:
if class object is not an instance of Agent / Instance / Backupset
"""
from .agent import Agent
from .instance import Instance
from .backupset import Backupset
self._agent_object = None
self._instance_object = None
self._backupset_object = None
self._url_param = ''
if isinstance(class_object, Agent):
self._agent_object = class_object
self._url_param += self._agent_object.agent_id
elif isinstance(class_object, Instance):
self._instance_object = class_object
self._agent_object = self._instance_object._agent_object
self._url_param += '{0}&instanceId={1}'.format(
self._agent_object.agent_id, self._instance_object.instance_id
)
elif isinstance(class_object, Backupset):
self._backupset_object = class_object
self._instance_object = class_object._instance_object
self._agent_object = self._instance_object._agent_object
self._url_param += self._agent_object.agent_id
self._url_param += '&backupsetId={0}'.format(
self._backupset_object.backupset_id
)
else:
raise SDKException('Subclient', '115')
self._client_object = self._agent_object._client_object
self._commcell_object = self._agent_object._commcell_object
self._cvpysdk_object = self._commcell_object._cvpysdk_object
self._services = self._commcell_object._services
self._update_response_ = self._commcell_object._update_response_
self._SUBCLIENTS = self._services['GET_ALL_SUBCLIENTS'] % (
self._client_object.client_id, self._url_param
)
self._ADD_SUBCLIENT = self._services['ADD_SUBCLIENT']
self._default_subclient = None
# sql server subclient type dict
self._sqlsubclient_type_dict = {
'DATABASE': 1,
'FILE_FILEGROUP': 2,
}
# this will work only for `Exchange Database` Agent, as only an object of
# ExchangeDatabaseAgent class has these attributes
if self._instance_object is None and hasattr(
self._agent_object, '_instance_object'):
self._instance_object = self._agent_object._instance_object
if self._backupset_object is None and hasattr(
self._agent_object, '_backupset_object'):
self._backupset_object = self._agent_object._backupset_object
self.refresh()
def __str__(self):
"""Representation string consisting of all subclients of the backupset.
Returns:
str - string of all the subclients of th backupset of an agent of a client
"""
representation_string = '{:^5}\t{:^20}\t{:^20}\t{:^20}\t{:^20}\t{:^20}\n\n'.format(
'S. No.', 'Subclient', 'Backupset', 'Instance', 'Agent', 'Client'
)
for index, subclient in enumerate(self._subclients):
sub_str = '{:^5}\t{:20}\t{:20}\t{:20}\t{:20}\t{:20}\n'.format(
index + 1,
subclient.split('\\')[-1],
self._subclients[subclient]['backupset'],
self._instance_object.instance_name,
self._agent_object.agent_name,
self._client_object.client_name
)
representation_string += sub_str
return representation_string.strip()
def __repr__(self):
"""Representation string for the instance of the Subclients class."""
if self._backupset_object is not None:
o_str = (
'Subclients class instance for Backupset: "{0}", '
'of Instance: "{1}", for Agent: "{2}"'
).format(
self._backupset_object.backupset_name,
self._instance_object.instance_name,
self._agent_object.agent_name
)
elif self._instance_object is not None:
o_str = 'Subclients class instance for Instance: "{0}", of Agent: "{1}"'.format(
self._instance_object.instance_name,
self._agent_object.agent_name
)
else:
o_str = 'Subclients class instance for Agent: "{0}"'.format(
self._agent_object.agent_name
)
return o_str
def __len__(self):
"""Returns the number of the subclients associated to the Agent for the selected Client."""
return len(self.all_subclients)
def __getitem__(self, value):
"""Returns the name of the subclient for the given subclient ID or
the details of the subclient for given subclient Name.
Args:
value (str / int) -- Name or ID of the subclient
Returns:
str - name of the subclient, if the subclient id was given
dict - dict of details of the subclient, if subclient name was given
Raises:
IndexError:
no subclient exists with the given Name / Id
"""
value = str(value)
if value in self.all_subclients:
return self.all_subclients[value]
else:
try:
return list(
filter(lambda x: x[1]['id'] == value, self.all_subclients.items())
)[0][0]
except IndexError:
raise IndexError('No subclient exists with the given Name / Id')
def _get_subclients(self):
"""Gets all the subclients associated to the client specified by the backupset object.
Returns:
dict - consists of all subclients in the backupset
{
"subclient1_name": {
"id": subclient1_id,
"backupset": backupset
},
"subclient2_name": {
"id": subclient2_id,
"backupset": backupset
}
}
Raises:
SDKException:
if response is empty
if response is not success
"""
flag, response = self._cvpysdk_object.make_request(
'GET', self._SUBCLIENTS)
if flag:
if response.json() and 'subClientProperties' in response.json():
return_dict = {}
for dictionary in response.json()['subClientProperties']:
# store the agent, instance, and backupset name for the current subclient
# the API call returns the subclients for all Agents, so we need to filter
# them out based on the Agent / Instance / Backupset that had been selected
# by the user earlier
agent = dictionary['subClientEntity']['appName'].lower()
instance = dictionary['subClientEntity']['instanceName'].lower(
)
backupset = dictionary['subClientEntity']['backupsetName'].lower(
)
# filter subclients for all entities: Agent, Instance, and Backupset
# as the instance of the Backupset class was passed for Subclients instance
# creation
if self._backupset_object is not None:
if (self._backupset_object.backupset_name in backupset and
self._instance_object.instance_name in instance and
self._agent_object.agent_name in agent):
temp_name = dictionary['subClientEntity']['subclientName'].lower(
)
temp_id = str(
dictionary['subClientEntity']['subclientId']).lower()
return_dict[temp_name] = {
"id": temp_id,
"backupset": backupset
}
if dictionary['commonProperties'].get(
'isDefaultSubclient'):
self._default_subclient = temp_name
elif self._instance_object is not None:
if (self._instance_object.instance_name in instance and
self._agent_object.agent_name in agent):
temp_name = dictionary['subClientEntity']['subclientName'].lower(
)
temp_id = str(
dictionary['subClientEntity']['subclientId']).lower()
if len(
self._instance_object.backupsets.all_backupsets) > 1:
temp_name = "{0}\\{1}".format(
backupset, temp_name)
return_dict[temp_name] = {
"id": temp_id,
"backupset": backupset
}
if dictionary['commonProperties'].get(
'isDefaultSubclient'):
self._default_subclient = temp_name
elif self._agent_object is not None:
if self._agent_object.agent_name in agent:
temp_name = dictionary['subClientEntity']['subclientName'].lower(
)
temp_id = str(
dictionary['subClientEntity']['subclientId']).lower()
if len(self._agent_object.instances.all_instances) > 1:
if len(
self._instance_object.backupsets.all_backupsets) > 1:
temp_name = "{0}\\{1}\\{2}".format(
instance, backupset, temp_name
)
else:
temp_name = "{0}\\{1}".format(
instance, temp_name)
else:
if len(
self._instance_object.backupsets.all_backupsets) > 1:
temp_name = "{0}\\{1}".format(
backupset, temp_name)
return_dict[temp_name] = {
"id": temp_id,
"backupset": backupset
}
if dictionary['commonProperties'].get(
'isDefaultSubclient'):
self._default_subclient = temp_name
return return_dict
else:
raise SDKException('Response', '102')
else:
raise SDKException(
'Response',
'101',
self._update_response_(
response.text))
@property
def all_subclients(self):
"""Returns dict of all the subclients configured on this backupset
Retruns:
dict - consists of all subclients in the backupset
{
"subclient1_name": {
"id": subclient1_id,
"backupset": backupset
},
"subclient2_name": {
"id": subclient2_id,
"backupset": backupset
}
}
"""
return self._subclients
def has_subclient(self, subclient_name):
"""Checks if a subclient exists in the commcell with the input subclient name.
Args:
subclient_name (str) -- name of the subclient
Returns:
bool - boolean output whether the subclient exists in the backupset or not
Raises:
SDKException:
if type of the subclient name argument is not string
"""
if not isinstance(subclient_name, str):
raise SDKException('Subclient', '101')
return self._subclients and subclient_name.lower() in self._subclients
def _process_add_request(self, request_json):
"""To post the add subclient request
Args:
request_json (dict) -- Request json to be passed as the payload
Returns:
object - instance of the Subclient class
"""
flag, response = self._cvpysdk_object.make_request(
'POST', self._ADD_SUBCLIENT, request_json
)
if flag:
if response.json() and 'response' in response.json():
error_code = response.json()['response']['errorCode']
if error_code != 0:
error_string = response.json()['response']['errorString']
raise SDKException(
'Subclient',
'102',
'Failed to create subclient\nError: "{0}"'.format(error_string)
)
else:
# initialize the subclients again so the subclient object has all the subclients
self.refresh()
subclient_name = request_json['subClientProperties']['subClientEntity']['subclientName']
return self.get(subclient_name)
else:
raise SDKException('Response', '102')
else:
raise SDKException('Response', '101', self._update_response_(response.text))
def add(self, subclient_name, storage_policy=None,
subclient_type=None, description='', advanced_options=None,
pre_scan_cmd=None):
"""Adds a new subclient to the backupset.
Args:
subclient_name (str) -- name of the new subclient to add
storage_policy (str) -- name of the storage policy to be associated
with the subclient
default: None
subclient_type (str) -- type of subclient for sql server
default: None
Valid Values are:
- DATABASE
- FILE_FILEGROUP
description (str) -- description for the subclient (optional)
default: ''
advanced_options (dict) -- dict of additional options needed to create
subclient with additional properties
default : None
Example:
{
ondemand_subclient : True
}
pre_scan_cmd (str) -- path to the batch file/shell script file to run
before each backup of the subclient
Returns:
object - instance of the Subclient class
Raises:
SDKException:
if subclient name argument is not of type string
if storage policy argument is not of type string
if description argument is not of type string
if failed to create subclient
if response is empty
if response is not success
if subclient already exists with the given name
"""
if not (isinstance(subclient_name, str) and
isinstance(description, str)):
raise SDKException('Subclient', '101')
if self.has_subclient(subclient_name):
raise SDKException(
'Subclient', '102', 'Subclient "{0}" already exists.'.format(
subclient_name)
)
if self._backupset_object is None:
if self._instance_object.backupsets.has_backupset(
'defaultBackupSet'):
self._backupset_object = self._instance_object.backupsets.get(
'defaultBackupSet')
else:
self._backupset_object = self._instance_object.backupsets.get(
sorted(self._instance_object.backupsets.all_backupsets)[0]
)
if storage_policy and not self._commcell_object.storage_policies.has_policy(
storage_policy):
raise SDKException(
'Subclient',
'102',
'Storage Policy: "{0}" does not exist in the Commcell'.format(
storage_policy)
)
if advanced_options:
if advanced_options.get("ondemand_subclient", False):
ondemand_value = advanced_options.get("ondemand_subclient")
else:
ondemand_value = False
else:
ondemand_value = False
request_json = {
"subClientProperties": {
"contentOperationType": 2,
"subClientEntity": {
"clientName": self._client_object.client_name,
"appName": self._agent_object.agent_name,
"instanceName": self._instance_object.instance_name,
"backupsetName": self._backupset_object.backupset_name,
"subclientName": subclient_name
},
"commonProperties": {
"description": description,
"enableBackup": True,
"onDemandSubClient": ondemand_value,
"storageDevice": {
"dataBackupStoragePolicy": {
"storagePolicyName": storage_policy
}
},
}
}
}
if storage_policy is None:
del request_json["subClientProperties"]["commonProperties"]["storageDevice"]
if pre_scan_cmd is not None:
request_json["subClientProperties"]["commonProperties"]["prepostProcess"] = {
"runAs": 1,
"preScanCommand": pre_scan_cmd
}
if self._agent_object.agent_name == 'sql server':
request_json['subClientProperties']['mssqlSubClientProp'] = {
'sqlSubclientType': self._sqlsubclient_type_dict[subclient_type]
}
return self._process_add_request(request_json)
def add_oracle_logical_dump_subclient(
self,
subclient_name,
storage_policy,
dump_dir,
user_name,
domain_name,
password,
full_mode,
schema_value=None):
"""
Method to add subclient for oracle logical dump.
This method add two type of subclient full mode
and schema mode. For full mode full_mode should be
true and schema_value should be none and for schema
mode full_mode should be false and schema_value should
be list of values.Rest of thing should be same for both.
Args:
subclient_name (Str) -- subclient name for logical dump
storage_policy (Str) -- Storage policy for subclient
dump_dir (Str) -- dump directory for subclient
user_name (Str) -- username for oracle database
domain_name (Str) -- domainname for oracle database
password (Str) -- password for oracle database
(should be in encrypted and decrypted form)
full_mode (bool) -- if ture then subclient for full mode otherwise schema mode
schema_value (list) -- schema value for schema mode subclient
default: None
Return:
object - instance of the Subclient class
Raises:
SDKException:
if subclient name argument is not of type string
if storage policy argument is not of type string
if subclient name already present
if storage policy does not exist
"""
if not (isinstance(subclient_name, str) and
isinstance(storage_policy, str) and
isinstance(dump_dir, str) and
isinstance(user_name, str) and
isinstance(domain_name, str) and
isinstance(password, str) and
isinstance(full_mode, bool)):
raise SDKException('Subclient', '101')
if (full_mode == False and not
isinstance(schema_value, list)):
raise SDKException('Subclient', '101')
if self.has_subclient(subclient_name):
raise SDKException(
'Subclient', '102', 'Subclient "{0}" already exists.'.format(
subclient_name)
)
if self._backupset_object is None:
if self._instance_object.backupsets.has_backupset(
'defaultBackupSet'):
self._backupset_object = self._instance_object.backupsets.get(
'defaultBackupSet')
else:
self._backupset_object = self._instance_object.backupsets.get(
sorted(self._instance_object.backupsets.all_backupsets)[0]
)
if not self._commcell_object.storage_policies.has_policy(
storage_policy):
raise SDKException(
'Subclient',
'102',
'Storage Policy: "{0}" does not exist in the Commcell'.format(
storage_policy)
)
request_json = {
"subClientProperties": {
"subClientEntity": {
"clientName": self._client_object.client_name,
"instanceName": self._instance_object.instance_name,
"appName": self._agent_object.agent_name,
"backupsetName": self._backupset_object.backupset_name,
"subclientName": subclient_name
},
"oracleSubclientProp": {
"data": False,
"archiveDelete": False,
"useSQLConntect": False,
"dbSubclientType": 2,
"mergeIncImageCopies": False,
"selectiveOnlineFull": False,
"protectBackupRecoveryArea": False,
"selectArchiveLogDestForBackup": False,
"backupSPFile": False,
"backupControlFile": False,
"backupArchiveLog": False,
"validate": False,
},
"commonProperties": {
"snapCopyInfo": {
"useSeparateProxyForSnapToTape": False,
"checkProxyForSQLIntegrity": False,
"snapToTapeProxyToUseSource": False,
"isSnapBackupEnabled": False,
"IsOracleSposDriverEnabled": False,
"isRMANEnableForTapeMovement": False
},
"dbDumpConfig": {
"fullMode": True,
"database": "",
"dumpDir": dump_dir,
"parallelism": 2,
"overrideInstanceUser": True,
"sqlConnect": {
"password": b64encode(password.encode()).decode(),
"domainName": domain_name,
"userName": user_name
}
},
"storageDevice": {
"dataBackupStoragePolicy": {
"storagePolicyName": storage_policy
},
"deDuplicationOptions": {
"enableDeduplication": True
}
}
}
}
}
if (full_mode == False):
request_json["subClientProperties"]["commonProperties"]["dbDumpConfig"]["fullMode"] = False
request_json["subClientProperties"]["commonProperties"]["dbDumpConfig"]["schema"] = schema_value
return self._process_add_request(request_json)
def add_postgresql_subclient(
self, subclient_name, storage_policy,
contents, no_of_streams=1, collect_object_list=False):
"""Adds a new postgresql subclient to the backupset.
Args:
subclient_name (str) -- name of the new subclient to add
storage_policy (str) -- name of the storage policy to be associated
with the subclient
contents (list) -- database list to be added as subclient content
no_of_streams (int) -- No of backup streams to be used
default: 1
collect_object_list (bool) -- Boolean flag to determine if collect object
list needs to be enabled for subclient or not
default: False
Returns:
object - instance of the Subclient class
Raises:
SDKException:
if subclient name argument is not of type string
if storage policy argument is not of type string
if conetnts argument is not of type list
if contents is empty list
if failed to create subclient
if response is empty
if response is not success
if subclient already exists with the given name
"""
if not (isinstance(subclient_name, str) and
isinstance(storage_policy, str) and
isinstance(contents, list)):
raise SDKException('Subclient', '101')
if self.has_subclient(subclient_name):
raise SDKException(
'Subclient', '102', 'Subclient "{0}" already exists.'.format(
subclient_name)
)
if not self._commcell_object.storage_policies.has_policy(
storage_policy):
raise SDKException(
'Subclient',
'102',
'Storage Policy: "{0}" does not exist in the Commcell'.format(
storage_policy)
)
if not contents:
raise SDKException(
'Subclient',
'102',
'Content list cannot be empty'
)
content_list = []
for content in contents:
content_list.append({"postgreSQLContent": {"databaseName": content}})
request_json = {
"subClientProperties": {
"contentOperationType": 2,
"subClientEntity": {
"clientName": self._client_object.client_name,
"appName": self._agent_object.agent_name,
"instanceName": self._instance_object.instance_name,
"backupsetName": self._backupset_object.backupset_name,
"subclientName": subclient_name
},
"commonProperties": {
"storageDevice": {
"dataBackupStoragePolicy": {
"storagePolicyName": storage_policy
}
},
},
"postgreSQLSubclientProp": {
"numberOfBackupStreams": no_of_streams,
"collectObjectListDuringBackup": collect_object_list
},
"content": content_list
}
}
return self._process_add_request(request_json)
def add_mysql_subclient(
self,
subclient_name,
storage_policy,
contents,
**kwargs
):
"""Adds a new mysql subclient to the instance.
Args:
subclient_name (str) -- name of the new subclient to add
storage_policy (str) -- name of the storage policy to be associated
with the subclient
contents (list) -- database list to be added as subclient content
kwargs (dict) -- dict of keyword arguments as follows
no_of_backup_streams (int) -- No of backup streams to be used
default: 1
no_of_log_backup_streams (int) -- No of Transaction log backup streams
default: 1
full_instance_xtrabackup (bool) -- True if XtraBackup is selected for subclient
default: False
Returns:
object - instance of the Subclient class
Raises:
SDKException:
if subclient name argument is not of type string
if storage policy argument is not of type string
if conetnts argument is not of type list
if contents is empty list
if failed to create subclient
if response is empty
if response is not success
if subclient already exists with the given name
"""
if not (isinstance(subclient_name, str) and
isinstance(storage_policy, str) and
isinstance(contents, list)):
raise SDKException('Subclient', '101')
if self.has_subclient(subclient_name):
raise SDKException(
'Subclient', '102', 'Subclient "{0}" already exists.'.format(
subclient_name)
)
if not self._commcell_object.storage_policies.has_policy(
storage_policy):
raise SDKException(
'Subclient',
'102',
'Storage Policy: "{0}" does not exist in the Commcell'.format(
storage_policy)